pixi-viewport
pixi-viewport copied to clipboard
Getting x,y position in viewport from mouse pointer location
Is there a way I can use the mouse pointer x,y location to get the x,y location of the viewport that the mouse is hovering over? That is, something that is always correct regardless of pan or zoom of the viewport.
Think maybe I found it. viewport.toWorld(x, y) and viewport.toScreen(x, y) seem like they should do what I'm after
I've been trying to feed browser mouse event screenX/screenY and clientX/clientY into viewport.toWorld(x, y) but I'm not quite getting the value I expect. Does anyone know which I should be using?
If your canvas is not full screen, then ensure you include the viewport.option.interaction = renderer.plugins.interaction to compensate for the difference between canvas and corner of page. Otherwise it should work.
@davidfig it seems like the interaction manager was deprecated by pixi.js on version 7.0.0. Is there any other workaround for this? I'm having the exact issue you've described, where because my canvas does not begin at the top left corner of page, it's not correctly compensating when zooming for example. I did try just plugging in their EventSystem instead, with no luck, zoom stops working entirely!
Appreciate any help you can provide!