-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Closed
Labels
Description
Description
The official example Mouse Wheel Zoom uses camera.preRender()
, but in TypeScript this method is marked as protected, causing type errors.
this.input.on('wheel', (pointer, gameObjects, deltaX, deltaY, deltaZ) => {
// Get the current world point under pointer.
const worldPoint = camera.getWorldPoint(pointer.x, pointer.y);
const newZoom = camera.zoom - camera.zoom * 0.001 * deltaY;
camera.zoom = Phaser.Math.Clamp(newZoom, 0.25, 2);
// Update camera matrix, so `getWorldPoint` returns zoom-adjusted coordinates.
camera.preRender();
const newWorldPoint = camera.getWorldPoint(pointer.x, pointer.y);
// Scroll the camera to keep the pointer under the same world point.
camera.scrollX -= newWorldPoint.x - worldPoint.x;
camera.scrollY -= newWorldPoint.y - worldPoint.y;
});
Expected Behavior
Maybe preRender
should be accessible as a public method, matching the behavior shown in examples? Or is there other way to fix it rather than @ts-ignore
?
samme