Jump to content

Scale manager: resize to visible


C_S
 Share

Recommended Posts

Hi

I want to know how I can resize a Phaser game to exactly the current size of the browser window. I modified the My First Phaser Game example as follows:

var game = new Phaser.Game(window.innerWidth * window.devicePixelRatio, window.innerHeight * window.devicePixelRatio, Phaser.AUTO, '', { preload: preload, create: create, update: update });

function preload() {

    game.scale.scaleMode = Phaser.ScaleManager.RESIZE;
   
and did relative positioning of the ground element:

    var ground = platforms.create(0, game.world.height - 64, 'ground');
The result is that I am unable to see the ground because it is too low

I also positioned a platform this way and it does not move up when I make the browser window smaller, although this should cause game.world.height to decrease.

I figured that I have to make the game keep track of the window size changes, so I put the following into the update function:

    game.world.width = window.innerWidth * window.devicePixelRatio;
    game.world.height = window.innerHeight * window.devicePixelRatio;


That did not change the situation.

 

My goal is for all game elements to be positioned in relation to the bottom boundary of the game. Also, I need the game to adjust its height to the extent of what is seen in the browser window.

Code attached. Any ideas?

index.html

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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