Here is a video I recorded with the problem visually https://www.youtube.com/watch?v=AC-4c4Qcyeo&feature=youtu.be
Currently facing a bug after when tocuhesMoved drag line path is completed I want the sprite to move to the position that the last place where the touch was. However you can touch anywhere on the UIView and it will move to that loaction without using the touchesMoved drag line. How do I only make the sprite move to the location only using the drag line mechanic to move the sprite?
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Moving");
if ([touches count]) {
UITouch* touch = [touches anyObject];
CGPoint position = [touch locationInNode:self];
path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, position.x, position.y);
CGPathAddLineToPoint(path, NULL, blade.position.x, blade.position.y);
//test points
//NSLog(@"%f", position.x);
//NSLog(@"%f", position.y);
self.line2.path = path;
}
}
TouchesEnded~~~~~
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.line2 removeFromParent];
if ([touches count]) {
[blade runAction:[SKAction moveTo:[[touches anyObject]locationInNode:self]duration:0.21]];
}
}
All the content inside touchesEnded it´s being executed every time a touch event exists thanks to this conditional
Noticed that inside touchesMoved you add a path to self.line2 so inside touchesEnded you can do the following
so if self.line2 is not equal to nil the content only will be executed if the line path exists
Good Luck!!