Jump to content

Mouse events - Stage.getMousePosition()


ranom
 Share

Recommended Posts

Trying to accomplish a very simple thing - get the x and y values of the current mouse coordinate.

 

I found this method defined here http://www.goodboydigital.com/pixijs/docs/classes/Stage.html#method_getMousePosition

However javascript console says: Uncaught TypeError: stage.getMousePosition is not a function

Using the latest pixi build (as of 14.5.2015). Are the docs outdated or am i doing something wrong?

 

Link to comment
Share on other sites

God I'm so stupid, it is "renderer.plugins.interaction" not "renderer.interaction" so sorry about that!!

 

if you was to make a drag or drop function, which one are u mostly likely to use?

function onMove (e){     var mouseData = renderer.plugins.interaction.mouse.global;}

or

function onMove (e){      var mouseData = e.data.getLocalPosition(stageContainer);}
Link to comment
Share on other sites

For drag specifically I don't think it matters because all that matters is the delta between the moves, not what the point is when you check. Whichever feels best to you is probably good, getLocalPosition does involve some matrix calculations so *maybe* you want to avoid that if you don't *need* to know the exact local position?

Link to comment
Share on other sites

  • 7 years later...

Hello, this method no longer works in version 7 since replacing InteractionManager with EventSystem. I haven't been able to find a new method for determining mouse position, is there a new method documented somewhere? I see that `rootPointerEvent` exists on `app.renderer.events` but it is not exposed, is there a standard way of accessing that? In TypeScript I can use...

(app.renderer.events as any).rootPointerEvent.global

...for now which works, but I thought I'd ask if there's a better way to do this.

Link to comment
Share on other sites

On 12/30/2022 at 7:05 PM, topherlicious said:

Hello, this method no longer works in version 7 since replacing InteractionManager with EventSystem. I haven't been able to find a new method for determining mouse position, is there a new method documented somewhere? I see that `rootPointerEvent` exists on `app.renderer.events` but it is not exposed, is there a standard way of accessing that? In TypeScript I can use...

(app.renderer.events as any).rootPointerEvent.global

...for now which works, but I thought I'd ask if there's a better way to do this.

 

Hello, unfortunatelly this didn't work for me, i found the solution and then get coordinates from the event:

app.renderer.view.onmousemove = function (e:any) {
   console.log(e)
}

i am not sure if this is the way it should be handled but it works

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