quasilyte / ebitengine-input

A Godot-inspired action input handling system for Ebitengine
MIT License
66 stars 8 forks source link

Is it possible to catch a "click&pull" and "touch&swipe" event? #42

Open TLINDEN opened 5 months ago

TLINDEN commented 5 months ago

I need the user to be able to click on an object and pull it into some direction. When the user releases the mouse button, the object would move into the desired direction. And I need the same behavior with a touch pad (mobile).

Is this possible with this module somehow?

Thanks in advance, Tom

quasilyte commented 2 months ago

Hi!

There is nothing builtin support for this kind of thing as I'm not sure how it fits a single key/gesture format, but it's quite easy to implement it. With that being said, maybe it will be added one day if there is an elegant way to do it.

This chunk of code handles many kinds of "scrolls" (a very close thing, you can probably see how to adjust it for your needs): https://github.com/quasilyte/roboden-game/blob/9a5d355f3ddcd0767c9083233bc814f0b54246cf/src/scenes/staging/camera_manager.go#L104-L171

It has middle-mouse button click-and-pull scrolling that you're interested and it works identically on mobiles.

So basically, for mobiles you need to remember the gesture start pos. Then you need to wait until the first tick the action is no longer active (or use "released" event, but I don't think it works with touches right now?). Then you have 2 positions: one from the start and one at the end of the gesture.

For mouse, it's basically the same.

quasilyte commented 2 months ago

This specific issue can make the game-side implementation a bit easier (at least for the mouse part of things): https://github.com/quasilyte/ebitengine-input/issues/39

quasilyte commented 2 months ago

Regarding the "released" tap inputs: #38