1

pause現在、resume、 、メソッドでアニメーションを制御するために cocos2d Director を使用していstopAnimationます。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);
}
4

1 に答える 1

3

Director のソースを調べましたが、参考になるものは何もありませんでした。あなたのコードは、書かれているように、アニメーションが一時停止した時間や他のシーンが再生されていた時間を考慮していないことに気付きました。

それが懸念される場合は、シーンまたはレイヤーでスケジュールした tick メソッドで経過時間を追跡できます。

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;
}
于 2009-08-03T04:35:44.900 に答える