在我的游戏中,我有一个运行无尽动画的SpriteNode;用户可以通过按下按钮来停止动画(也可以恢复);我需要知道动画的当前帧,所以我可以读取与它相关的正确值(来自XML文件)。
这是我的代码:
SKAction *animateCircle = [SKAction
animateWithTextures:_animationTextures
timePerFrame: [self getAnimationSpeedAccordingToStage]];
SKAction *repeatAnimation = [SKAction repeatActionForever:animateCircle];
[shapeNode runAction:repeatAnimation withKey:@"shapeAnimation"];
animationStartTime = [NSDate date];
[self resumeShapeAnimation];
答案 0 :(得分:0)
你的动画纹理是否编号? 如果他们遵循textureNameNumber这样的模式,你可以使用我自己使用的这个解决方案:
-(int) getAnimationFrameFromTexture: (SKTexture*) texture imageName:(NSString*) name
{
NSString* textureString = [NSString stringWithFormat:@"%@", texture];
int i;
char numberStr[4]="000";
for( i=0 ;i<[textureString length]; i++)
{
char character = [textureString characterAtIndex:i];
if(character=='\'')
break; //found '
}
//Adds length
i+=[name length]+1;
for(int j=0;i<[textureString length];i++, j++)
{
char character = [textureString characterAtIndex:i];
numberStr[j]=character;
if(character=='\'')
break;
}
numberFromString=[NSString stringWithUTF8String:numberStr];
int number = [numberFromString intValue];
return number;
}