如何使用SpriteKit和UITouch
创建直线?
我想要一种允许我添加起点和终点而不是路径的方法。就像橡皮筋一样。
答案 0 :(得分:3)
创建一个SKShapeNode
,当用户开始触摸移动时,这是一行,例如在touchesBegan:
。
SKShapeNode *line = [SKShapeNode node];
CGPoint startPoint = CGPointMake(..., ...)
CGPoint endPoint = CGPointMake(..., ...)
CGMutablePathRef pathToDraw = CGPathCreateMutable();
CGPathMoveToPoint(pathToDraw, NULL, startPoint.x, startPoint.y);
CGPathAddLineToPoint(pathToDraw, NULL, endPoint.x, endPoint.y);
line.path = pathToDraw;
line.strokeColor = [UIColor redColor]];
[self addChild:line];
修改其路径,以便在touchesMoved: