在Spritekit中,如何在removeFromParent之后再次启动动作?

问题描述 投票:1回答:1

我正在运行这个动作,我想让它在按下按钮时停止。这样做是可行的,但是当我试图再次运行这个动作时,它就不再工作了。为什么会出现这种情况?

    func buyProduct(product: SKProduct){
    print("Sending the Payment Request to Apple")
    let payment = SKPayment(product: product)
    SKPaymentQueue.default().add(payment)



    let rotateRight = SKAction.rotate(byAngle: 30, duration: 5.0)
    let rotateLeft = SKAction.rotate(byAngle: -30, duration: 5.0)
    let sequenceRotation = SKAction.sequence([rotateRight, rotateLeft])
    let repeatSequence = SKAction.repeatForever(sequenceRotation)


    activityIndicator.position = CGPoint(x: self.size.width / 2.0, y: self.size.height / 2.0)
    activityIndicator.zPosition = 120
    activityIndicator.run(repeatSequence)
    addChild(activityIndicator)

}

 //calling this in a button when I want to stop rotating. 
 func stopRotating() {

 activityIndicator.removeFromParent() 

}
swift skspritenode
1个回答
0
投票

我想明白了....

//call when to pause action
activityIndicator.isPaused = true

//call when to unpause action
activityIndicator.isPaused = false
© www.soinside.com 2019 - 2024. All rights reserved.