![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | kowid51384 |
I want the mouse cursor to change depending on what it is hovering over. It seems an object can tell if the cursor has entered it with the mouse_entered() signal.
But is that still optimal for a 2D RTS game that will have many units? I feel like it’d make more sense for the cursor to constantly check what’s underneath it, rather than have hundreds of units constantly check if the mouse cursor has entered them, but I am very new to Godot so maybe my understanding is wrong. Plus, I’ve saved the units as their own scenes and it doesn’t seem like I can connect their signals to the main scene.
Basic skeleton of what I was thinking:
extends Node2D #Custom cursors var cursor_default = load("res://Assets/RTSP_cursor_default.png") var cursor_ally = load("res://Assets/RTSP_cursor_ally_hover.png") var cursor_neutral = load("res://Assets/RTSP_cursor_neutral_hover.png") var cursor_enemy = load("res://Assets/RTSP_cursor_enemy_hover.png") func _process(delta): #getting the position of the mouse var hoverCheck = get_viewport().get_mouse_position() #Some code that would check if #there's anything remarkable at "hoverCheck" would go here. #If there is an enemy at "hoverCheck", then it would change the cursor. Input.set_custom_mouse_cursor(cursor_enemy) #However, a different cursor is set if it is an ally. Input.set_custom_mouse_cursor(cursor_ally) else: Input.set_custom_mouse_cursor(cursor_default)