How to change the cursor to an animated sprite

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By h06y

Hi guys. i’d like to change my cursor (preferably by a Singleton, so i can change it anytime). Is there any way to change it to an Animated Sprite?

:bust_in_silhouette: Reply From: Calinou

You can’t use an animated hardware cursor, but you can use a software cursor that’s represented by an AnimatedSprite (or Sprite + AnimationPlayer). Simply move the sprite’s position every frame in _process() to the cursor’s position. Keep in mind there will be an 1-frame lag compared to an hardware cursor, which makes this a bad idea for fast-paced games.

Can’t you do it with _physics_process(delta) and it will be every frame or will that be the same?

BlockOG | 2020-12-09 19:03

On high refresh rate monitors, it will be even worse if you use _physics_process() instead of _process() to move the cursor.

One way you could use to decrease the perceived latency is to extrapolate the cursor position, but doing so will introduce jittering.

Calinou | 2020-12-12 18:57

:bust_in_silhouette: Reply From: TheWarmWaffle

I fixed this recently to not have that one frame lag, this is the top result when searching for animated cursor so ill just leave this here:

text if the link expires:

If you use the normal method of having a sprite follow the mouse position then you’ll get input lag, that bugged me quite a bit. So I went down a couple of rabbit holes and finally figured out a fix.

You only need a Sprite with a script, AnimatedTexture set as the Sprites Texture (your cursor animation), and this line of code:


So what’s happening here is you get the Sprites texture (the AnimatedTexture) get its current frame, then get the resource for the current frame, and set the cursors texture to that resource.

Now just plop that line of code into _process(delta) and you’re good to go

side not, if you wanna see how much input delay this gets rid of you can put this

global_position = get_global_mouse_position()

into _process(delta) as well and compare both the cursors!