如何在 Spritekit 中的 removeFromParent 之后再次开始操作?

Posted

技术标签:

【中文标题】如何在 Spritekit 中的 removeFromParent 之后再次开始操作?【英文标题】:How to start action again after removeFromParent in Spritekit? 【发布时间】:2020-04-19 16:10:16 【问题描述】:

我正在运行此操作,我希望它在按下按钮时停止。那行得通,但是当我尝试再次运行该操作时,它不再起作用了。为什么会这样?

    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() 


【问题讨论】:

【参考方案1】:

想通了....

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

//call when to unpause action
activityIndicator.isPaused = false

【讨论】:

以上是关于如何在 Spritekit 中的 removeFromParent 之后再次开始操作?的主要内容,如果未能解决你的问题,请参考以下文章