Jump to content

Mouse position and button in a css scaled canvas


saltemishel
 Share

Recommended Posts

Hi All,

Is there a way for us to edit the game's pointer position according to the css scaled canvas?

I'm setting my phaser game canvas size to 200% screen size and scale my game down to 100% screen size using css.

I need to make the mouse position times 2 but not sure where I can make the changes that the phaser button will work.

Thanks.

 

 

 

 

Link to comment
Share on other sites

In case anyone needs it, I added the following code in each of the game state's resize function to update the mouse position. (I don't guarantee that it won't cause any unwanted problem though)

this.game.input.scale.x=this.game.width/window.innerWidth;
this.game.input.scale.y=this.game.height/window.innerHeight;

I'm using this scale mode, the game will resize game canvas to fit the game canvas always.

this.game.scale.scaleMode = Phaser.ScaleManager.RESIZE;

 

Link to comment
Share on other sites

It's not in the positional arguments but you can put it in a config object:

new Phaser.Game({
  antialias:             true,
  enableDebug:           true,
  height:                600,
  physicsConfig:         null,
  preserveDrawingBuffer: false,
  renderer:              Phaser.AUTO,
  resolution:            1,
  scaleMode:             Phaser.ScaleManager.NO_SCALE,
  seed:                  null,
  transparent:           false,
  width:                 800,
})

The object config isn't documented in 2.6.2 but you can read v2/src/core/Game.js#L446.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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