我想在我的雪碧節點上運行兩個動畫,具體取決於它的旋轉。如果該值爲負值,則運行其中一個動畫,如果該值爲正則運行另一個動畫。我設法做到了(有點),但是我有一個問題。如果Animation1正在運行,並且zRotation更改爲正值,則它們都會運行,因爲它們會一直重複。所以我這樣做:停止SKYECTION RepeatsForever - 雪碧套件
NSMutableArray *walkingTextures = [NSMutableArray arrayWithCapacity:14];
for (int i = 1; i < 15; i++) {
NSString *textureName =
[NSString stringWithFormat:@"character%d", i];
SKTexture *texture =
[SKTexture textureWithImageNamed:textureName];
[walkingTextures addObject:texture];
}
SKAction *spriteAnimation = [SKAction animateWithTextures:Textures timePerFrame:0.04];
repeatWalkAnimation = [SKAction repeatActionForever:spriteAnimation];
[sprite runAction:repeatWalkAnimation withKey:@"animation1"];
,然後當我希望它停止:
[self removeActionForKey:@"animation1"];
但它一直運行的操作,我怎麼能停止動作,然後呢?謝謝!
變化[自removeActionForKey:@ 「動畫1」];到[sprite removeActionForKey:@「animation1」];你將不得不維護一個指向精靈的全局變量。 – ZeMoon
@akashg您也可以命名精靈,然後在包含它的場景或節點中按名稱檢索它。 –
是的,傑森是對的。這將更容易維護。 – ZeMoon