Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a project setting to automatically scale custom mouse cursors according to the viewport scale factor #11296

Open
aladvs opened this issue Dec 6, 2024 · 5 comments

Comments

@aladvs
Copy link

aladvs commented Dec 6, 2024

Describe the project you are working on

A 2D twin-stick shooter.

Describe the problem or limitation you are having in your project

Currently, custom mouse cursors only work at a specific size, and do not scale according to the resolution of the game. This is great if it's being used for it's intended purpose. Unfortunately, you cannot use this to create a twin stick shooter crosshair for the mouse, as you cannot scale the mouse cursor dynamically with the resolution.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Currently, accomplishing this is extremely difficult, as using a sprite instead as a software cursor introduces input lag. Extending the custom mouse settings would make the process of creating a 2D crosshair much simpler, such as those in games like Noita and Nuclear Throne currently have.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Image

If this enhancement will not be used often, can it be worked around with a few lines of script?

This can be worked around by generating different cursors at all resolutions and then picking a proper one based on the resolution. This is extremely cumbersome to do, and is not future proof.

Is there a reason why this should be core and not an add-on in the asset library?

Not possible without lag using GDScript. Extends existing cursor logic rather than adding a new feature.

@Calinou
Copy link
Member

Calinou commented Dec 6, 2024

This can be worked around by generating different cursors at all resolutions and then picking a proper one based on the resolution. This is extremely cumbersome to do, and is not future proof.

An easier workaround is to use Image.resize() on the cursor image before setting it in a script, with the scale factor determined by the following:

var scale_factor: float = min(
		(float(get_viewport().size.x) / get_viewport().get_visible_rect().size.x),
		(float(get_viewport().size.y) / get_viewport().get_visible_rect().size.y)
)

(The above snippet can be replaced by godotengine/godot#80965 in 4.4 onwards.)

To avoid blurriness at high scale factors, you could start from an image that is tailored for the highest scale factor your game is designed to reasonably support (e.g. the scale factor used when playing on a 4K display), then scale down from that.

@aladvs
Copy link
Author

aladvs commented Dec 11, 2024

This can be worked around by generating different cursors at all resolutions and then picking a proper one based on the resolution. This is extremely cumbersome to do, and is not future proof.

An easier workaround is to use Image.resize() on the cursor image before setting it in a script, with the scale factor determined by the following:

var scale_factor: float = min(
(float(get_viewport().size.x) / get_viewport().get_visible_rect().size.x),
(float(get_viewport().size.y) / get_viewport().get_visible_rect().size.y)
)
(The above snippet can be replaced by godotengine/godot#80965 in 4.4 onwards.)

To avoid blurriness at high scale factors, you could start from an image that is tailored for the highest scale factor your game is designed to reasonably support (e.g. the scale factor used when playing on a 4K display), then scale down from that.

This is a good workaround! Thanks.

Are the docs not accurate about the size of the image?
Image

@Calinou
Copy link
Member

Calinou commented Dec 11, 2024

Are the docs not accurate about the size of the image?

The warning is still accurate - you want to make sure your final cursor image size doesn't exceed 256×256 (128×128 on the web platform).

For example, this means that on a hiDPI display at 200% scale, the physical size of the cursor image must not exceed 128×128 DPI-independent pixels (64×64 on the web platform). This is because the image data is internally 256×256 (128×128 on the web platform), and that's what the limitation affects.

@arkology
Copy link

this means that on a hiDPI display at 200% scale, the physical size of the cursor image must not exceed 128×128 DPI-independent pixels (64×64 on the web platform). This is because the image data is internally 256×256 (128×128 on the web platform), and that's what the limitation affects.

It will be good to clarify this (about physical size) in the documentation.

@Calinou
Copy link
Member

Calinou commented Dec 11, 2024

It will be good to clarify this (about physical size) in the documentation.

The engine currently doesn't scale cursor images for you, so mentioning a notion of physical size would be misleading right now.

@Calinou Calinou changed the title Custom mouse cursor scaling Add a project setting to automatically scale custom mouse cursors according to the viewport scale factor Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants