Jump to content

Adjust mouse cordinates for scaled stage?


kahootbird
 Share

Recommended Posts

The code would look something like that below. Basically I'm wondering if you scale the stage to the screen size, if there is a way to adjust the mouse X and Y coordinates to the new size -- the coordinates provided I've found that it's a bit offset the further toward bottom right you go from the pointermove event.

//Scale stage
var resolution_width = 1024
var resolution_height = 768

app.stage.scale.x = window.innerWidth / screen_width;
app.stage.scale.y = window.innerHeight / screen_height;

//Get mouse x and y on mouse move
app.stage.pointermove = moved;
function moved(e)
{
  console.log([e.data.global.x,e.data.global.y]
}
Link to comment
Share on other sites

  • 4 years later...
On 6/22/2019 at 11:10 AM, bubamara said:

you need to convert global coordinates to local coordinates : http://pixijs.download/dev/docs/PIXI.DisplayObject.html#toLocal

function moved(e)
{
    const global = e.data.global;

    const local = app.stage.toLocal(global);

    console.log(global.x, global.y, local.x, local.y)
}

 

Local coordinates just mean that you should divide global coordinates on scale value: e.data.global.x /= app.stage.scale.x
 

I think methods like toLocal are useless

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