Jump to content

How to get mouse position in every frame in V3?


lunarovich
 Share

Recommended Posts

Hello, in pixi.js V2 I was using getMousePosition() of the Stage class to read a mouse position in every frame. In V3, the Stage class is gone, together with its getMousePosition().

 

Now, in V3, I know that InteractionManager has a property .mouse, which is of the type InteractionData. However, I do not know how to grab a reference to the automatically created instance of the InteractionManager.

 

On the other hand, if I try to instantiate the InteractionManager myself, I can read a global mouse position. However, all the mouse events are reported twice, which is unacceptable...

 

Lastly, there is no callback possibility for .mousemove on regular DisplayObjects/Containers, so I cannot read the interactionData in every tick.

Link to comment
Share on other sites

code snippets is helpful to allow other people to help you..

 

I have used a mousemove event listener on a sprite like this..

mySprite('mousemove', mouseMoveCallback);function mouseMoveCallback(mouseData) {  console.log("X = "+mouseData.data.originalEvent.movementX);  console.log("Y = "+mouseData.data.originalEvent.movementY);}

This is correct syntax for V3 and will log your mouse position in the console. 

 

You still create a 'stage' of sorts with the code..

//you can therefore use the listener on the stage variablevar stage = new PIXI.Container(0xFFFFFF);

I have yet to discover the necessity of the Interaction Manager class as my app is interactive without instantiating it.

 

Hope this helps!

Link to comment
Share on other sites

I think you meant:

 

mySprite.on('mousemove', ...); 
And you should pass color to the renderer (backgroundColor option), not the container. Passing color to a container does nothing.

I have yet to discover the necessity of the Interaction Manager class as my app is interactive without instantiating it.

That is because we create one for you, and it is exposed at "renderer.plugins.interaction".

Link to comment
Share on other sites

  • 8 months later...
On 5/7/2015 at 10:14 PM, jcdiprose said:

 


mySprite('mousemove', mouseMoveCallback);function mouseMoveCallback(mouseData) {  console.log("X = "+mouseData.data.originalEvent.movementX);  console.log("Y = "+mouseData.data.originalEvent.movementY);}

 

the movementX & movementY params isn't works for me on chrome(v 47.0.2526.111).

i use pageX pageY instead of.

the codes such like:

mouseData.data.originalEvent.pageX

mouseData.data.originalEvent.pageY

hope this can help someone who need it.

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