Game Development Reference
In-Depth Information
essential role in determining which collision callback method runs when two objects col-
lide.
If you take another look at the Item Physics tab shown in Figure 4-1 , you'll notice there's
a “Collision type” field. You can enter any name there, but it must be a legal Objective-C
identifier—meaning it should be all letters and digits, with no spaces or special characters
except an underscore, and the name must not start with a digit.
The Collision type identifier can then be used as the name of either or both col-
lisionTypeA and collisionTypeB parameters in collision callback methods.
Caution Setting or changing the “Collision type” setting does not affect wheth-
er any two bodies can collide or not. The “Collision type” is solely used to de-
termine which callback method, if any, runs when a collision between two bod-
ies occurs where at least one has a non-empty Collision type .
Give it a shot: open the Player.ccb and select the player sprite. Then switch to the
Item Physics tab and enter player in the “Collision type” field. You can then implement
the wildcard callback method in Listing 4-13 to be notified whenever the player starts col-
liding with another shape.
Listing 4-13 . Collision callback that runs when the player collides with any other body
-(BOOL) ccPhysicsCollisionBegin:(CCPhysicsCollisionPair
*)pair
player:(CCNode *)player
wildcard:(CCNode *)wildcard
{
NSLog(@“collision - player: %@, wildcard: %@", player,
wildcard);
return YES;
}
This method will just print a message to the debug Console. Note that the second paramet-
er's name is player , the same string you entered as the body's “Collision type.” The
third parameter's name is the special identifier wildcard , which stands literally for “any
body.”
Search WWH ::




Custom Search