Skip to content

Camera.preRender should be public instead of protected? #7020

@zoubingwu

Description

@zoubingwu

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;
});

Error:
Image

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?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions