【问题标题】:Current Frame of Animation - SKSpriteNode当前动画帧 - SKSpriteNode
【发布时间】:2014-03-11 15:56:57
【问题描述】:

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

【问题讨论】:

标签: ios objective-c animation sprite-kit skaction


【解决方案1】:

你的动画纹理有编号吗? 如果他们遵循类似 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;
}

【讨论】:

    猜你喜欢
    • 2014-09-17
    • 1970-01-01
    • 2017-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    相关资源
    最近更新 更多