我正在使用Phaser 3框架开发我的第一个简单游戏. 我有《敌人》类(扩展演员类).在构造函数中,我创建了两个对象- Arc和文本.这两个物体应该附着在每个敌人身上并一起移动.
export class Enemy extends Actor {
constructor(
scene: Phaser.Scene, x: number, y: number
) {
super(scene, x, y, 'enemy')
this.x = x
this.y = x
const circle: GameObjects.Arc = this.scene.add.circle(x, y, 20, 0x333333)
const elSizeText: GameObjects.Text = this.scene.add.text(x, y, 'label, {font: 'bold 20px Arial'})
this.scene.physics.add.existing(this)
this.setVelocity(0, 500)
}
}
我通过创建容器并将所有3个对象包含在其中来实现了这一点.
this.container = this.scene.add.container(x, y)
this.container.add([circle, elSizeText, this])
问题是,现在如果我需要更改(或获取)敌人的位置,我应该更改This.Container.x,this.container.y.更改这个.x和这个.y似乎更自然.
还有更正确的方法来实现子对象到Actor类的附加吗?