我正在构建一个游戏,当屏幕被触摸时(它在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