swift - SpriteKit remembering which sprite was touched -


i have 'game' 3 sprites. if user clicks 'sprite1', , thereafter 'sprite2'. there way remember sprites pressed? 2 sprites if there more need empty 'memory' , start on last 1 'touched', didn't want work booleans.

all sprites have .name attribute can acces them there.

would if statement sufficient so

var spritearr:[string] = [] let location = (touch uitouch).locationinnode(self) touch in touches{    if spritearr.count < 2 {         spritearr.append(self.nodeatpoint(location))    }else{       spritearr.removeall       spritearr.append(self.nodeatpoint(location))    } } 

you can check sprites accessing .name of node , storing names in array this.

 var nodenames:[string] = []     override func touchesbegan(touches: set<nsobject>, withevent event: uievent) {                  let touch = touches.first as! uitouch         var touchednode:sknode = nodeatpoint(touch.locationinnode(self))          if(nodenames.count > 2){              nodenames = []         }         if(touchednode.name != nil){             if(!contains(nodenames, touchednode.name)){                  nodenames.append(touchednode.name)             }         }     } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -