这是我在视觉上记录的问题视频 https://www.youtube.com/watch?v=AC-4c4Qcyeo&feature=youtu.be
目前在 tocuhesMoved 拖动线路径完成后面临一个错误我希望精灵移动到最后一次触摸的位置。但是,您可以触摸 UIView 上的任何位置,它会移动到该位置,而无需使用 touchesMoved 拖动线。如何仅使用拖动线机制移动精灵使精灵移动到该位置?
- (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;
}
}
摸完~~~~~
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.line2 removeFromParent];
if ([touches count]) {
[blade runAction:[SKAction moveTo:[[touches anyObject]locationInNode:self]duration:0.21]];
}
}