我正在使用 UITouch 绘制一个 ShapeNode,如下所示:
线条正确绘制。但是,我的问题是将物理体添加到 shapenode(我希望 SKSpriteNode 碰撞和反弹)。但就好像物理体从未附加到 shapenode 上一样。我使用 YMCPhysicsDebugger 来查看物理体相对于 shapenode 的位置,但它没有检测到任何东西。
有没有人遇到过这个?您如何成功地将物理体添加到动态形状节点?
`-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
pathToDraw = CGPathCreateMutable();
CGPathMoveToPoint(pathToDraw, NULL, positionInScene.x, positionInScene.y);
selectorLine = [SKShapeNode node];
selectorLine.path = pathToDraw;
selectorLine.strokeColor = [SKColor greenColor];
selectorLine.lineWidth = 10;
selectorLine.physicsBody=[SKPhysicsBody bodyWithPolygonFromPath:pathToDraw];
selectorLine.physicsBody.restitution=1.0f;
selectorLine.physicsBody.dynamic=YES;
selectorLine.physicsBody.usesPreciseCollisionDetection=YES;
selectorLine.physicsBody.mass=0.2;
selectorLine.zPosition=1.5;
[self addChild:selectorLine];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
CGPathAddLineToPoint(pathToDraw, NULL, positionInScene.x, positionInScene.y);
selectorLine.path = pathToDraw;
}
谢谢,道格