This came to me as a surprise while trying to write a script, which can run in iOS, HTML5, Flash and Neko. I knew it can be done by cross-compiling through NME to all these target platforms. While this hold good almost in every case but when it comes to regular stage update or the ENTER_FRAME event, it is a problem.
Well, if you are a flash developer and depend on ENTER_FRAME event for a long time, then it may come to you as a surprise like me. The game loop as the gaming engines call it, now has to be worked upon. Fortunately we have a timer function in haXe and that quite fits the game.
Before going ahead in timer, lets see the unreliable nature of ENTER_FRAME for all targets. Firstly I was creating different circles in stage area with an ENTER_FRAME, while that worked well in all platforms, I thought its good to go for all. But then I tried to rely upon the same ENTER_FRAME event with a drag and drop and position change of the elements. Whoa!! That does not work! I stopped relying on the ENTER_FRAME event and changed that with Timer and everything is back in the action again.
The haXe timer code is a little different than Flash timer and the code looks as below.
var timer = new Timer(10); //10 is the time difference in milliseconds between the timer call
timer.run = onEachTimerTick;//its kind of event listener
function onEachTimerTick():Void {}
For me, ENTER_FRAME event only worked for Flash targets and nothing else. So be careful if you want to target other delivery methods.
Happy coding!
Hey, this might solve the issue I’m having…
I was originally avoiding framerate dependency with the ENTER_FRAME event by using a Date timer, but then I found out that the Android / C++ implementations round down to seconds instead of milliseconds.
Apparently neko.Sys.time(); gives me what I want, but its not available under my current build flags.
So then… Timer()? might that solve my issue… investigating now.
Update, this seems to work for me, using Timer.stamp();
Thanks John,
thats a perfect way to update the screen at a particular interval.
Have you seen the Actuate lib for tween animation, thats just to make the tweens, but thought it may help.