Jump to content

How to make sprites follow my mouse on the canvas?


caymanbruce
 Share

Recommended Posts

Hi I am new to PIXI. I want to make my player sprite follow my mouse on the screen. How can I achieve that? I am using PIXI v4.

I have read the docs and I have found PIXI.interactions.InterationManager which takes a renderer as its parameter.

Something like this:
 

Quote

 

let manager = new PIXI.interactions.InteractionManager(renderer);

manager.on('mousemove', moveHanlder, false);

 

I have also found some codes that just listen to the `mousemove` event on the stage or on the sprite. Which one is the correct way to do in PIXI v4? I assume this is a very simple task because I can do it easily with pure javascript. But I just can't get it to work in PIXI. I wish I could find the solution on the books or the examples but all they mention are just dragging the sprites which is not what I want.

I also want to know if I should put the event listening out of my animation function or inside it because it seems it can get the mouse position outside of my animation function.

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