Game Development Reference
In-Depth Information
Keep in mind that if two bodies' Categories and Masks prevent them from colliding,
their corresponding collision callback methods will not fire either. Likewise, if you are
mainly interested in determining which types of bodies have collided in order to run cus-
tom code, all you need to set up is the Collision type identifier.
Tip Editing Categories and Masks is required only when it comes to preventing
collisions with certain types of bodies. But once you start editing them for one
or more bodies, it may be required to edit Categories and Masks of seemingly
unrelated bodies to ensure certain bodies will still be colliding.
Letting the Player Leave
Since this game requires the player to move from A to B, where A is left and B is right,
there's got to be something at B that brings the player to a new level. This is where you'll
need an exit of sorts and a collision callback method that triggers the exit-level code. This
should be straightforward with what you just learned.
Creating an Exit Node
In SpriteBuilder, right-click the Prefabs folder in the File View and create a New File.
Name the file Exit1.ccb , and change its type to Sprite before clicking the Create but-
ton. Then select the root CCSprite in the Timeline, and on the Item Properties tab, click
the “Sprite frame” drop-down menu. You can use any image, but when you are using the
topic's example graphics you should select the SpriteSheets/Level1a/
level1_foreground_doughnut.png . The doughnut will act as the exit object for
the first world.
With the sprite still selected, switch to the Item Physics tab. Select the “Enable physics”
check box, and change the body type to Static; this prevents the exit node from moving or
rotating due to gravity or other forces. Then enter exit in the “Collision type” field. This
will allow you to easily determine when the player collided with this specific object.
Leave the Categories and Masks fields empty so that the player surely collides with the
exit node.
Search WWH ::




Custom Search