Game Development Reference
In-Depth Information
If you notice any of the borders falling down, you forgot to set them to Static. In that case,
open the corresponding CCB file and check that Static is selected on the Item Physics tab.
Tip You can quickly open a CCB file by double-clicking on its thumbnail in
the Tileless Editor View.
If it's done correctly, the player should no longer be able to move or fall outside the level.
Congratulations! You now have collisions in your level.
Interlude: Physics Debug Drawing
There's one important aspect about collision shapes you have to memorize: the physics
engine couldn't care less about what's drawn on the screen. It considers only its internal
state.
Image and collision shapes, for instance, may not always match up exactly, perhaps
caused by an editing accident in SpriteBuilder or simply because you've modified the im-
age contents without adapting the sprite's collision shape. To debug such issues, it is very
helpful to turn on physics debug drawing once in a while.
Caution Debug drawing will slow down your game. If you want to assess your
game's performance or simply play the game, be sure to have physics debug
drawing turned off.
To turn debug drawing on, add a new BOOL to the GameScene.m in Xcode as seen in
Listing 4-7 .
Listing 4-7 . Add the debug draw ivar
@implementation GameScene
{
// Other variables omitted
BOOL _drawPhysicsShapes;
}
Search WWH ::




Custom Search