Jump to content

detect mouse even when hovering


itachi
 Share

Recommended Posts

Hello!so i want to detect when the mouse is over a sprite and continue executing some code until the mouse exits the area...with mouseover it executes the code once and thats sadly not enough for me...with mousemove i cant execute code when the mouse just hovers in sprite...any help would be appreciated ty

 

 

 

Link to comment
Share on other sites

Use a boolean value to indicate when mouse is on & check in render. Or add the render listener when pointerover happens & remove it with pointerout. Or if you dont prefer events you can do a hittest and see if current pointer position overlaps with your object.

For example

let isOn = false;
sprite.addEventListener("pointerover", ()=>isOn=true);
sprite.addEventListener("pointerout", ()=>isOn=false);

const onRender = ()=>{
  if(isOn){
    // do something.
  }
}

 

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