- Edited
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?