Maybe I am missing something, so here is an example:
import Phaser from "phaser";
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: "#000",
parent: "game-container",
pixelArt: true,
scene: {
preload: preload,
create: create
},
physics: {
default: "arcade",
arcade: {
debug: true
}
}
};
const game = new Phaser.Game(config);
function preload() {
this.load.image('cursor', '../assets/images/crosshair.png');
this.load.image("player", "../assets/images/player.png");
}
function create() {
this.calculateDegreesFromRadian = (radian) => {
return radian * 180 / Math.PI;
}
this.calculateAngleInDegrees = (x, y, x2, y2) => {
return this.calculateDegreesFromRadian(Phaser.Math.Angle.Between(x, y, x2, y2));
}
this.player = this.physics.add.image(20, 20, "player", 0);
this.cursor = this.add.image(0, 0, 'cursor').setVisible(true);
this.input.on('pointermove', function (pointer) {
this.cursor.setPosition(pointer.x, pointer.y);
this.physics.velocityFromAngle(this.calculateAngleInDegrees(this.player.x, this.player.y, this.cursor.x, this.cursor.y), 20, this.player.body.velocity);
}, this);
//this.cameras.main.startFollow(this.player);
}
That code, as expected, produces the following: https://gyazo.com/9c0d29dfde124d9aba4ee662c70e695e
However, uncommenting the line letting the camera follow, produces the following: https://gyazo.com/2c4cf7c19e08177e7b6e17742f57ba6a
Am I missing something?