2014-02-13 43 views
2

在我的游戏中,我有一个运行无尽动画的SpriteNode;用户可以通过点击一个按钮来停止动画(简历);我需要知道动画的当前帧,所以我可以读取与其相关的适当值(来自XML文件)。当前动画帧 - SKSpriteNode

这里是我的代码:

SKAction *animateCircle = [SKAction 
         animateWithTextures:_animationTextures 
         timePerFrame: [self getAnimationSpeedAccordingToStage]]; 
    SKAction *repeatAnimation = [SKAction repeatActionForever:animateCircle]; 
    [shapeNode runAction:repeatAnimation withKey:@"shapeAnimation"]; 
    animationStartTime = [NSDate date]; 
    [self resumeShapeAnimation]; 
+0

可能重复http://stackoverflow.com/questions/21698512/sktexture-get-图像名称) – jackslash

回答

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; 
} 
[SKTexture取得图片名称(中