How can I rotate a Sprite to face particular x,y coordinates?

Made that funny example, where arrows on sprites rotate towards pointer.
Extended Sprite object. Passing in its constructor pointer’s position in NDC. In the update function, there is simple cast from scene coords into screen NDC for sprite’s position. Subtract sprite’s poisiton from pointer’s position. Call .angle(). Apply the result angle to sprite’s texture.

Picture:

Demo: https://codepen.io/prisoner849/full/BaVZKWW

PS Though, not sure how correct this approach is.

6 Likes