我如何使敌人精灵跟随 Phaser 3 中的玩家精灵?
How do i make it so an enemy sprite follows the player sprite in Phaser 3?
我正在使用 Phaser 3
create(){
this.player = this.physics.add.sprite(100, 450, 'player');
this.enemy = this.physics.add.sprite(100, 450, 'enemy');
this.physics.moveToObject(this.enemy, this.player, 100);
}
到目前为止我有这个但是因为我使用的是 this.physics.add.sprite 而不是 this.physics.add.image 它不起作用。
我特别需要使用this.physics.add.sprite
已编辑:
enemyFollows () {
this.enemy.x = this.player.body.position.x;
this.enemy.y = this.player.body.position.y;
}
现在正在使用它,但需要让它慢慢移动到玩家的 body 位置。
我成功了。
enemyFollows () {
this.physics.moveToObject(this.enemy, this.player, 100);
}
我没有把它放在 create() 函数中,而是为它创建了一个新函数,并在 update() 中调用了 enemyFollows()
像这样
update() {
this.enemyFollows();
}
我正在使用 Phaser 3
create(){
this.player = this.physics.add.sprite(100, 450, 'player');
this.enemy = this.physics.add.sprite(100, 450, 'enemy');
this.physics.moveToObject(this.enemy, this.player, 100);
}
到目前为止我有这个但是因为我使用的是 this.physics.add.sprite 而不是 this.physics.add.image 它不起作用。
我特别需要使用this.physics.add.sprite
已编辑:
enemyFollows () {
this.enemy.x = this.player.body.position.x;
this.enemy.y = this.player.body.position.y;
}
现在正在使用它,但需要让它慢慢移动到玩家的 body 位置。
我成功了。
enemyFollows () {
this.physics.moveToObject(this.enemy, this.player, 100);
}
我没有把它放在 create() 函数中,而是为它创建了一个新函数,并在 update() 中调用了 enemyFollows()
像这样
update() {
this.enemyFollows();
}