Cocos2d game Timer
I want to add a timer to my game. I have a GameManager singleton.
-(void) startTimerWithDuration:(float) duration
{
[self schedule:@selector(time开发者_JAVA百科Up) interval: duration];
}
-(void) timerUp
{
[self unschedule:_cmd];
[self lose];
}
-(void) lose
{
[[CCDirector sharedDirector] pushScene: [GameOverScene node]];
}
Then in my GameScene init, I have
[self addChild:[GameManager node]];
Then I have:
[[GameManager sharedManager] startTimerWithDuration:60.0f];
I get this error in console:
*** Assertion failure in -[CCTimer initWithTarget:selector:interval:
And this is the cctimer
#if COCOS2D_DEBUG
NSMethodSignature *sig = [t methodSignatureForSelector:s];
NSAssert(sig !=0 , @"Signature not found for selector - does it have the following form? -(void) name: (ccTime) dt");
#endif
I don't know why. Are there some common approach to counting the time? Since it is a common usage I guess.
Your
-(void) timerUp
{
[self unschedule:_cmd];
[self lose];
}
should be
-(void) timerUp:(ccTime)delta
{
[self unschedule:_cmd];
[self lose];
}
精彩评论