Jump to content

Mouse position


moonbeaver
 Share

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.

 

 

Link to comment
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);  }}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...