Godot-proposals: Use AnimatedTexture as cursor shape resource / allow custom animated cursors

Created on 16 Sep 2019  路  3Comments  路  Source: godotengine/godot-proposals

Describe the project you are working on:
An action game on PC that requires a lot of interactions to be done using the mouse cursor with various states. (Arrow, I-beam, Pointing hand, horizontal resize, diagonal resize, etc)

Describe how this feature / enhancement will help your project:
With the game being reliant on the mouse cursor a lot of times, it makes sense to add some flair and liveliness to it. Or any game, really, unless said game is purely keyboard/controller based. It being hardware based instead of a node being updated constantly to follow the mouse cursor will also help with the overall performance of the game as it's one less thing the script has to be parsed for. One could argue that static cursors can be more than enough but at the end of the day, video games are all about presentation and visual flair.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:
I don't think there's a need for a diagram since this is just talking about adding animation to the already existing custom mouse cursor system but I made one anyway...
diagram_proposal

Describe implementation detail for your proposal (in code), if possible:
I am not familiar with the low-level workings pertaining to the implementation directly but I do know that both Windows and macOS have support for animated cursors as it is used by the system-provided default cursors themselves. (On Windows, they come in the form of *.ani files instead of the one used for static cursors which is *.cur.) I believe Linux allows animated cursors too.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
This will require recreating a cursor management system to check for and change the cursor depending on the input type as well as checking the node's mouse_default_cursor_shape property in order to show the appropriate AnimatedTexture. Well, that or change everything in the project that ever used mouse_default_cursor_shape and apply specific changes to them directly. (Would be quite troublesome especially in larger projects) That doesn't even include things such as horizontal, vertical, or diagonal resizing cursors as I have no idea how one would go about detecting those at runtime.

Is there a reason why this should be core and not an add-on in the asset library?:
The change is related to more lower-level stuff making it impossible to implement as an addon.

core

Most helpful comment

Unfortunately I don't know how to get the cursor shape. So unfortunately for this workaround you would have to use Areas and signals, I suppose, that inform your sticky node what Sprite to show and what animation to play.
Maybe we should also request to expose a getter for the cursor shape while we are at it. Because honestly, if performance allows it, I much rather have the full power of the AnimationPlayer than just some AnimatedTexture if I really go as far to animate my cursor.

All 3 comments

Meanwhile, you could maybe try hiding the OS mouse cursor and stick a node with an AnimatedTexture, AnimatedSprite or Sprite+Animationplayer (my favourite) on the mouse cursor position. Like so:

func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)

func _process(delta):
    $MyAnimatedCursor.position = get_global_mouse_position()

https://www.youtube.com/watch?v=PoXVo-18o2U

@golddotasksquestions hmm, this doesn't solve the issue of cursor shapes though, this would only replace the default cursor. What about the resizer cursors when you drag the side of a WindowDialog node to resize at runtime, how would you change the cursor then?

Unfortunately I don't know how to get the cursor shape. So unfortunately for this workaround you would have to use Areas and signals, I suppose, that inform your sticky node what Sprite to show and what animation to play.
Maybe we should also request to expose a getter for the cursor shape while we are at it. Because honestly, if performance allows it, I much rather have the full power of the AnimationPlayer than just some AnimatedTexture if I really go as far to animate my cursor.

Was this page helpful?
0 / 5 - 0 ratings