darthdeus / comfy

Comfy is a fun 2D game engine built in Rust. It's designed to be opinionated, productive, and easy to use.
https://comfyengine.org
Apache License 2.0
717 stars 35 forks source link

Add Touch Support #93

Open Sigmoidle opened 7 months ago

Sigmoidle commented 7 months ago

I have exposed the following function to the user:

get_touch_locations() -> Vec<Vec2>

Things to check:

Example usage:

let touch_locations = get_touch_locations();
for touch_location in touch_locations{
    // do something with Vec2 touch location
}

Compiles with:

Works with:

Please try my test game at: https://sigmoidle.itch.io/comfy-touch-support-cat-ball-wow The itch.io page includes the repository for the test game.

PLEASE NOTE: The changes to devices.rs may not work for all users and should be reviewed.

Currently broken:

juh9870 commented 7 months ago

Seems to be broken on android (using the example game https://sigmoidle.itch.io/comfy-touch-support-cat-ball-wow)

https://github.com/darthdeus/comfy/assets/15922601/7934a6ed-0c0a-4126-8478-042266db7b9f

Sigmoidle commented 7 months ago

To add to @juh9870's message, this behaviour also happens on IOS.

The function get_touch_position() returns a position even when no fingers are on the screen.

Also, it seemingly only returns one finger at a time.

I'm not sure how to fix this, I'll need some help from some more experience rust developers.

juh9870 commented 7 months ago

Also, I believe that the touch API should have some level of interoperability with the mouse API. Even on the actual mobile devices, mouse pointers are not that uncommon, even as an accessibility feature: https://stackoverflow.com/a/54862570

Putting the burden of supporting both touch and mouse on the game developers is asking a bit too much, especially since developers coming from other languages would expect that they can just target one input method, and have the other work automatically, even if in a limited fashion.

Sigmoidle commented 7 months ago

I've updated this pull request to fix the multi-touch bug and the lingering touch bug. Please try the itch.io game to preview the changes.