Copy link to clipboard
Copied
Hello,
i have a problem with touch-events not being accurate on Mobile devices. On the desktop there are no problems.
I noticed it first when working with Starling. i have a sprite moving from left to right over the stage, which the user has to tap, i.e. a pickup/coin.
When the coin is not moving, the mouse/touch event fires correctly, but when it is moving over the stage, i seem to touch the stage just before the coin to get a touchevent on the coin. this seems to be increasing, the faster the coin is moving.
Later on, i worked with away3d, where i have a rotating mesh (also a pickup/coin). When it is not moving, i can click it correctly, but when it is moving, the same thing seems to happen as it does with the starling-sprites.
I'm starting to wonder if it is starling and/or away3d related, or maybe it has something to do with stage3d. It seems that the air-player internally thinks the object is already further then it actually is on the screen.
i created 2 posts for this issue also on stack overflow:
http://stackoverflow.com/questions/17103740/as3-air-mobile-click-and-or-touchevents-on-moving-object...
http://stackoverflow.com/questions/16857841/starling-touchevent-on-sprite
Anyone also experiencing this issue? Am i forgetting something? I tried it on different devices, different frame-rates, different events and different approaches (touch-event on stage instead of the object itself etc).
Thanks in advance
- Marijn
Copy link to clipboard
Copied
I'll take a crack at a possible place to investigate. Just speaking to the Starling code you posted (maybe the other is the same),
I am seeing a 'onEnterFrame' function of yours and there you are driving the movement of an object explicitly when you get an onEnterFrame.
Are you attaching an ENTER_FRAME listener to the native stage itself or are you using a Starling ENTER_FRAME event?
Look at the Starling source and see the sequence that happens in nextFrame() and advanceTime(passedTime), which like any framework is what defines the engine's unique event loop sequence.
You don't say which version of Starling you are using (and the order of function calls inside advanceTime() might have changed between versions) so you want to confirm with the version you are using:
In the latest Starling 1.3 the sequence goes:
1) TouchProcessor.advanceTime
all the latest queued touches are processed, hitTested against objects, updated and events are sent out for touches
based on their found targets
2) stage.advanceTime
this is where the Starling ENTER_FRAME is dispatched to all listeners of the Starling version of ENTER_FRAME
3) juggler.advanceTime
any animations, tweens and IAnimatable objects are told to update their time
4) Finally render() is called after advanceTime(), using latest positions of the display list rendered to the screen
Given that you are forcing an object movement in an ENTER_FRAME trigger, if it is a Starling triggered enterFrame, then you might be updating its position and getting it rendered into a new position *after* the touches have already processed for the same 'current frame'.
One way to test if this is the source of your issue, if you are listening on a Starling ENTER_FRAME event, change your onEnterFrame function that is moving an object explicitly and instead attach that function to the *nativeStage*'s Event.ENTER_FRAME only, and use a priority > 0 so that it will be called *completely before* Starling's event loop is processed for the same nativeStage ENTER_FRAME event.
nativeStage.addEventListener(Event.ENTER_FRAME, yourEnterFrame, false, 1, true);
That should move the object to its new position *before* Starling's touch processing occurs, and I wonder if you would see a difference in your attempts to touch the object when it is appearing on screen.
Just a conjecture on my part, haven't tried it, just a theory.
Copy link to clipboard
Copied
Thanks, that does make sense in theory. I think i have the enterframe listening on the starling-stage indeed. I'll give it a try this monday, as i dont have the source here with me.
I'll let you know how it works out.
Copy link to clipboard
Copied
Hey Jeffrey,
It seems like your solution helped a bit, but it is still not as accurate as i would like it to be
I'll keep looking into it some more, if i ever found the issue and/or solution, i'll post it here aswell