【发布时间】:2022-09-27 12:17:27
【问题描述】:
我正在 Phaser 中重新制作 8ball pool 以获得乐趣,并且正在设置 cue/cueball 的瞄准。我目前在鼠标移动时让提示围绕主球的中心点旋转:
create() {
// Spawn in pool table
this.setupTable();
// Initialize cueball
this.cueball = new Ball(this, 847, 400, \'ballsAndCue\', \'14ball.png\', true);
// Initialize cue
this.cue = new Cue(this, 800, 400, \'ballsAndCue\', \'cue.png\', this.cueball);
// Set cue rotation to follow cursor on cursor movement
this.input.on(\'pointermove\', function (pointer) {
this.angle = Phaser.Math.Angle.BetweenPoints(this.cue, pointer);
this.cue.rotation = this.angle;
}, this);
}
但是我希望球杆围绕整个母球旋转。我尝试将this.cue 提供给Phaser.Actions.RotateAround()/Phaser.Actions.RotateAroundDistance(),但无法让它们工作。看看 Phaser 2,他们有一个你可以设置的支点,但除了setOrigin(),我没有看到任何类似的东西,我已经习惯了让球杆围绕尖端旋转。
提示类:
import Phaser from \'phaser\';
export default class Cue extends Phaser.GameObjects.Sprite {
constructor(scene, x, y, spritesheet, sprite, cueball) {
super(scene, x, y, spritesheet, sprite);
scene.add.existing(this);
this.setX(cueball.x);
this.setY(cueball.y);
this.setScale(0.7, 1);
this.setOrigin(0, 0.5);
}
}
我怎样才能让球杆围绕主球的圆周旋转?
标签: javascript rotation game-development phaser-framework