Game Development Reference
In-Depth Information
It's also worth noting that box-based collision is faster than precise collision detection
(because it is very quick to mathematically calculate whether two rectangles overlap, but slower
to compare all the pixels between two images). Therefore, as far as collision in platform games is
concerned, box-based collision is a safer, faster, and more reliable alternative to precise, pixel-
based collision. That's why it's important that we make use of box-based collision detection in
our game as well as ensuring that the dimensions of each box are the same for all the different
sprites of the main character (otherwise, you could still get the kind of sprite-switching problem
shown in Figure 2-3). So this is what we will do next.
Editing the Sprite Collision Masks
1. Reopen the Sprite Properties for spr_pod_fall_left by double-clicking on it in the
resource list.
2. Click the Modify Mask button and the Mask Properties form will appear.
3. Under Image , ensure that the Show Collision Mask is enabled so that you can see the
results of the changes you will make.
4. Under Shape , select Rectangle and under Bounding Box, select Manual .
5. Set the Bounding Box dimensions to Left 24 , Right 40 , Top 24 , and Bottom 60 , as
shown in Figure 2-5. Notice how the shaded area on the collision mask alters to reflect
the changes you make.
6. Repeat steps 1-5 with identical values for spr_pod_fall_right , spr_pod_jump_left ,
spr_pod_jump_right , spr_pod_stand_left , spr_pod_stand_right , spr_pod_walk_left ,
and spr_pod_walk_right (that is, all of the Fishpod sprites). All of these sprites must
have the same bounding box dimensions for the game to work correctly.
7. Repeat steps 1-5 for spr_rock_middle using Left 0 , Right 31 , Top 5 , and Bottom 20 . This
is the full-width platform sprite. Note that the bounding box doesn't include the top-
most pixels of the rock, as this allows the character to have a small overlap when it is
standing on the rock. It also doesn't include much of the spiky underside of the rock as
it is cosmetic.
8. Repeat steps 1-5 for spr_rock_begin using Left 16 , Right 31 , Top 5 , and Bottom 20 . This
is a half-width platform sprite, but it still needs to have the same Top and Bottom
values as the full-width platform to ensure smooth movement across them.
9. Repeat steps 1-5 for spr_rock_end using Left 0 , Right 15 , Top 5 , and Bottom 20 .
The remaining five sprites ( spr_lava_begin , spr_lava_middle , spr_lava_end , spr_gold , and
spr_pansy ) can actually keep their default Precise Collision Checking setting. Fishpod won't
physically interact with them in the same way because they are either hazards that will kill him
instantly or collectables that will disappear on contact. Because they don't have a physical effect
on Fishpod, it isn't essential for them to use the same approach to bounding-box collision.
You may also be wondering why we set up a bounding box that is much smaller than the size
of the character (after all, a bounding box suggests a boundary that is outside the sprite), but
there are actually two good reasons to do this:
 
Search WWH ::




Custom Search