Jump to content

Mousehover events in canvas!?


Slyvan25
 Share

Recommended Posts

Hello everyone!,

I'm stuck with my 2d game.. i'm trying to give certain sprites a on mousehover event(i dont really know if this is possible lel but i  am really new with canvas so pleas help me out).

does anyone know a better way or the sollution for this???

regards,

slyvan25

Link to comment
Share on other sites

The DOM exposes mouse over events but they work at the DOM element level, so, you'd get them for the canvas element but what you actually want is for elements inside the canvas element, however, these internal element aren't DOM elements so you need to map the mouse coordinates into your own in-canvas coordinate system, possibly working out whatever z-indexing method you're using, to work out which canvas element (sprite) the mouse is currently over.

Most canvas rendering libs (such as Pixi) handle this mapping for you and expose elements on a per-canvas element (i.e a sprite) level which is akin to the DOM mouseover events, but for non-DOM elements.

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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