moonbeaver Posted July 25, 2014 Share Posted July 25, 2014 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 More sharing options...
lewster32 Posted July 25, 2014 Share Posted July 25, 2014 You need to poll the game.input.activePointer.position property (usually in your update function) which will always contain the position of the mouse - see this fiddle: http://jsfiddle.net/lewster32/95Cyq/ cwright 1 Link to comment Share on other sites More sharing options...
moonbeaver Posted July 25, 2014 Author Share Posted July 25, 2014 Thanks, it works. Apparently, my mistake was that I actually redefined game.input.mouse.onMouseMove, now I use game.input.addMoveCallback lewster32 1 Link to comment Share on other sites More sharing options...
moonbeaver Posted July 25, 2014 Author Share Posted July 25, 2014 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 More sharing options...
lewster32 Posted July 25, 2014 Share Posted July 25, 2014 It's working fine in here in Chrome 36.0.1985.125 on Windows 7, so not sure... Link to comment Share on other sites More sharing options...
Recommended Posts