Game Development Reference
In-Depth Information
collision detection between instances in your games. Unfortunately, it's not difficult to spot that
something is not quite right in this version, as the character frequently gets stuck while walking or
jumping into platforms. This is because the collision masks are always changing to exactly match
the pixels displayed in the animation frames of the character. So sometimes collisions can occur
in one animation frame, but go away in the next when the sprite changes (see Figure 2-3). This
can then result in the character getting stuck, flipping back and forth between sprites. There are
also problems with the precise collision on the platforms themselves, where even tiny bumps
stop the character from walking across them properly.
Now run box_collision.exe and compare the difference. This version illustrates a simpler
box-based collision system for our platform game where the colored rectangles are now used for
calculating collisions. Of course, you wouldn't see the bounding boxes in the finished game, but
notice that it produces a much more solid and predictable playing experience. The result is better
because all the character sprites use an identically sized bounding box and there are no dips or
bumps in the shapes to give unpredictable results (see Figure 2-4).
Figure 2-3. A precise collision has occurred between the falling pod sprite and the platform (left), which
triggers a change to the standing pod sprite (right). However, as a result of the sprite change, there is no
longer a collision with the platform, so it triggers a change back to the original falling sprite, and so begins
an endless loop
Figure 2-4. Using box-based collision, the same collision is not triggered unless there is an overlap between
the bounding boxes (left) and crucially when the sprite switches (right), the collision box remains the same
 
Search WWH ::




Custom Search