Hi all,
I’m facing a problem relative to mouse pointer: the worldX and worldY coordinates don’t update if I don’t move the mouse and only move the camera. The game I’m developing is a top-down shooter and the camera follow the player that is always at the center of the screen. As said before, if I only move the camera but not the mouse, the worldX and worldY coordinates of the mouse pointer don’t change but if I only click a button of the mouse, the coordinates will update correctly. I suspect that the worldX and worldY coordinates are updated only on mouse event (move and click) and not during every frame. Am I correct? How can I get the mouse coordinates relative to world even if the mouse is not moving (or clicking) but only the camera?
The worldX and worldY were not updated on camera movement unless I moved my pointer. I was able to fix it by using the regular x/y and combining it with the camera x/y.
For anyone stumbling on this setPollAlways doesn’t work, here’s how to solve this -
getMouseCoords() {
// Takes a Camera and updates this Pointer's worldX and worldY values so they are the result of a translation through the given Camera.
this.scene.input.activePointer.updateWorldPoint(this.scene.cameras.main);
const pointer = this.scene.input.activePointer
return {
mouseX: pointer.worldX,
mouseY: pointer.worldY,
}
}