Sign in to follow this  
moonbeaver

Mouse position

Recommended Posts

It's probably very simple, but I cannot figure this out.

How can I get mouse position?

I know I can use input.mouse.onMouseMove, but it provides browser event, so it is not affected by scaling/align.

 

game.input.position, game.input.mousePointer.position, game.input.x/y etc only update when I click somewhere, and never update on mouse move.

 

 

Share this post


Link to post
Share on other sites

I'm getting weird mouse coordinates in fullscreen EXACT_FIT mode in Chrome(and opera). Firefox works fine.

With game size 1280x720, in fullscreen it shows coordinates up to 3065x1382 in Chrome.

What am I doing wrong?

Example here http://codepen.io/anon/pen/FDJgB

 

window.onload = function(){  var game = new Phaser.Game(1280, 720, Phaser.AUTO, 'phaser', { preload: preload, create: create, update: update });  function preload() {  }  function create() {      game.stage.backgroundColor = 0x777777;      game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT;      //game.input.onDown.add(goFull);      var btn = game.add.button(1280, 0, 'img', goFull);      btn.anchor.setTo(1, 0);  }  function goFull(){      if(game.scale.isFullScreen){          game.scale.stopFullScreen();      } else {          game.scale.startFullScreen();      }  }  function update(){      var x = Math.round(game.input.activePointer.position.x);      var y = Math.round(game.input.activePointer.position.y);      game.debug.text("x:" + x + " y:" + y, 20, 30);  }}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.