comfy icon indicating copy to clipboard operation
comfy copied to clipboard

Add Touch Support

Open Sigmoidle opened this issue 1 year ago • 4 comments

I have exposed the following function to the user:

get_touch_locations() -> Vec<Vec2>

Things to check:

  • Currently the Vec2 is in screen position and not world position. Which should be default?
  • When no fingers are on the screen, this function returns an empty Vec<>, is this ok?
  • How can we make this function more "comfy" for the game developer?

Example usage:

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

Compiles with:

  • OS: macOS Sonoma
  • CPU: M2

Works with:

  • OS: IOS, Android
  • Browser: Safari, Chrome

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:

  • ~~No multi-touch support out-of-the-box~~ - fixed
  • ~~Touch position doesn't reset (to none?) when no fingers are on the screen.~~ - fixed
  • Cargo format pipeline doesn't pass? Could a more experienced rust dev help me with this one?

Sigmoidle avatar Mar 01 '24 13:03 Sigmoidle

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

juh9870 avatar Mar 01 '24 13:03 juh9870

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.

Sigmoidle avatar Mar 01 '24 13:03 Sigmoidle

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.

juh9870 avatar Mar 01 '24 13:03 juh9870

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.

Sigmoidle avatar Mar 01 '24 15:03 Sigmoidle