Game Development Reference
In-Depth Information
y
eb$]llha*depPaopLkejp$necdpPelT(necdpPelU(pnqa%%
w
_khheoekj`ena_perao***
y
If the shape of the ]llha object now comes into contact with either of these points, a collision is
detected. I'm sure you can see how you could use this alongside depPaopK^fa_p to really fine-tune
your collision-detection system.
Figure 7-30. Calculate the points that you want to use in the collision.
Using hitTestPoint to create an environmental boundary
Let me show you a neat little trick using depPaopLkejp that you'll almost certainly find useful in some
of your games. Have a look at the scene that you built in ejpan]_peraLh]ucnkqj`*bh]. You can make
the lh]uan object move all over the stage. However, if this were a realistic scenario, the pig should not
be able to move off the hill into the sky. (I could make a little comment here about “when pigs fly,”
but good taste got the better of me this time!) Wouldn't it be nice if you could just confine its range
of movement to the area of the hill? You can, with a little help from depPaopLkejp.
1. Make sure that your lh]uan object is within the area of the dehh object. If its center t and u
position is not on the hill, you won't be able to move it when you test the project.
2. Add the following code to the kjAjpanBn]ia event handler (note that the eb/ahoa statement
from the previous example was removed to make sure that the effect of this new code is as
clear as possible):
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
ajaiu*ckpk=j`Opkl$.%7
da]hpd*iapan*se`pd))7
 
Search Nedrilad ::




Custom Search