Fix sorting of sprites

Sort function for sprite array was not implemented correctly, creating an incorrect sorting of the sprites.