In all of my projects with custom cursors, I use this code:

extends Node

var sprite = preload("res://cursor.png")
var normal_window_size := Vector2(ProjectSettings.get_setting("display/window/size/width"), ProjectSettings.get_setting("display/window/size/height"))

func _ready() -> void:
	get_viewport().connect("size_changed", self, "cursor_update")
	cursor_update()

func cursor_update():
	print("cursor resized!")
	var current_window_size = OS.window_size
	var scale_multiple = min(floor(current_window_size.x / normal_window_size.x), floor(current_window_size.y / normal_window_size.y)) + 1
	
        var img = sprite.get_data()
	img.resize(sprite.get_width()*scale_multiple, sprite.get_height()*scale_multiple, Image.INTERPOLATE_NEAREST)
	var imgtex := ImageTexture.new()
	imgtex.create_from_image(img)
	
	Input.set_custom_mouse_cursor(imgtex, Input.CURSOR_ARROW, Vector2(0, 0))

But the "size_changed" signal in the game's viewport is only called when the window mode is 2D.
Is there any way to detect when the user resizes the game window with the Viewport mode?

  • You could set a timer that checks OS.window_size and sees if it is different and then call your function.

    It's unlikely that users resize their window that often. so checking once a second (or even a few seconds) is probably enough.

If you use viewport than the size has not changed. It is just stretched to fill the window.

But I'm unsure of what you are doing. I don't believe you need the window size or actual mouse position for a custom cursor.

  • Ly97 replied to this.

    cybereality
    What I'm doing is resizing the cursor sprite correctly to the window size. So it's bigger or smaller depending on the window.

    You could set a timer that checks OS.window_size and sees if it is different and then call your function.

    It's unlikely that users resize their window that often. so checking once a second (or even a few seconds) is probably enough.