2009-07-27 6 views
1

저는 현재 pause, resumestopAnimation 방법으로 애니메이션을 제어하기 위해 cocos2d Director를 사용하고 있습니다. 디렉터를 사용하여 애니메이션이 재생 된 시간을 반환 할 수 있습니까?cocos2d Director가 시간을 반환 할 수 있습니까?

나는 현재이 방법을 사용하고 있습니다 :

-(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; 
} 
관련 문제