我正在构建一个游戏,当屏幕被触摸时,标签应该弹到屏幕(只有一次)(它在touchesBegan内)。
我发现这扩展有助于“弹跳”,但我不知道当我在3秒(持续时间?!!)之前按restartButton (这个按钮工作得很好)时,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()
是实际的游戏场景(如位置、比例尺、物理等)。
发布于 2016-04-04 07:46:31
在Sprite中工作时,请注意SKScene是SKNode的成员。调用removeAllActions
只删除应用于屏幕的操作,调用removeAllChildren
只删除子操作,而不是操作。
你需要给你所有的孩子打电话给removeAllActions
,让他们停止移动。
如果您想要为场景设置一个方法来删除所有孩子的操作,请在SKNode
上设置一个扩展。
extension SKNode
{
func removeAllActionsIncludingChildren()
{
self.removeAllActions()
self.children.map { $0.removeAllActionsIncludingChildren()}
}
}
https://stackoverflow.com/questions/36389977
复制