I have a very time consuming function (calculating moves in a strategy games) which takes quite long to execute. I don’t want my game to freeze while calculating, so how could I keep animations running and maybe updating a progress bar on the screen, while the function calculates?
[import]uid: 9644 topic_id: 7862 reply_id: 307862[/import]
for animations, have you tried transition.to? [import]uid: 12455 topic_id: 7862 reply_id: 27915[/import]
I am using manual animations, so I wonder WHEN Corona does any screen updates… between two function calls? Or at fixed intervals, no matter if a function still executes? I think I read something about screen refreshes in the manual but I can’t find it anymore =( [import]uid: 9644 topic_id: 7862 reply_id: 27987[/import]
corona does screen updates between enterFrame’s
if your game code takes longer to execute than the frame rate, you’re going to see visual slow down [import]uid: 6645 topic_id: 7862 reply_id: 28008[/import]
Hm, I am thinking of two ways to prevent visual slow downs while my calculation intensive function is performed (it needs about 2-3 seconds to perform, it’s a round based strategy game):
-
Using an enter frame listener to calls the calculating function once per frame. The calculating function measures the time passed since it has been called. If it exceeds the time of a frame (33 millisecs), it remembers its state and aborts. The next time the function is called, it will continue calculating on the remembered state. Would this work?
-
Using a coroutine -I am not familiar with LUA coroutines yet, but would this eventually be the way to do it?
[import]uid: 9644 topic_id: 7862 reply_id: 28576[/import]
I think a coroutine would be the way to go, but I can’t advise there.
My best advice would be to take a serious look at why your calculation is so slow. Could it simply be made faster by reducing the number of loops or perhaps could it be broken into stages, called successively, one every 100 milliseconds?
Executing lots of code (especially the whole or fragments of a processor intensive function) during EnterFrame events is a bad idea because of the frequency of the EnterFrame calls. [import]uid: 8271 topic_id: 7862 reply_id: 28752[/import]