pixi-viewport icon indicating copy to clipboard operation
pixi-viewport copied to clipboard

Zoom at mouse position

Open krnbatta opened this issue 4 years ago • 4 comments

Is there any way to get zooming focused at the mouse position. For now, it is difficult to understand the proper pattern to it. I want to zoom like how Google Maps work. Is this what originally happens or supposed to happen and I am doing something wrong? Or is there any particular flag that needs to be turned on or off?

krnbatta avatar Mar 01 '20 16:03 krnbatta

viewport.wheel() will let you zoom with the mouse wheel at the mouse location. See docs here: https://davidfig.github.io/pixi-viewport/jsdoc/Viewport.html#wheel

davidfig avatar Mar 02 '20 00:03 davidfig

It is actually broken if you don't render your canvas over whole body and do not supply an InteractionManager from PIXI app. Solution 1:

const viewport = new Viewport({
  divWheel: document.getElementById('my-canvas-wrapper'),
  interaction: app.renderer.plugins.interaction, // app is PIXI.Application
  ...
});

Solution 2: provide only divWheel and wait if https://github.com/davidfig/pixi-viewport/pull/226 gets merged :)

richard-ejem avatar Apr 29 '20 11:04 richard-ejem

Why do you prefer solution #2?

davidfig avatar Apr 30 '20 01:04 davidfig

I didn't mean I prefer it. I just noticed (and prepared a PR with fix) yesterday that the builtin handler is broken under these circumstances (we previously overlooked the insertion of PIXI interaction manager in our codebase). I actually used the solution 1 in my codebase too because I think it will lead to more consistent behavior with PIXI app itself, however the bug is still worth fixing.

richard-ejem avatar Apr 30 '20 07:04 richard-ejem