Pause an SKAction in Spritekit with Swift

前端 未结 3 1703
既然无缘
既然无缘 2021-01-02 07:10

I have the following code to move an SKSpriteNode.

let moveDown = SKAction.moveBy(CGVectorMake(0, -120), duration: 1)
let moveUp = SKAction.move         


        
3条回答
  •  甜味超标
    2021-01-02 07:39

    You should run an action with key:

     square.runAction(SKAction.repeatActionForever(moveSequence), withKey:"moving")
    

    Then, use action's speed property to pause it:

    if let action = square.actionForKey("moving") {
    
            action.speed = 0       
    }
    

    or to unpause it:

    action.speed = 1
    

提交回复
热议问题