phaser3中怎么在两个精灵间画线?

做了一个黄金矿工小游戏,希望在夹子发射和回收的时候展示被伸长的绳索。
现在用的是在create里添加graphics ,然后在update里画线,但是夹子回收的时候不知道该怎么处理

当然也不局限于使用graphics,如果您有更好的方法也可以提出来让我学习一下

create{
this.graphics = this.add.graphics();
this.graphics.lineStyle(2, 0xff00ff, 1.0);
}
update{
   this.graphics.moveTo(this.x, this.y);
    this.graphics.lineTo(this.player.x, this.player.y);
    this.graphics.strokePath();
}

img

该回答引用ChatGPT,如果有帮助到您请点个采纳
如果你希望在回收的时候不展示绳索,你可以在update中判断夹子的状态,仅在发射时画线。
例如:

kotlin




update{
   if (this.player.fired) {
      this.graphics.clear();
      this.graphics.lineStyle(2, 0xff00ff, 1.0);
      this.graphics.moveTo(this.x, this.y);
      this.graphics.lineTo(this.player.x, this.player.y);
      this.graphics.strokePath();
   } else {
      this.graphics.clear();
   }
}

在这里,我们使用graphics.clear()在回收时删除绘图,并仅在发射时创建绘图。