2

在我的游戏中,我有一个 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];
4

1 回答 1

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;
}
于 2015-03-23T22:13:38.743 回答