Slyvan25 Posted February 22, 2018 Share Posted February 22, 2018 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 Quote Link to comment Share on other sites More sharing options...
mattstyles Posted February 28, 2018 Share Posted February 28, 2018 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. 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.