wipster Posted January 6, 2018 Share Posted January 6, 2018 Hi, I want my game to be always in 16:9 with letterboxing when neccessary. I'm using this code in the very first state: this.game.scale.aspectRatio = 1.77; this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; this.game.scale.align(true, true); When I now start the game after I resized the browser to a quadratic format the aspect ratio is different, close to 1. As if the aspect ratio I set is just being ignored and the canvas is scaled to the complete window. I'm not in the browser full screen mode. When I start in a format close to 16:9 everything works as expected, thus I guess only at startup something goes wrong. Am I missing something? Link to comment Share on other sites More sharing options...
samme Posted January 6, 2018 Share Posted January 6, 2018 scale.aspectRatio is actually read-only. In scale mode SHOW_ALL you just need to set game width/height in that ratio, eg, 1920 × 1080. wipster 1 Link to comment Share on other sites More sharing options...
wipster Posted January 17, 2018 Author Share Posted January 17, 2018 Thank you very much. That worked. When I now add sprites, they are scaled wrong though. Although I don't touch the scale of the sprite. this.game.load.image(Assets.SOME_KEY, 'assets/sprite.png'); this.someSprite = this.game.add.sprite(0, 0, Assets.SOME_KEY); this.someSprite.anchor.set(0.5, 0.5); The aspect ratio of the sprite is only correct when the canvas has the exact dimensions 1920x1080. Otherwise it is deformed either in width or in height, depending on the size of the screen (browser window). The canvas now always has an aspect ratio of 16:9 as wished. Is there more I have to take into consideration? Link to comment Share on other sites More sharing options...
wipster Posted January 17, 2018 Author Share Posted January 17, 2018 I figured out why my sprites where scaled wrong. I did this: this.game.width = 1920; this.game.height = 1080; Instead of this: this.game.scale.width = 1920; this.game.scale.height = 1080; Now everything works as expected. Link to comment Share on other sites More sharing options...
Recommended Posts