hide and unhide SKSprite Node

时间:2015-06-15 14:26:50

标签: ios swift sprite-kit skspritenode

I am trying to hide a node when it's clicked and unhide it when a button is clicked. After unhiding the node, I can't click it again but I want it to be clickable again. Below is my code for hiding and unhiding using SKAction. Am I missing something?

when the ball Node is clicked it is hidden and added to an array clickedBall

ballNode.runAction(SKAction.hide())
clickedBall.append(ballNode)

when the button is clicked, it is shown via array clickedBall

clickedBall.last?.runAction(SKAction.unhide())

but I can't click the node again to hide it again..

please help.. thank you

2 个答案:

答案 0 :(得分:2)

单击节点时,您可以使用节点的“隐藏”属性,而不是运行操作:

ballNode.hidden = true

然后在希望节点重新出现时将值设置为false

答案 1 :(得分:1)

点击节点后,要隐藏它,您可以运行ballNode.removeFromParent()并将其添加回addChild(ballNode)