【问题标题】:How to start action again after removeFromParent in Spritekit?如何在 Spritekit 中的 removeFromParent 之后再次开始操作?
【发布时间】: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() 

}

【问题讨论】:

    标签: swift skspritenode


    【解决方案1】:

    想通了....

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-12
      • 1970-01-01
      • 1970-01-01
      • 2012-01-19
      • 2019-11-07
      • 2013-02-23
      • 1970-01-01
      相关资源
      最近更新 更多