我目前正在使用cocos2d Director通过pause
,resume
和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);
}
答案 0 :(得分:3)
我查看了Director的来源,但没有看到任何可以帮助你的东西。我注意到你编写的代码没有考虑动画暂停或其他场景播放的时间。
如果这是一个问题,您可以在场景或图层中安排的刻度方法中跟踪已用时间。
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;
}