gpt4 book ai didi

ios - 使用 spritekit 和 UITouch 绘制直线创建多条线

转载 作者:行者123 更新时间:2023-11-28 20:05:05 24 4
gpt4 key购买 nike

应该很简单。

我正在尝试使用 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,它只在用户结束触摸后创建一条线。我希望用户在触摸时看到正在绘制的线条。

谢谢,道格

最佳答案

在您的 touchesMoved 中创建一个新路径。您正在修改相同的路径,只是向其中添加了越来越多的行。

关于ios - 使用 spritekit 和 UITouch 绘制直线创建多条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22353969/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com