Game Development Reference
In-Depth Information
has been proven to happen in quantum physics, real-world objects that we can actually
see with our own eyes have yet to show that effect.
Rigid bodies can sometimes penetrate each other and get stuck, especially if they're
constrained by joints that hold two or more bodies together and limit their range of mo-
tion. This can lead to undesirable trembling motions of the bodies as they struggle to
move apart while keeping their joint constraints satisfied. You may have seen this even
in modern games; for example, the ragdolls of dead actors in a first-person shooter
game can sometimes be seen in very unnatural body positions, their limbs not coming
to rest at all, causing the entire ragdoll to tremble or worse. Such events continue to
amaze and amuse players. Do a search for “physics glitch” on your favorite video site
and you'll see what I mean.
And of course there can be game-play issues. With rigid bodies, you never know what
will happen given enough players interacting with them. Eventually some players may
manage to block themselves and trap themselves in a dead-end situation, or they may
figure out how to exploit the physics simulation to be able to move to areas they
shouldn't be able to reach.
The Showdown: Box2D vs. Chipmunk
As I mentioned, cocos2d is distributed with two physics engines: Box2D and Chip-
munk. How should you choose between them?
In a lot of cases, it boils down to a matter of taste. Most developers argue along the
lines of the programming language in which the physics engines are implemented:
Box2D is written entirely in C++, whereas Chipmunk is written in C.
You may favor Box2D over Chipmunk simply because of its C++ interface. Being
written in C++ has the added advantage that it integrates better with the likewise
object-oriented Objective-C language. You may also appreciate that Box2D uses a
verbose language throughout, as opposed to the many one-letter variable names com-
mon in Chipmunk. In addition, Box2D makes use of operator overloading so that you
can, for example, add two vectors simply by writing the following:
b2Vec2 newVec = vec1 + vec2;
Search Nedrilad ::

Custom Search