2009-07-27 46 views
1

我目前正在使用cocos2d导演来控制我的动画,使用pause,resumestopAnimation方法。是否也可以使用导演返回动画播放的时间?cocos2d导演可以返回时间吗?

我目前使用这种方法:

-(void)stopAnimation:(id)sender { 
    //Timer initialized elsewhere: startTimer = [NSDate timeIntervalSinceReferenceDate]; 
    //Do other method stuff here 

    [[Director sharedDirector] stopAnimation]; 
    stopTimer = [NSDate timeIntervalSinceReferenceDate]; 
    elapsedTime = (stopTimer - startTimer); 
    NSLog(@"elapsedTime = %f", elapsedTime); 
} 

回答

3

我通过董事来源看,并没有看到任何会帮助你。我注意到,您的代码在编写时并未考虑您的动画暂停或其他场景播放的时间。

如果这是一个问题,您可以使用您在场景或图层中计划的打勾方法来跟踪已用时间。

MyLayer.h

@interface MyLayer : Layer { 
    ccTime totalTime; 
} 

@property (nonatomic, assign) ccTime totalTime; 

MyLayer.m

-(id)init 
{ 
    if((self = [super init])) 
    { 
     [self schedule:@selector(update:)]; 
    } 

    return self; 
} 

// deltaTime is the amount of running time that has passed 
// since the last time update was called 
// Will only be called when the director is not paused 
// and when it is part of the active scene 
-(void)update:(ccTime)deltaTime 
{ 
    totalTime += deltaTime; 
}