Game Development Reference
In-Depth Information
if ([node isKindOfClass:[CCSprite class]] && (node.tag == 1 || node.tag == 2))
{
// The sprite's collision radius is a percentage of its image width.
// The same factor is used in the checkForCollision method.
CCSprite* sprite = (CCSprite*)node;
float radius = sprite.texture.contentSize.width * 0.4f;
float angle = 0;
int numSegments = 10;
bool drawLineToCenter = NO;
ccDrawCircle(sprite.position, radius, angle, numSegments, drawLineToCenter);
}
}
}
#endif
Labels and Bitmap Fonts
Labels are the second-most important graphical element of cocos2d games, right after
sprites. The easiest and most flexible solution seems to be the CCLabelTTF class, but
its performance is terrible if you need to change the displayed text frequently. The al-
ternative is the CCLabelBMFont class, which renders bitmap fonts instead of
TrueType fonts. Along with that I'll introduce you to Glyph Designer, an elegant tool
for converting TrueType fonts into bitmap fonts and enhancing them along the way
with effects like shadows, color gradients, and so on.
Adding the Score Label
The game needs some kind of scoring mechanism. Let's add a simple time-lapse
counter as the score. Start by adding the score's Label in the init method of the
GameLayer class:
scoreLabel = [CCLabelTTF labelWithString:@"0" fontName:@"Arial" fontSize:48];
scoreLabel.position = CGPointMake(screenSize.width / 2, screenSize.height);
// Adjust the label's anchorPoint's y position to make it align with the top.
Search Nedrilad ::




Custom Search