Game Development Reference
In-Depth Information
4. In the I]ej[Lh]ucnkqj`*]o file, add the following code in bold to the kjAjpanBn]ia event
handler:
bqj_pekjkjAjpanBn]ia$arajp6Arajp%6rke`
w
++Ikrapdalh]uan
lh]uan*t'9rt7
lh]uan*u'9ru7
++?khheoekj`apa_pekj
eb$lh]uan*depPaopK^fa_p$ajaiu%%
w
iaoo]ca@eolh]u*patp9Kq_d7
y
ahoa
w
iaoo]ca@eolh]u*patp9Jk_khheoekj***7
y
y
5. Save the I]ej[Lh]ucnkqj`*]o file and test the project.
6. You'll see the words No collision displayed in the dynamic text field.
Use the arrow keys to move the lh]uan object into the ajaiu object,
and the text field will display Ouch!! Figure 7-5 shows what this
looks like.
Not bad for a few simple lines of code, huh? If you move the lh]uan object
away from the ajaiu, the text field displays No collision again. (You'll find
the complete code for this example in the chapter's source files in I]ej[
Lh]ucnkqj`[.*]o.)
It gets even better.
Figure 7-5. The text changes
when the two objects touch.
Triggering a change of state
You can put any directives you like inside the eb statement that checks for a collision. In this example,
you'll use a ckpk=j`Opkl method to change the state of the ajaiu object.
You might recall from Chapter 3 that you can give Movie Clip objects new states by changing some-
thing about how they look on another frame. The first thing you need to do is modify the enemy
Movie Clip symbol. Mine is called Ksh, but yours might be called something else.
1. Double-click the ajaiu object in the Library to enter symbol editing mode.
2. Add frames or keyframes wherever necessary to extend the graphics from frame 1 into frame 2.
 
Search Nedrilad ::




Custom Search