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

Getting x,y position in viewport from mouse pointer location

Open digitalsadhu opened this issue 4 years ago • 4 comments

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.

digitalsadhu avatar Mar 11 '21 19:03 digitalsadhu

Think maybe I found it. viewport.toWorld(x, y) and viewport.toScreen(x, y) seem like they should do what I'm after

digitalsadhu avatar Mar 11 '21 20:03 digitalsadhu

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?

digitalsadhu avatar Mar 11 '21 22:03 digitalsadhu

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 avatar Mar 12 '21 01:03 davidfig

@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!

rodrigo-nexudus avatar Feb 15 '23 17:02 rodrigo-nexudus