在 Phaser 3 中,你会如何让一个 Sprite 跟随另一个 Sprite ?
一个例子是 slither.io 中蛇的各个部分。
在 Phaser 2 中有一个 addChild
( see here ),它在 Phaser 3 中只存在于容器中......有很多关于如何在 Phaser 2 中实现这一点的示例,但我可以还没弄清楚 Phaser 3...
或者,我可以创建自己的 Path 数组,如 this example 。但我确信应该有一个更简单的解决方案。
最佳答案
听起来与我的问题类似,String of moving sprites following the player, most efficient way to do it?
最后我只是使用了我自己在开场问题中提到的建议:
- 创建一个 Phaser.Group Sprite
- 使用 9999 个位置点 (x,y) 的数组
- 跟踪头位置的数组索引
- 对于每一帧,保存数组中索引位置处的头部位置值
- 在
.update()
中相应更新以下 Sprite 的位置 - 索引+1(如果大于 9999,则索引=0)
这就是我在final game中使用的;)
关于javascript - 如何在 Phaser 3 中让 Sprite 跟随另一个 Sprite ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50891482/