我正在尝试使用新的 SKSpritenode ,我设法创建了一个 Spritenode 在屏幕上移动它,尽管我希望 Spritenode 在它移动的地方留下痕迹(颜色)。
创建 Sprite 节点的代码和我尝试创建一个 shapenode 作为 spritenode 的子节点(这不起作用)。
-(void)movetherayoflight{
ray1=[[lightray1 alloc]initWithColor:[SKColor redColor] size:CGSizeMake(6,6)];
[ray1 setPosition:CGPointMake(50, 50)];
ray1.physicsBody=[SKPhysicsBody bodyWithRectangleOfSize:ray1.size];
ray1.physicsBody.restitution=1;
ray1.physicsBody.linearDamping=0;
ray1.physicsBody.friction=0;
ray1.physicsBody.allowsRotation=NO;
ray1.physicsBody.velocity=CGVectorMake(0.0f, 300.0f);
[self addChild:ray1];
SKShapeNode *raayyy=[[SKShapeNode alloc]init];
CGMutablePathRef rayPath = CGPathCreateMutable();
CGPoint fff=CGPointMake(ray1.position.x, ray1.position.y);
CGPoint startpoint=CGPointMake(50, 100);
//CGPathAddLines(rayPath, NULL, &fff, 2);
CGPathAddLines(rayPath, NULL, &startpoint, 5);
//CGPathAddLineToPoint(rayPath, NULL, ray1.position.x, ray1.position.y);
raayyy.path=rayPath;
raayyy.lineWidth = 1.0;
//raayyy.fillColor = [SKColor whiteColor];
raayyy.strokeColor = [SKColor greenColor];
raayyy.glowWidth = 0.5;
[ray1 addChild:raayyy];
}
如果您有更好的解决方案,请告诉我!