我有一个自定义的LineBall类,如下所示:
@implementation LineBall
-(instancetype) init {
self = [super initWithImageNamed:LINE_BALL_IMAGE];
self.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:self.size.width/2];
self.physicsBody.categoryBitMask = BBPhysicsCategoryLineBall;
self.name = @"lineBall";
self.physicsBody.friction = 0.0f;
self.physicsBody.restitution = 1.0f;
self.physicsBody.linearDamping = 0.0f;
self.physicsBody.allowsRotation = NO;
self.physicsBody.dynamic = YES;
return self;
}
稍后我将它添加到GameScene并按预期工作。问题是现在我想在LineBall旅行的任何地方画线。我怎样才能做到这一点?
答案 0 :(得分:0)
这是在移动球后面画一条小道的一种方法。
在didSimulatePhysics
方法中:
CGPath
循环遍历数组元素来创建可变CGPathAddLineToPoint
以连接每个点SKShapeNode
shapeNodeWithPath
来创建球的路径
SKShapeNode
添加到场景