如何实时更改SKActions

时间:2015-12-11 10:52:35

标签: ios swift sprite-kit

所以我有一个猜谜游戏。它有动画的主场景和4个级别。默认情况下,只有第一级解锁,并且它具有不断进行的动画。当玩家完成第一级时,我将整数传递给主场景以改变第二级的纹理并在其上运行动画。所有动画都是在后台完成的,因此我无法在第二级添加动作。我需要停止仅代表一个未锁定级别的背景动画,并立即运行具有两个打开级别的动画。一般来说,传递一个整数是有效的,纹理在他们需要时更换,但无论我尝试什么 - 我都无法在项目运行时用第二个动画取代第一个动画。我在这里读到我应该"杀死"第一个动画,然后才添加新动画。嗯,它没有奏效。我觉得我误解了行动,但我不知道怎么做。这是我的代码:

    let action1 = SKAction.repeatActionForever(SKAction.animateWithTextures(firstArray, timePerFrame: 0.1))
    let action2 = SKAction.repeatActionForever(SKAction.animateWithTextures(secondArray, timePerFrame: 0.2))
    let action3 = SKAction.repeatActionForever(SKAction.animateWithTextures(thirdArray, timePerFrame: 0.2))
    let action4 = SKAction.repeatActionForever(SKAction.animateWithTextures(fourthArray, timePerFrame: 0.2))

    if !hp1open {
    background.runAction(action1, withKey: "act1")
    }else if hp1open == true {
        background.removeActionForKey("act1")
        background.runAction(action2, withKey: "act2")
    }else if hp1open == true && rp1open == true {
        background.removeActionForKey("act2")
        background.runAction(action3, withKey: "act3")
    }else if hp1open == true && rp1open == true && fp1open == true {
        background.removeActionForKey("act3")
        background.runAction(action4, withKey: "act4")
    }

hp1open,rp1open等等 - 我用它来改变等级纹理到"解锁"。我已经尝试过使用节点本身以及我在场景之间传递而不是它们的整数。它不起作用,所以我认为我的问题是SKActions。请帮助!

0 个答案:

没有答案