2009-07-27 28 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; 
}