Need advice on mouse/touch/msPointer best practice

For developers using the Construct 2 Javascript SDK

Post » Fri Sep 27, 2013 10:11 pm

I am refining my SpriteButton plugin because of some odd behaviors I've seen in our environment. NDA prevents me from saying what our environment is specifically, so I will just say that it is a browser embedded in an application, written by another party so I cannot modify the browser's behavior.

In SpriteButton, I copied code from DragDrop that registers for all three input types (msPointer, mouse and touch) -- the issue is that if multiple types are registered, multiple events are sent to the plugin. For specific example:

On the Android version of the environment, if I tap a button, I get a touch down, touch up, mouse down, mouse up, in that order. Because the mouse up is the last event, and a true mouse up needs to leave the button in a "hover" state, (as the pointer is still over the button) a tap results in a button showing its hover image after the click. Ideally I would only get touch events for a touch and not mouse events, but since I cannot modify the environment, I can only modify what events I register for.

On Windows, IE10+ supports msPointer, so I can just not register for mouse or touch if msPointer is supported, and thus only get one callback issued for one event. iOS doesn't support mouse, so I can just not register for mouse on that platform. Android theoretically supports both.

I can detect Runtime.isAndroid and Runtime.isiOS and not register for mouse events in both cases, but it feels a bit brittle to me. Does anyone know of a more robust way to filter out a mouse event that is a duplicate of a touch event? Obviously I could test the position values, but that isn't 100% reliable. Ideally I'd find something bulletproof.

In the meantime, I will probably just not register for mouse events on iOS and Android, but it does men my plugin could act funny on a system that supports both touch & mouse but not msPointer (such as Chrome under Windows 8, perhaps? I haven't tested, and IE supports msPointer)
B
6
S
1
Posts: 22
Reputation: 446

Post » Sat Sep 28, 2013 1:38 pm

I think if you call preventDefault() on the touch event, it ought to prevent the synthetic mouse event firing afterwards. But there's a bug in the stock Android browser where it always fires the mouse event afterwards. It shouldn't happen in Chrome for Android, which is a much better browser anyway and is gradually replacing the stock browser.
Scirra Founder
B
399
S
236
G
89
Posts: 24,529
Reputation: 195,390


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests