[英]Create a straight line with SpriteKit
How can I create a straight line using SpriteKit and UITouch
? 如何使用SpriteKit和
UITouch
创建一条直线?
I wanted a method that allowed me to add the start point and the end point instead of a path. 我想要一个允许我添加起点和终点而不是路径的方法。 Just like a rubber band.
就像橡皮筋一样。
Create a SKShapeNode
that is a line when user begins the touch movement eg in touchesBegan:
. 当用户开始触摸运动(例如在
touchesBegan:
时, 创建一个SKShapeNode
作为行。
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];
Modify its path to change its length in touchesMoved:
修改其路径以更改
touchesMoved:
长度touchesMoved:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.