我是Phaser 3的菜鸟,正在尝试在关注者中添加一个群组(2个精灵)。当我在'add.follower'中使用精灵时,代码有效。
function create () {
var bola = this.add.group();
bola.create(0, 0, 'bola15');
bola.create(0, 0, 'bolasombra');
var line1 = new Phaser.Curves.Line([ 100, 100, 500, 100 ]);
var line2 = new Phaser.Curves.Line([ 500, 100, 500, 500 ]);
path1 = this.add.path();
path1.add(line1);
path1.add(line2);
var mover = this.add.follower(path1, 0, 0, bola);
mover.startFollow({
positionOnPath: true,
duration: 3000,
yoyo: false,
repeat: 0,
rotateToPath: false,
verticalAdjust: true
});
}
这就是我得到的:
对此有任何解决方案,还是通过其他方式实现类似目标?
编辑:
尝试过“容器”并得到相同的结果:
bola = this.add.container(0,0);
bola1 = this.add.sprite(0,0,'bola15');
bola2 = this.add.sprite(0,0,'bolasombra');
bola.add(bola1);
bola.add(bola2);
答案 0 :(得分:1)
在当前状态下,PathFollower
设置为仅可容纳一个GameObject。不幸的是,这意味着您必须将组项目一个接一个地添加到关注者。您可以设置一个循环来遍历您的组项目并创建路径跟随者,如下所示:
for (var i = 0; i < bola.children.entries.length; i++) {
var mover = this.add.follower(path1, 0, 0, bola.children.entries[i].texture.key);
mover.startFollow({
positionOnPath: true,
duration: 3000,
yoyo: false,
repeat: 0,
rotateToPath: false,
verticalAdjust: true
});
}
在Phaser 3实验室中检查this example,以查看另一个示例,该示例说明在组结构对您的游戏不重要的情况下如何使用具有相同路径的多个项目。