我正在尝试将矩形图形对象的锚点设置到它的中心,这样我就可以在它的旋转之间进行补间。我能找到的唯一相关信息是使用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
}
}发布于 2020-02-23 21:55:53
我不知道您的Rectangle类是什么,但我假设它是Phaser.graphics的扩展
如果是这样,则需要在rectangle实例上调用setOrigin方法。
tempRect = new Rectangle(100, 100, 75, 50) # create
tempRect.setOrigin(tempRect.halfWidth, tempRect.halfHeight) // Set origin to middle point
test.strokeRectShape(tempRect);https://stackoverflow.com/questions/59783765
复制相似问题