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

Make joystick invisible when not is use #15

Closed
CraigBuilds opened this issue Jan 10, 2024 · 11 comments
Closed

Make joystick invisible when not is use #15

CraigBuilds opened this issue Jan 10, 2024 · 11 comments
Assignees
Labels
enhancement New feature or request

Comments

@CraigBuilds
Copy link

CraigBuilds commented Jan 10, 2024

Is your feature request related to a problem? Please describe.
The joystick takes up space on the screen.

Describe the solution you'd like
If the user is not holding down the mouse button, or is not touching the screen, the joystick should not be visible. The joystick area will appear wherever the user clicks / touches.

Describe alternatives you've considered
Create a custom system that checks for mouse state and modifies the joystick entity. But I do not know how to do this.

Additional context
N/A

@CraigBuilds CraigBuilds added the enhancement New feature or request label Jan 10, 2024
@SergioRibera
Copy link
Owner

Hello, this feature is related to a feature that I want to add, this one here (#7 ) to be able to externalize behaviors, but I am still thinking about how to do it, on the other hand I will help you temporarily with this, just give me a moment because I have changed system and I have to reconfigure the project

@SergioRibera SergioRibera self-assigned this Jan 10, 2024
@clinuxrulz
Copy link
Contributor

Just a thought. A quick hack would be to spawn the joystick as a child of a parent node. And have the parent node's display field of Style to Display::None while the screen is not touched. That way, no change to this library/plugin is required.

@clinuxrulz
Copy link
Contributor

clinuxrulz commented Jan 26, 2024

The EventReader<VirtualJoystickEvent> can simply be read to determine if the joystick is being used, then the Styles visible field of the joystick's root node can be modify in system reading those events.

So invisible joystick when joystick not used should be possible with no changes to this library/plugin. I may create an example to show how if I get time.

@CraigBuilds
Copy link
Author

An example will be brilliant thank you. One thing to consider when using this style of joystick (one that appears wherever you touch instead of staying in a fixed location), is that the joystick area needs to be the whole screen. This means it may need to support window resize events. It also means that the "knob" can be dragged around the whole screen, instead of being limited to a max distance from where it was first clicked.

@clinuxrulz
Copy link
Contributor

clinuxrulz commented Feb 16, 2024

I got close, but no cigar.

https://github.com/clinuxrulz/virtual_joystick/blob/invisible-joystick-example/examples/invisible.rs

The problem is the input's in virtual_joystick's PreUpdate system input get ignored while the joystick is invisible. So I don't think it is possible without a change to this library. Unless a PrePreUpdate schedule is possible.

@SergioRibera
Copy link
Owner

I would probably opt to do something with the color instead of hiding it, previously there was this in the examples

e57c8d4

@clinuxrulz
Copy link
Contributor

@SergioRibera that solves one problem. Another problem is knob.interactable_zone_rect gets updated at PostUpdate. So the touch/mouse down event gets missed by one frame when manually setting joystick position on touch/mouse down event.

@SergioRibera
Copy link
Owner

@clinuxrulz I hadn't noticed that detail, I'll see if I can fix it

@clinuxrulz
Copy link
Contributor

clinuxrulz commented Feb 16, 2024

PostUpdate probably is the right place, so it can handle dynamic joystick type.
We probably just need to support it out of the box with the library itself. Technically that interactive zone should be ignored for the invisible joystick type for touchstart/mouse-down filtering.
Invisible joystick would need a different kind of interactive starter zone. Sometimes you might want the joystick to only become activated with the left ½ of the screen is touch. E.g. invisible joystick on left and action buttons on right.

Invisible Joystick:

  • one type of interactive zone for setting the initial joystick position. E.g. ½ screen.
  • another type interactive zone for keeping knob movement in bounds.

@clinuxrulz
Copy link
Contributor

Its working now. No change to library needed. Just needed to make interactive area Val::Percent(100) while invisible (alpha channel 0.0), and change it to its normal size when not invisible (alpha channel 1.0).

@SergioRibera
Copy link
Owner

SergioRibera commented Mar 23, 2024

I will close this issue to follow up on the custom behaviors feature (#7 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants