Is using game.width / height useful for device scaling?


Does using game.width / game.height rather than direct numbers such as (300,300) for something such as the positions help phaser scale if it was for instance wrapped and ported to other mobile devices.

For instance:

vs something like
game.add.image((game.width) + 10, (game.height) + 10)


Yes, use game.width and game.height.

For positioning the sprites, always think in terms of percentages, since different mobiles has different resolutions, it is better to use game.width and game.height for positioning the sprites.

for example, if you want to position a sprite in the middle of the screen(that is 50%=0.5) you have to use
game.add.image(game.width * 0.5,game.height * 0.5,‘id’);

By using this, whatever the screen resolution, it is always positioned in the middle of the screen.

1 Like

You could also scale the canvas using the ScaleManager.

1 Like

Thanks I’ll check this out


makes sense I’ll start to implement everything with game.height / width to save time thank you