我正在構建一個遊戲,當屏幕被觸摸時(它在touchesBegan中),標籤應該彈回到屏幕(僅一次)。Sprite Kit中的彈跳標籤
我發現this擴展與「反彈」幫助,但我不知道會發生什麼,當我觸摸restartButton(此按鈕是工作得很好)以前3秒(長的時間?!?!), myLabel只會出現沒有任何動畫。我做錯了什麼?
Ps:restartButton有一個removeAllActions()。所以即使這個動畫在循環中(我猜不是),它會被停止,不是嗎?
//myLabel
myLabel.position = CGPoint(x: self.frame.width/2, y: self.frame.height)
myLabel.text = "0"
self.addChild(myLabel)
//bounces into screen (using Sprite-Kit Spring)
self. myLabel.runAction(SKAction.moveTo(CGPoint(x: self.frame.width/2, y: self.frame.height/1.125), duration: 3.0, delay: 0.5, usingSpringWithDamping: 0.2, initialSpringVelocity: 0.0))
當restartButton被觸摸時,它調用此函數:
func restartScene(){
self.removeAllChildren()
self.removeAllActions()
gameStarted = false
createScene()
}
PS:createScene()
是實際遊戲場景(的東西,如位置,規模,物理學等)。
removeAllActions僅刪除場景中的動作,而不是其子節點的動作。 RemoveAllChildren不會刪除操作。致電刪除標籤上的所有操作。 – Knight0fDragon
謝謝!有效!! =) – Luiz