Game Development Reference
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):