我希望在Sprite Kit中绘制沿着touchesmoved收集的点的线条。
最有效的方法是什么?我尝试了几次,我的线条要么在y轴上错误,要么占用了很多处理能力,使fps降至每秒10帧。
有什么想法吗?
最有效的方法是什么?我尝试了几次,我的线条要么在y轴上错误,要么占用了很多处理能力,使fps降至每秒10帧。
有什么想法吗?
@interface MyScene()
{
CGMutablePathRef pathToDraw;
SKShapeNode *lineNode;
}
@end
@implementation
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch* touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
pathToDraw = CGPathCreateMutable();
CGPathMoveToPoint(pathToDraw, NULL, positionInScene.x, positionInScene.y);
lineNode = [SKShapeNode node];
lineNode.path = pathToDraw;
lineNode.strokeColor = [SKColor redColor];
[self addChild:lineNode];
}
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch* touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
CGPathAddLineToPoint(pathToDraw, NULL, positionInScene.x, positionInScene.y);
lineNode.path = pathToDraw;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// delete the following line if you want the line to remain on screen.
[lineNode removeFromParent];
CGPathRelease(pathToDraw);
}
@end