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

#1

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:

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

#2

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
#3

You could also scale the canvas using the ScaleManager.

1 Like
#4

Thanks I’ll check this out

#5

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