开发者

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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜