Hi! I’m trying to make a code that checks whether the current mouse cursor shape is 1 or 2 and changes it to the other one. So far I only got something like this:
func _unhandled_input(event):
if event.is_action_pressed(“Action1”):
if Input.get_current_cursor_shape()==cursor1:
Input.set_custom_mouse_cursor(cursor2, Input.CURSOR_ARROW, Vector2(0, 0))
else
Input.set_custom_mouse_cursor(cursor1, Input.CURSOR_ARROW, Vector2(0, 0))
3 things I don’t understand about this:
Is it correct to use unhandled input or should I use the func _ready()?
The part in bold, what do I write there (and anywhere else for that matter) to make the code work?
The part in the last line that says ‘cursor1’, should it be “res://cursor1.png”? Because the debugging tool says the node is not found
Input.get_cursor_shape() returns the CursorShape, which corresponds with the second argument of Input.set_custom_mouse_cursor, which is in your case Input.CURSOR_ARROW.
You could try something along the idea of:
func _ready() -> void:
var cursor1 = load("res://icon.svg")
var cursor2 = load("res://icon.svg")
Input.set_custom_mouse_cursor(cursor1, Input.CURSOR_ARROW, Vector2(10, 10))
Input.set_custom_mouse_cursor(cursor2, Input.CURSOR_CROSS)
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("ui_accept"):
if Input.get_current_cursor_shape() == Input.CURSOR_ARROW:
Input.set_default_cursor_shape(Input.CURSOR_CROSS)
else:
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
_ready is called only once, when the node enters the scene tree. _unhandled_input is called whenever an InputEvent happens (and if it hasn’t been set to handled during the previous steps of input handling)