If the program has to do something which will take a while what is the best way to show a busy cursor? Should I use the sprite library routines? [import]uid: 1813 topic_id: 307 reply_id: 300307[/import]
I would:
-
Load the wait-image which will be animated (this image will be placed, by default, in the stage-object/group)
-
Turn image off (imgWait.isVisible = false) and place it at the desired location on-screen
-
Make image the top-most display object in stage-group ( ex. imgWait.parent:insert( imgWait ) )
When it comes time to do work that may take awhile:
-
Make wait-image visible
-
Start up an “enterFrame” event handler which animates the wait-image
-
Do the work which takes awhile
-
Stop the “enterFrame” event handler ( see: Runtime:removeEventListener() )
-
Make wait-image invisible
HTH,
David [import]uid: 1581 topic_id: 307 reply_id: 436[/import]
David thanks for your advice. It helped me work out a solution. One problem appears to be that when you are servicing the enterFrame event nothing else happens. So what I did was use Lua’s coroutines.
To start a long computation I do:
thread = coroutine.create(longComputation)
in the enterFrame handler:
function enterFrameHandler(event)
…
if thread then
coroutine.resume(thread ) – starts it first time or resumes it subsequent times
end
…
end
function longComputation()
make visible some sort of “I’m busy image” (I did a progress bar)
do lots of stuff, periodically doing a coroutine.yield()
thread = nil – stop thread being processed by enterFrameHandler
end
The result is that frames are updated while the computation works.
Note Lua coroutines are non preemptive, so you are responsible for yielding periodically.
[import]uid: 1813 topic_id: 307 reply_id: 473[/import]
Forgot about co-routines…, but, yea, as they let you do thing cooperatively they would probably be a better choice than just using the enterFrame event. Cool! [import]uid: 1581 topic_id: 307 reply_id: 481[/import]