【问题标题】:How to make sprite follow another sprite in Phaser 3如何使精灵跟随Phaser 3中的另一个精灵
【发布时间】:2018-06-18 19:58:17
【问题描述】:

在 Phaser 3 中如何让一个精灵跟随另一个精灵?

一个例子是slither.io中的一条蛇的部分

在 Phaser 2 中有 addChild (see here),在 Phaser 3 中只存在于容器中......有很多关于如何在 Phaser 2 中完成此操作的示例,但我无法弄清楚对于移相器 3...

或者,我可以创建自己的路径数组,如this example。但我很确定应该有一个更简单的解决方案。

【问题讨论】:

    标签: javascript phaser-framework


    【解决方案1】:

    听起来和我的问题类似,String of moving sprites following the player, most efficient way to do it?

    最后我只是使用了我在开头问题中提到的自己的建议:

    • 创建一个 Phaser.Group 的精灵
    • 使用类似 9999 个位置点 (x,y) 的数组
    • 跟踪头部位置的数组索引
    • 对于每一帧,将头部位置的值保存在数组中的索引位置
    • .update() 中相应地更新以下精灵的位置
    • index+1(如果大于 9999 则 index=0)

    这就是我在final game 中使用的;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-03
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多