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
Post a Comment