Game Development Reference
In-Depth Information
If it passes this second test, the main part of the event handler is allowed to run. The first thing that
happens is that the object is made a child of the first next available item box. This places the object
into one of the item boxes at the top-right corner of the stage:
Let's break this down into two smaller parts. First, there's this bit of code:
It figures out which item box is free by finding out how long the [_khha_pekjF]n array currently is.
If no objects have yet been collected, the array's hajcpd property is zero. This means that the item
box that is used to store the object is epai>kt,. epai>kt + , equals epai>kt,. epai>kt, is the first
Let's look at another example. If 2 objects have already been collected , then the hajcpd of the
[_khha_pekjF]n array is .. Because you started naming the item boxes at zero (,), . is the last box,
the third one. That means that epai>kt + . equals epai>kt., which is the third box.
I know; it's confusing! But run it through a few times in your head or on a piece of paper, and it will
start to make sense.
An important thing to keep in mind is that this bit of code uses square brackets, WY, to dynamically
create the name of the item box that you want to move the collected object to. When two bugs have
been collected, for example, the code interprets this:
to mean this:
Make sense?
Once you have the name of the object, you can trigger one of that object's methods. That's what the
second bit of code is:
It adds the collected object as its child, which causes the object to attach itself to the item box. You
can see this happening visually on the stage when one of the bugs is caught.
To make a bit more sense of this, imagine that the bhu object called this event and happened to be the
second object collected. The entire directive would be interpreted like this:
The next job is to center the object in the item box. That's the work of these two lines:
Search Nedrilad ::

Custom Search