YoYoGames/GameMaker-HTML5

Multitouch input positions (device>0) are sometimes wrong on mobile devices (device /iOS.js SetLocation issue)

caroparo opened this issue · 3 comments

When a room has an enabled and visible view, SetTouchLocation includes extra logic that overwrites eventX, eventY values from touchHandler, making them incorrect, unlike g_EventMouseX, g_EventMouseY that are unmodified for device 0.

The view in question has custom scaling logic, so it's not the same size as the application_surface or gui size.
I'm not sure whether it's safe to simply remove the pView.GetMouseX, pView.GetMouseY logic, but that's what works for me.
Edit: Also, the mobile exports always have multitouch controls working as intended.

Related scripts and functions:
functions/Function_YoYo.js : device_mouse_x_to_gui, device_mouse_y_to_gui
device/iOS.js : touchHandler(event)
device/iOS.js : yyTouchEvent.prototype.SetTouchLocation

Attached is a sample project showcasing the issue of position mismatch between mouse=device0 and touch=device1.
Note the view size has an aspect ratio matching the canvas, but the sizes are different.
h5_view_multitouch.zip

pkraif commented

There's now an open PR for the fix, but I just wanted to let you know @caroparo that when you use device_mouse_x_to_gui, you need to draw it in the Draw GUI event, otherwise it will seem like it doesn't align. In regular Draw event you could usedevice_mouse_x.

@pkraif
Thanks for the tips and fix; the project was only made as a minimal example so I assumed it's clear enough, since the second touch aligns when it should not. Changing the event to Draw GUI does make the example more relevant, the mouse pos aligns while the 2nd touch does not, matching what's happening in my project.