I really love the selected answer.
using Input.set_custom_mouse_cursor()
but in case anyone needs to know how to implement this answer too :
Godot Doc for Input.set_mouse_mode()
Input.set_mouse_mode(
pass it 0,1,2,or 3 )
Godot Doc for Input.MOUSE_MODE_...
Member constants defined in Input you can use ( identical to using 0-3 )
Input.set_mouse_mode( Input.MOUSE_MODE_VISIBLE ) # or pass 0 as parameter
Input.set_mouse_mode( Input.MOUSE_MODE_HIDDEN ) # or 1
Input.set_mouse_mode( Input.MOUSE_MODE_CAPTURED ) # or 2
Input.set_mouse_mode( Input.MOUSE_MODE_CONFINED ) # or 3
NOTE: Godot 2.1.4 set_mouse_mode() only has modes 0,1,2 ;
Input.MOUSE_MODE_CONFINED added in 3.0 alpha
Godot Doc for Control.set_default_cursor_shape()
accepts one number between 0 and 16 as a parameter.
N O T E S :
- Only changes the cursor when it is directly above the node
that called set_default_cursor_shape(
int 0..16 )
- If the node that calls set_default_cursor_shape(int)
is partially covered by a child node (or sibling node)
only hovering over the non-covered parts will change the cursor
Godot Doc for Control's Numeric Constants
class Control has 17 constants defined for each cursor shape mode you can pass
example : set_default_cursor_shape( Control.CURSOR_WAIT )
example of each in the code your can try below
Simple scene + code to test set_default_cursor_shape()
:
=== Scene Setup ===
- Make a new scene,
- Click tab for 2D
- Add a new Panel node to the scene
(found under Node -> CanvasItem -> Control -> Panel)
- Resize Panel to a comfortable size
(we'll be clicking it)
- Add a .gd script to your Panel
Paste the code below
(be sure to uncomment the if statement for either 2.1.4 or 3.0 alpha)
Add back the TAB characters
- Type a TAB in Godot.
- Select 1 tab character (drag mouse or shift+arrow keys)
- ctrl+c
- ctrl+r (for replace)
- in the first box, type 4 spaces
- in the second box, ctrl+v paste your tab character
- click Replace All
I had to click "Replace All" 3 times
Press F6
or click the button "Play the edited scene"
- Click + see your cursor change! + click + click ...
(see Output window to see which mode it is in)
=== determining InputEvent subclass type in _input(event):
differs .... ===
NOTE:
Godot 3.0 alpha 1 has removed the member variable type
from class InputEvent
, so the code will be different
depending on whether you run using 3.0 alpha or using 2.1.4
for 3.0 alpha --- uncomment this if statement on line 17
if( event is InputEventMouseButton and event.is_pressed() ):
for 2.1.4 ---------- uncomment this if statement on line 20
if( event.type == InputEvent.MOUSE_BUTTON and event.is_pressed() ):
=== .gd script to test set_default_cursor_shape(int shape)
===
remember to replace sets of 4 spaces with TAB character
# -- Have a wonderful day --
# ~ G r a s s H 0 P E r ~
extends Panel
var cursor_set_to = 0
func _ready():
set_process_input(true)
func _input(event):
## if statement depending on your version of Godot goes here :
# ------------------------------------------------------------
## for 3.0 alpha -- uncomment this if
# if( event is InputEventMouseButton and event.is_pressed() ):
## for 2.1.4 -- uncomment this if
# if( event.type == InputEvent.MOUSE_BUTTON and event.is_pressed() ):
cursor_set_to += 1
if cursor_set_to > 16 :
cursor_set_to = 0
set_default_cursor_shape(cursor_set_to)
if cursor_set_to == Control.CURSOR_ARROW :
print( "CURSOR_ARROW = 0" )
if cursor_set_to == Control.CURSOR_IBEAM :
print( "CURSOR_IBEAM = 1" )
if cursor_set_to == Control.CURSOR_POINTING_HAND :
print( "CURSOR_POINTING_HAND = 2" )
if cursor_set_to == Control.CURSOR_CROSS :
print( "CURSOR_CROSS = 3" )
if cursor_set_to == Control.CURSOR_WAIT :
print( "CURSOR_WAIT = 4" )
if cursor_set_to == Control.CURSOR_BUSY :
print( "CURSOR_BUSY = 5" )
if cursor_set_to == Control.CURSOR_DRAG :
print( "CURSOR_DRAG = 6" )
if cursor_set_to == Control.CURSOR_CAN_DROP :
print( "CURSOR_CAN_DROP = 7" )
if cursor_set_to == Control.CURSOR_FORBIDDEN :
print( "CURSOR_FORBIDDEN = 8" )
if cursor_set_to == Control.CURSOR_VSIZE :
print( "CURSOR_VSIZE = 9" )
if cursor_set_to == Control.CURSOR_HSIZE :
print( "CURSOR_HSIZE = 10" )
if cursor_set_to == Control.CURSOR_BDIAGSIZE :
print( "CURSOR_BDIAGSIZE = 11" )
if cursor_set_to == Control.CURSOR_FDIAGSIZE :
print( "CURSOR_FDIAGSIZE = 12" )
if cursor_set_to == Control.CURSOR_MOVE :
print( "CURSOR_MOVE = 13" )
if cursor_set_to == Control.CURSOR_VSPLIT :
print( "CURSOR_VSPLIT = 14" )
if cursor_set_to == Control.CURSOR_HSPLIT :
print( "CURSOR_HSPLIT = 15" )
if cursor_set_to == Control.CURSOR_HELP :
print( "CURSOR_HELP = 16" )
#Legal: CCzero
Hope this helps someone someday.
Or provides a bit of entertainment.
Peace,
~ G r a s s H 0 P E r ~