make a timer count down and score displayed on the screen in Cocos2D
How can I apply a timer count down in Cocos2D and the score counter that both will be display开发者_开发知识库 on the screen?
I am still new to this
Please help me out
Thanks a lot
You should have a look into the Timer class. Here is a link to the Timer class overview - cocos2d for iPhone 0.8.2. You won't need to implement one directly (but indirectly), but its good to know how it works.
For displaying the actual counter in the screen using cocos2d, have a look at LabelAtlas. Here is a link to LabelAtlas class overview - cocos2d for iPhone 0.8.2
/* basically you create a LabelAtlas subclass that
has a method for updating itself with the current time
or score. I will call it ScoreLabel in this example */
ScoreLabel * bonusScore = [[ScoreLabel alloc] initWithString:@"0"
charMapFile:@"charMap.png"
itemWidth:10
itemHeight:10
startCharMap:'0'];
// then schedule a method to be called that updates the current score
// schedule: paramter of type SEL. It should pass the method to be scheduled
// interval is in seconds, it determines how often the method is called.
[bonusScore schedule:@selector(updateScore) interval:0.5];
/* the implementation of the updateScore method could be */
-(void)updateScore {
[self setString: [[World sharedWorld] timeLeft]]];
}
Have a look at the cocos2d examples for AtlasSprites (and for LabelAtlas) to see how to implement the image you need to support the class.
精彩评论