ios - 当前动画帧-SKSpriteNode

标签 ios objective-c animation sprite-kit skaction

在我的游戏中,我有一个运行无尽动画的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/

相关文章:

ios - 如何在单击时为单元格添加边框

ios - 以编程方式通过 USB 模拟 iPhone(真实设备,而非模拟器)位置

javascript - React Native listView 项目删除未正确删除项目

objective-c - 无法使用 iOS 从主线程方法发送事件并做出 native react

jquery - 转换 div 内的文本

python - PyQt5 中 QLabel 的 FontSize 动画

ios - 如何创建自定义类以向 UINavigationBar IOS 添加阴影

ios - 通过 Wifi 和/或蓝牙进行点对点数据传输

ios - UICollectionViewCell 奇怪的行为。单元格未正确更新图层

android - Android 上 AccelerateDecelerateInterpolator 的逆函数