I want to run a SKAction if my SKSpriteNode Sorcerer is touched. With my current code, whenever I touch, my SpriteNode 'stone' will move to the Sorcerer. I could call the location of the touch with specific x and y coord., but since the 'Sorcerer' is moving, I can't do that. How can I fix this?
- (void)Sorcerer {
Sorcerer = [SKSpriteNode spriteNodeWithImageNamed:@"Sorcerer.png"];
Sorcerer.size = CGSizeMake(85, 85);
Sorcerer.zPosition = 2;
Sorcerer.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(50, 50)];
Sorcerer.physicsBody.dynamic = NO;
Sorcerer.physicsBody.allowsRotation = NO;
Sorcerer.physicsBody.usesPreciseCollisionDetection = YES;
Sorcerer.physicsBody.restitution = 0;
Sorcerer.position = CGPointMake(self.frame.size.width * 1.25, self.frame.size.height / 2.2);
SKAction * actionMove = [SKAction moveToX:self.frame.size.width / 2 duration:10];
[Sorcerer runAction:[SKAction repeatActionForever:[SKAction sequence:@[actionMove]]]];
[self addChild:Sorcerer];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:Sorcerer];
Stone = [SKSpriteNode spriteNodeWithImageNamed:@"Stone.png"];
Stone.position = Human.position;
Stone.zPosition = 1;
Stone.scale = 0.6;
SKAction *action = [SKAction moveTo:Sorcerer.position duration:0.5];
SKAction *remove = [SKAction removeFromParent];
[Stone runAction:[SKAction sequence:@[action,remove]]];
[self addChild:Stone];
}