Ios 如何限制节点的数量?(Spritekit)

Ios 如何限制节点的数量?(Spritekit),ios,swift,sprite-kit,Ios,Swift,Sprite Kit,我有个小问题。请查看: override func touchesBegan(touches: Set, withEvent event: UIEvent) { for touch in (touches as! Set<UITouch>) { var Location:CGPoint = touch.locationInNode(self) var Node:SKNode = self.nodeAtPoint(Location) if(Location.x < se

我有个小问题。请查看:

 override func touchesBegan(touches: Set, withEvent event: UIEvent) {

for touch in (touches as! Set<UITouch>) {

var Location:CGPoint = touch.locationInNode(self)
var Node:SKNode = self.nodeAtPoint(Location)

 if(Location.x < self.size.width/2) {

        node2.addchild(sprite2)
        node1.removeFromParent()
}
if (Location.x > self.size.width/2) {

        node1.addchild(sprite1)

        node2.removeFromParent()
}

问题是,例如,当我在屏幕的同一侧点击10次,比如说,右侧显示10个spritenodes,由于physicsBody,我不能使用hidden。你们能帮帮我吗?

不清楚你们在问什么。当我点击左边时,英雄在左边,右边的英雄消失了,但是当我在左边点击2次时,它会创建两个英雄。请告诉我你理解我的英文不是很好。你需要用属性跟踪左/右精灵-如果不是零,那么采取适当的行动-要么将现有精灵移动到新位置,要么移除现有精灵并创建一个新的。你不会说第二次轻敲的期望行为应该是什么哦,好吧,谢谢你,伙计。