我创建了一个代码,通过触摸创建一条无限大小的线,我想知道如何限制大小,使线的开头和结尾可以是一个很小的距离到最大设定距离?
我使用的代码是:
pathToDraw = CGPathCreateMutable();
CGPathMoveToPoint(pathToDraw, NULL, positionInScene.x, positionInScene.y);
lineNode = [SKShapeNode node];
lineNode.path = pathToDraw;
lineNode.zPosition = 1000;
lineNode.strokeColor = [SKColor blueColor];
lineNode.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromPath:pathToDraw];
lineNode.physicsBody.categoryBitMask = ballCategory;
lineNode.physicsBody.contactTestBitMask = ballCategory;
[self addChild:lineNode];
在触摸开始方法和
CGPathAddLineToPoint(pathToDraw, NULL, location.x, location.y);
lineNode.path = pathToDraw;
lineNode.zPosition = 1000;
lineNode.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromPath:pathToDraw];
lineNode.physicsBody.categoryBitMask = boundaryCategory;
lineNode.physicsBody.contactTestBitMask = ballCategory;
lineNode.name = @"boundary";
lineNode.physicsBody.restitution=1;
在 touchMoved 方法中。
谢谢