dimanche 19 avril 2015

How to control the number of nodes when i tap? Spritekit

Hi guys im new making iOS games (spriteKit) and im making a game where im using two spritenodes (left, right) but is the same hero. The game is about evading obstacles that are comming from two sides so when i tap one of the sides the opposite node should disappear and appears on the right place. The problem is when i tap more than once on the same side of the screen it appears more nodes and i dont want that. Here is the code:



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()
}

Aucun commentaire:

Enregistrer un commentaire