在我的游戏中,我有一个运行无尽动画的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];
最佳答案
您的动画纹理编号了吗?
如果他们遵循类似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;
}
关于ios - 当前动画帧-SKSpriteNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21742943/