我正在尝试将矩形图形对象的锚点设置为它的中心,以便我可以补间它的旋转。我能找到的唯一相关信息是使用 dispalyOriginX 和 dispalyOriginY 属性,但这似乎没有任何作用。这是我的代码:
export default class GameUi extends Phaser.GameObjects.Group {
constructor(scene) {
super(scene);
let test = new Graphics(scene);
test.setName('test');
test.lineStyle(4, 0xffffff, 1);
test.strokeRectShape(new Rectangle(100, 100, 75, 50));
// The following doesn't work :(
// test.displayOriginX = 0.5;
// test.displayOriginY = 0.5;
scene.tweens.add({
targets: test,
angle: 20,
duration: 2000,
ease: "Power2",
yoyo: true,
loop: -1
});
this.addMultiple([test], true);
}
}
矩形应该围绕其中心旋转,但如下图所示,它似乎围绕游戏区域的左上角旋转。我尝试了值在 0.5 到 500 之间的 displayOrigin 属性,结果都相同。
我在想这可能是因为我将矩形添加到导致问题的组中,但我尝试不将它添加到具有相同效果的组中。这是我的代码不属于组时的样子:
export default class GameUi {
constructor(scene) {
let test = scene.add.graphics();
// the rest stays the same as in my first code example
}
}