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

Best Way to handle touch as directional control #71

Open
ningacoding opened this issue May 20, 2022 · 3 comments
Open

Best Way to handle touch as directional control #71

ningacoding opened this issue May 20, 2022 · 3 comments

Comments

@ningacoding
Copy link

Hello, what's the best Way to handle touch user input? in order to build a simple directional (up,right,down,left) control.

The touches only have type 'move', 'long-press', etc.

Is there a Way the touches gives the orientation natively?

Adding event types like 'move-left', etc.

@ningacoding ningacoding changed the title Beat Way to handle touch as directional control Best Way to handle touch as directional control May 20, 2022
@bberak
Copy link
Owner

bberak commented May 21, 2022

Hi @ningacoding,

The touch event should have enough data in its payload to help you determine direction. Something like:

touches.filter(t => t.type === "move").forEach(t => {
    let finger = entities[t.id];
    if (finger && finger.position) {
      finger.position = [
        finger.position[0] + t.delta.pageX,
        finger.position[1] + t.delta.pageY
      ];
    }
  });

For something with a little more functionality, you can take a look at the Gamepad Controller System from the template project.

Hope that helps!

@ningacoding
Copy link
Author

Hi @bberak , thank you for your answer.

with Gamepad Controller System, How i detect "up", "left", "down", "right" events?

I just need to call dispatch("up") to fire event, but i don't under stand the code inside gamepad-controler.

I already added the component into my App:

msedge_dfyS9gB3Zu

But i don't understand how it works, I move the D-Pad, it just turns from transparent to white and viceversa. I don't see D-Pad move.

@helloworq
Copy link

Hi @bberak , thank you for your answer.

with Gamepad Controller System, How i detect "up", "left", "down", "right" events?

I just need to call dispatch("up") to fire event, but i don't under stand the code inside gamepad-controler.

I already added the component into my App:

msedge_dfyS9gB3Zu msedge_dfyS9gB3Zu

But i don't understand how it works, I move the D-Pad, it just turns from transparent to white and viceversa. I don't see D-Pad move.

Hi,Could you please help me how can i add the gamepad-controller into my own project. i have tried it serval times,but it dose not work

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

No branches or pull requests

3 participants