I have a mouse/touch handler that performs several image/sound load/unload operations. This is like a "Next" button which moves from one scene to the other.
On some scenes this can take 3-4 seconds.
I noticed mouse/touch events are buffered during this time, and delivered to their respective handlers the moment the long lua operation finishes.
I want to control this event buffering, and remove old events from the previous screen, because visually the user clicks on the previously shown objects on screen but the events take place after they are thrown and new ones are shown on the screen.
I tried various other techniques with Timer object, but could not reach a satisfactory result.
I could load all objects for all scenes at the very start of the app, but that might bring out memory issues, since there are many scenes.
I could write a scene loader that releases the lua thread by using a Timer and uses a list of resource objects to load at every timer event and maybe also display a "loading next scene please wait" indicator, and during this time the mouse/touch events would be delivered but not used. But this would be a big task at the moment.
In short:
What are my options to control the buffered touch / mouse events after a lengthy lua event handler code finishes its job ?
Does mouse / touch events have an origination time comparable / compatible with os.timer() ?
This could be used to detect stale / old touch/mouse down events?
Thanks for developing such a highly productive environment.
I hope the opengl(es?) support arrives soon.
Comments
if you add to the scene a dummy empty sprite just before starting the process of switching to new scene (onExitBegin if you use scenemanager) and also you add eventhandlers to this sprite for all touch events, which do nothing except calling stopPropagation, and then when the switching ended (onExitend) you could remove this sprite and so every touch events incoming during the scene-change would be absorbed by this sprite.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
I modded my own version of page manager with a topologically similar change to your suggestion, but instead of adding empty sprite.. I coded a disable/enable all buttons option after which I ran fast a few rounds of empty/unprocessesed rounds of Event.TIMER events and after which I reenabled the all buttons at Event.TIMER_COMPLETE event. It seems the together with unhandled Event.TIMER events the disabled buttons ate up all the "old" touch events.
It would be simpler if there was something native to Gideros API such as a class level call to EventDispatcher.purgeEvents()
which removes all buffered events
and so I could call it at the end of lengthy lua operations.
also, although the above should be enough, if it is not, maybe the dummy sprite method is better than the timer method, as it aims directly to eat up the touch events, while your solution is not doing that, just waiting enough so that they disappear, but you never know how much you need to wait.
in any case i'm glad if you could make it to work as you wanted in some way or another.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
you can consider to change to scenemanager, it is never too late, at some point i also had to rewrite some of my code to be able to use scenemanager, but it may be worth to do once.
see my last comment here about how to change scenemanager according to my idea:
http://www.giderosmobile.com/forum/discussion/comment/21841#Comment_21841
Fragmenter - animated loop machine and IKONOMIKON - the memory game
At the moment, without using scenemanager, the long scene loading code disables all buttons, and prepares a timer to re-enabled them. The timer iterations is just 2, and interval is 10ms. The last iteration sends Event.TIMER_COMPLETE at which the buttons are re-enabled. The code change is minimal and all stale events generated in the long code execution get thrown away.