C_S

Scale manager: resize to visible

Recommended Posts

C_S    0

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

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


  • Recently Browsing   0 members

    No registered users viewing this page.