Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zoubingwu opened this issue Jan 31, 2025 · 1 comment
Closed

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

zoubingwu opened this issue Jan 31, 2025 · 1 comment
Assignees

Comments

@zoubingwu
Copy link

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?

@zekeatchan
Copy link
Collaborator

Hi @zoubingwu. Thanks for submitting this issue. We have fixed this and pushed it to the master branch. It will be part of the next release. Do test it out and let us know if you encounter any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants