need a way to scale up a custom cursor in code
The demo code below shows how to make and apply a scaled image.
@export var texture: Texture2D
# Image can be modified, ordinary Texture2D doesn't
var image: Image # We keep the original one
func ready() -> void:
# Get the actual image data from a Texture2D
image = texture.get_image()
func set_cursor_scale(scale: float) -> void:
var scaled := image.duplicate()
# Pixel counts are integars, so we cast Vector2 (using float) to Vector2i (using int)
var size := Vector2i(scale * image.get_size())
# Resize the image with bilinear interpolation
scaled.resize(size.x, size.y, Image.INTERPOLATE_BILINEAR)
# We finally set the scaled image for the cursor
DisplayServer.cursor_set_custom_image(scaled)
1 Like