Hi All!
I am currently using Event.ENTER_FRAME for my "game loop" (moving objects, keeping track of time, etc) however this loop is not at a constant speed (runs faster on my phone than the emulator) and runs at the limit of the hardware so sometimes when moving an object it lags a bit when (i guess) something else is happening on the phone/computer.
I need a game loop that runs at a constant speed, and doesn't lag out at all. I was thinking of using a timer that calls itself (ie. infinite loop) and has a "break" ability built in when needed (end of level, character death, etc).
Is there a better way to do this? It seems very messy.
Thanks for the help!
edit: I have used the Event.ENTER_FRAME before as a game loop without any problems (on version 2013.09) so I am not sure if I am doing something wrong this time, or its implementation has changed?
more edit: This time I do have multiple Event.ENTER_FRAME events set to call DIFFERENT methods, I am not sure if this might cause problems for the runtime trying to sync up the different events?
Comments
Well enter frame does as event says, it is executed everytime the screen is redrawn.
You could achieve a more constant time with Timer, and we are even considering providing a constant time event in future, but in the end the screen still won't be redrawn until enter frame event.
So instead of slowing the game down, I think constant time would provide more jumping kind of effect on slow devices.
But what you want to use is completely up to you
Using timer should not be so messy, set it up in the scene init and dispose in scene exit begin event of SceneManager.
As for other questions, I think enter frame was not changed for quite some time, and calling it on multiple objects also should not have such effect. Maybe problem is something else, you can check this thread for some info:
http://giderosmobile.com/forum/discussion/4448/fps-onenterframe-and-bottleneck-performance/p1
Likes: incipient
This is the "lag" i was talking about: http://1drv.ms/1gcVCDS I will use the timer and avoid this problem.
Thank you again for your help!
I just threw this post up, could be helpful.
http://giderosmobile.com/forum/discussion/4506/move-sprites-more-efficiently#Item_1
As you say, the gideros framework is really efficient, but you need to use it with "best practices" to get the most out of it
If you were NOT to service your vehicle, it would still run (to a point) but would run better if you serviced it regularly.
Similarly, Gideros is efficient and good practices help extract the maximum out of it.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps