Game Development Reference
In-Depth Information
Although the bkn loop is a perennial favorite, AS3.0 allows you to create loops in a few other ways
as well. You can also create a sdeha loop or a `k)sdeha loop. They all do the same things as the bkn
loop, although they have nuances that might be useful in certain situations.
The sdeha loop can be particularly useful for games. It looks like this:
sdeha$ ]_anp]ej_kj`epekjeopnqa %
The sdeha loops don't run for a set number of times; they run as many times as they need to until the
condition becomes b]hoa. When you use sdeha loops in your programs, you have to make sure that
the condition eventually will become b]hoa. If it doesn't, the loop will run “forever” and the Flash
Player might hang. The Flash Player usually quits the loop itself if it runs for 15 seconds without end-
ing, but sometimes it doesn't! Use sdeha loops with caution and always save your work before you
test them.
I won't be covering sdeha and `k)sdeha loops in detail in this topic, but it's worth doing a bit of
further research into them just to see what they're capable of. For more information, see the sec-
tion titled “ Looping” in the chapter “ ActionScript Language and Syntax,” from Adobe's online docu-
ment, Programming Adobe ActionScript 3.0 for Adobe Flash (dppl6++dahl*]`k^a*_ki+aj[QO+
Looping through platforms
The platforms all share the same instance name, except for the number that appears at the end of
their name. You can make the platform collision detection code much more efficient by putting one
directive inside a bkn loop and then repeating that directive for as many times as there are platform
instances. All you need to do is replace the number in the instance name with the bkn loop's index
If that sounds confusing, it's actually much easier to understand when you see it put into practice:
1. In the I]ej[>qc?]p_dan*]o file, change the kjAjpanBn]ia event handler so it looks like this:
2. Save the I]ej[>qc?]p_dan*]o file and test the project. The cat can still jump across every plat-
form, but the code is much more efficient.
Search Nedrilad ::

Custom Search