Reputation: 103
I have some sprites coming from the bottom of the screen in a random order. I want to swipe the sprite in the direction of the swipe. I got the algorithm for swiping. Also, I get an NSLog message whenever any sprite has been touched in the screen. The NSLog gives correct responses to any and every object touched. But how do I know which sprite has been swiped to write the code for applying impulse to that particular sprite?
I am trying the following code:
SKNode *sprite = [self nodeAtPoint:location];
[ball.physicsBody applyImpulse:CGVectorMake(dx, dy) atPoint:location];
[self addChild:sprite];
Also,
userInteractionEnabled = YES for all the sprites
And all the sprites are performing an action (Just in case this is the reason why I cannot swipe them while they are already running an action, in this case what else should I use to move the sprites?)
Sorry if this is too dumb, I am a noob
Thanks in advance!
Upvotes: 0
Views: 51
Reputation: 637
You will need to use the name of the sprite with the name property:
node.name = @"nodeName";
for(SKNode *node in [self nodesAtPoint:location])
{
if([node.name isEqualToString:@"nodeName"])
{
// your custom code here
}
}
I hope this is what you were looking for, if not i am always here to help.
Upvotes: 3