【发布时间】:2014-03-12 14:03:05
【问题描述】:
应该很简单。
我正在尝试使用 UITouch 和 Spritekit 绘制一条直线。但是,当调用 touchesmoved 时,它会创建多行而不是单行。使用的代码如下:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
positionInScene1 = [touch locationInNode:self];
pathToDraw = CGPathCreateMutable();
selectorLine = [SKShapeNode node];
selectorLine.strokeColor = [SKColor greenColor];
selectorLine.lineWidth = 5;
[self addChild:selectorLine];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
pathToDraw2 = CGPathCreateMutable();
UITouch* touch = [touches anyObject];
positionInScene2 = [touch locationInNode:self];
CGPathMoveToPoint(pathToDraw2, NULL, positionInScene1.x, positionInScene1.y);
CGPathAddLineToPoint(pathToDraw2, NULL, positionInScene2.x, positionInScene2.y);
CGPathCloseSubpath(pathToDraw);
selectorLine.path = pathToDraw;
}
如果我移动
CGPathAddLineToPoint(pathToDraw, NULL, positionInScene2.x, positionInScene2.y);
到 touchesEnd,它只在用户结束触摸后创建一行。我希望用户在触摸时看到正在绘制的线。
谢谢, 道格
【问题讨论】:
-
多行从哪里到哪里?从起点到当前触摸位置的附加线,或前一个和当前触摸位置之间的附加线?
标签: ios objective-c sprite-kit uitouch