Game Development Reference
In-Depth Information
The last thing is to set the lh]uanD]o=llha variable to pnqa, which prevents the program from trying
to pick the apple up again if the lh]uan object already has it. The directives that drop the apple are
just as straightforward:
op]ca*]``?deh`$]llha%7
]llha*t9lh]uan*t7
]llha*u9lh]uan*u7
lh]uanD]o=llha9b]hoa7
eb$ajaiu*depPaopK^fa_p$]llha%%
w
iaoo]ca@eolh]u*patp9Pd]jgo7
y
You first use the ]``?deh` method to make the ]llha object a child of the op]ca object, which frees
it from bondage to the pig. Remember that the op]ca object is the parent object of all objects on the
stage, including the lh]uan and ajaiu objects. Objects that are children of the stage are at the top of
the food chain and are footloose and fancy free. The ]llha object now no longer has to mindlessly
follow the lh]uan object around and can get into any of its own trouble that it wants to.
The next thing was to give the ]llha object the same t and u positions as the lh]uan object. This fixes
it on the stage at its current position, which looks like it's being “dropped.” The lh]uanD]o=llha vari-
able was set to b]hoa, which allows the player to pick the apple up again later.
The last thing you did was actually a bit of a bonus. You added the following nested eb statement:
eb$ajaiu*depPaopK^fa_p$]llha%%
w
iaoo]ca@eolh]u*patp9Pd]jgo7
y
It checks to see whether the ajaiu object is touching the ]llha object. If it is, Thanks!! is displayed in
the dynamic text field. Awww . . . friends at last! (You can find the complete code for this example in
the I]ej[Lh]ucnkqj`[2*]o file.)
Learning the bad news about hitTestObject
First, let me just say that I love the depPaopK^fa_p method! You can see from these examples what
incredible power it can give you with just a few lines of code, a little imagination, and a bit of simple
logic. I'm sure your head must be swimming with ideas for games already. If you have any doubts, let
me just confirm to you right now: yes, you have all the skills you need already to start making them!
I won't stop you; go ahead, take a break from this chapter and start building them if you feel inspired.
A whole universe of possibilities exists!
But before you do go any further, take a closer look at just what makes depPaopK^fa_p tick. This must
be said, dear reader: depPaopK^fa_p holds a deep, dark secret that will cripple your games if you don't
understand it.
 
Search Nedrilad ::




Custom Search