Hello! Exciting to be able to ask some questions of some experts.
I’m working on my 3rd game, which happens to be my first platform game, and I have a general question that I haven’t been able to find a good answer to so far.
My games are exclusively code-based. No frames, no timelines, no gotoandplay, just pure AS2. I use pure code because I’m a programmer, and I’m stuck with AS2 because I need my game to submit a score to server at the end, and only have AS2-version of the score submit logic (plus I don’t know AS3).
I have a single movie clip which serves as the holder for the game logic:
onClipEvent(load)
{
// InitializeEverything
}
onClipEvent(enterFrame)
{
function leveldone()
{
timeleft = _root.timeleft;
for (i= timeleft; i > 0; i--)
{
_root.timeleft--;
_root.score += 10;
// force screen update here ????
}
}
// the MainLoop: ProcessEverything...
}
Everything is going pretty well with the game, the basic logic is all done. Now, when the player reaches the end of a level I call a support function called leveldone(). And one of the things that I would like to happen inside of this function is have the seconds remaining on the level’s countdown timer to be converted into bonus points. No problem so far.
But, what I would like to have happen is something like you might see in a Mario game, where you actually see the timer value quickly counting down, while the score correspondingly quickly counts up over a period of a few seconds.
I can add the code which does the countup/countdown, but obviously the screen is not updating each time I tweak the dynamic text, so only the final result is seen. If there was a function I could put inside my countup/countdown loop that would force the screen to be updated with the latest values of the score and the timer it would be perfect. But I’m not aware of such a function.
Now, I guess I could code up a special state inside the MainLoop that would handle this countup/countdown when a flag was set, but I would prefer to have the countdown/countup logic in a separate temporary mainloop, if possible. If I could somehow achieve this, it would allow me to also save checking a flag inside the MainLoop.
I remember from programming in X-Windows and Motif Widgets on UNIX that this was possible. You could at any point in the execution of the normal mainloop, setup a secondary mainloop that processed different events with some code like this:
while (specialLoop)
{
event = XGetNextEvent();
SpecialProcessEvent(event);
}
Does anybody have any suggestions, how, in completely AS2-based program, I can do something along these lines?
-
Either force a screen update while still processing within the MainLoop, or…
-
Branch off to a secondary MainLoop, do some stuff, then return to the MainLoop without having to check a new flag in each iteration of the primary MainLoop?