Game Development Reference
In-Depth Information
programming form to do so. (If you do leave it out, AS3.0 will add it automatically when it compiles
the program.)
Next is the ^hk_g function definition:
The op]pe_ keyword means that you can use this method directly in any other class, in the format
?khheoekj*^hk_g, without having to make an instance of the class first. (If that's not too clear right
now, it will make a little more sense later in the topic when you work more closely with instances of
classes.) For now, just know that it makes it very easy to use this method anywhere in the program.
The other important things about this function definition are its parameters:
These are local variables that are defined with the type Ikrea?hel. In the I]ej[Lh]ucnkqj`*]o file,
you used this line of code to call the method:
Both lh]uan and s]hh are Ikrea?hel objects, so it makes sense that k^fa_p= and k^fa_p> should
be typed as Ikrea?hel objects, too. When the method is called, a reference to the lh]uan object is
copied into the k^fa_p= variable, and a reference to the s]hh object is copied into the k^fa_p> vari-
able. Whenever you see k^fa_p= and k^fa_p> in the body of the method, you can replace them with
lh]uan and s]hh in your mind if that helps you better understand how the code is working.
To allow the player to push the wall, the order of the objects in the method call is reversed like this:
The s]hh object was referenced by the k^fa_p= variable. The roles were reversed, and the s]hh object
was forced to reposition itself to avoid overlapping with the moving lh]uan object, creating the push-
ing effect.
The first few lines of code inside the ^hk_g function definition initialize the method's local variables:
If you're this far into the topic, you're pretty much an expert on half-widths and half-heights! But the
last two lines deserve a good look. Let's start with this one:
Search Nedrilad ::

Custom Search