unintellisense Posted October 29, 2016 Share Posted October 29, 2016 Hello, I am trying to work out how I can use scene.pointerX/scene.pointerY to determine when my cursor is over a specific canvas2D rectangle. I made a small playground to show what I am trying to do. http://www.babylonjs-playground.com/#1885OI#6 The intention is for it to only toggle the box's color when clicking over it, but you can see that doesn't happen. What I really want this for is so that I can use a full size ScreenSpaceCanvas2D and be able to return early from my scene pointer actions if it is over specific rectangles. I tried scaling down the screen canvas to the size of the actual menu, but then I ran into the issue of scaling the menu properly in a way that behaves the same way the margin values do for a rectangle. Anyway, a bit new to Babylon.js, any help is appreciated. Quote Link to comment Share on other sites More sharing options...
unintellisense Posted October 30, 2016 Author Share Posted October 30, 2016 Looks like I can achieve what I want using the actualPosition/actualSize of the Prim2DBase. http://www.babylonjs-playground.com/#1885OI#8 Not sure if I misunderstand what the .boundingInfo BoundingInfo2D property is supposed to be used for. If I inspect the center for the boundingInfo it is nowhere near the actualPosition? http://www.babylonjs-playground.com/#1885OI#9 Anyway, guess I have a way forward. Quote Link to comment Share on other sites More sharing options...
Nabroski Posted October 30, 2016 Share Posted October 30, 2016 You can use the Canvas2d PointerElement and make a Callback to a PointerX/scene.PointerY http://www.babylonjs-playground.com/#1885OI#10 Quote Link to comment Share on other sites More sharing options...
unintellisense Posted October 30, 2016 Author Share Posted October 30, 2016 Thanks, but the idea was to be able to tell in my scene callbacks if I'm over the rect (so that I exit early instead of interacting with the scene beneath my canvas). The actual interaction with the element in this case was just for debugging/demo purposes. Quote Link to comment Share on other sites More sharing options...
Nabroski Posted October 30, 2016 Share Posted October 30, 2016 Hello So what is the benefit? canvas.observer.notify(scene.observer) yes i'm over the rect ? : scene.obsever.callback(function(mouse.event)) I would do it this way. http://www.babylonjs-playground.com/#1885OI#12 But i think some other user, will catch up soon. Best Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.