【发布时间】:2015-08-10 05:28:27
【问题描述】:
这是我在视觉上记录的问题视频 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;
}
}
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]];
}
}
【问题讨论】:
-
自从我看这个已经有一段时间了,但我相信你总是在触摸时得到 touchesBegan 和 touchesEnded,所以,在你的 touchesMoved 中简单地设置一个标志,在 touchesEnd 检查是否设置了标志, ie touchesMoved 实际上发生了,如果是这样移动你的“刀片”。由于您的路径似乎是一个属性,因此更好的选择是简单地检查 touchesEnded 中的 CGPath 以确定它是否为空。
-
我不太明白你说的标志是什么意思?但至于您所说的替代方案,您可以使用 (SKAction *)followPath:(CGPathRef)path 沿路径移动刀片并将其设置到新位置,然后执行 [self.line2 removeFromParent];
-
不,我的意思是正如 Julio 在下面添加的那样,测试 CGPath 是否包含点
标签: ios sprite skaction touchesmoved touchesended