- In HelloWorldScene.h create a new layer for score:
- CCLayer* scoreLayer;
- In HelloWorldScene.h import “CCLabelTTF.h” and add:
- int numScore
- CCLabelTTF* scoreLabel;
- In HelloWorldScene.m
- Initialize scoreLayer and add it to the scene
- scoreLayer = [[CCLayer alloc] init];
- [self addChild:scoreLayer z:2];
- Initialize the amount of numScore (numScore = 0;)
- Initialize what scoreLabel is going to hold
- scoreLabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"Score: %d", numScore] fontName:@"Arial" fontSize:28]; (note: available fonts - http://daringfireball.net/misc/2007/07/iphone-osx-fonts)
- scoreLabel.position = ccp(size.width - 100,size.height - 11);
- scoreLabel.color = ccc3(255, 255, 255);
- [scoreLayer addChild:scoreLabel];
- In the update function:
- When we check to see if a bullet has hit an enemy, in the part of code that says “YES HIT IT!” increase the score of numScore by however much (default of 100?)
- Then update the scoreLabel to the new number
- [scoreLabel setString:[NSString stringWithFormat:@"Score: %d",numScore]];
- release the label in dealloc.
Wednesday, January 12, 2011
Labels quicksheet
A few thoughts on making labels in your game from Matt...
Labels:
cocos2d,
ios,
quicksheet
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment