Jump to content

Detecting when scene pointer is over specific canvas2D child


Recommended Posts

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.


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.

Link to comment
Share on other sites

Looks like I can achieve what I want using the actualPosition/actualSize of the Prim2DBase.


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?


Anyway, guess I have a way forward.

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...