Jump to content

How to determine/detect mouse position inside the renderer's view?


neonwarge04
 Share

Recommended Posts

Hi,

I am trying this code:
this.mSprite.on('mousemove' , (function(mouseData){var mousePos = mouseData.data.getLocalPosition(this.mStage);console.log("Mouse position : " + mousePos.x + " , " + mousePos.y);}).bind(this));

Unfortunately, the mouse is still being detect even though its outside of the game view area. I got this information on this site though its a bit outdated: http://www.goodboydigital.com/pixi-js-now-even-better-at-being-interactive/

 

How can I get mouse position relative on the view?

Thank you!

 

Link to comment
Share on other sites

Yes, that's interesting: I can confirm the same problem... all the other events work great but that one is not what you would expect. My observation is that, any mouse move, anywhere in the document calls back on every registered listener and by anywhere I include outside of the renderer view element , so, something strange there...

 

(EDIT: this is already registered as a bug: #1837 and #1884. #2071 is also relevant  :) )

 

But, you don't actually need that one, you need mouseover...

.on('mouseover', f)

 ...works great.  Perhaps that's what you want?

Link to comment
Share on other sites

Well, you have two choices that I can think of... 

  1. Cherry-pick the code and make your own interaction manager/renderer patch (until the rewrite is done)
  2. Keep the objects you want to interact with in the same container as everything in front of it.
    You can add other display objects to the container after the active objects, you just need to tag the active ones - or partition your container.children array - if you need to treat them separately in other parts of your code.  The limitation is in the renderer, not the container...
  3. EDIT: actually there is a third and better option (sorry, I'm learning as I go...), you can nest containers: you can use nested containers to group elements to partition your active layer.
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...