A.Kman Posted June 20, 2017 Share Posted June 20, 2017 Hey all! I'm trying to update my game every time the screen is resized or turned from portrait to landscape and visa versa. What I'm doing right now is using window.onresize = this.resize(); but resize() is being called every frame. Does anyone either know why this isn't working or how to do this better? Thank you!!! Link to comment Share on other sites More sharing options...
samme Posted June 20, 2017 Share Posted June 20, 2017 See https://photonstorm.github.io/phaser-ce/Phaser.ScaleManager.html. Use scaleMode RESIZE. Link to comment Share on other sites More sharing options...
Dylan Cristy Posted June 26, 2017 Share Posted June 26, 2017 @samme is right, you have to use scaleMode.RESIZE. I found that in a web browser, sometimes the resize callback didn't always get fired on the very last bit of resizing/moving, so here is how I implemented resizing/realigning: In my Boot state, set the scale mode for the game: this.game.scale.scaleMode = Phaser.ScaleManager.RESIZE; Then, in my other game states (levels), I set flags for whether things need to be realigned (or not), and in the resize callback, only set the flag, and I do all the actual resizing in update(), like this: create() { this.game.scale.setResizeCallback(this.alignLevel, this); this.resized = false; this.resizedDoubleCheck = false; } alignLevel() { this.resized = true; } update() { if (this.resized || this.resizedDoubleCheck) { // do all the realigning of things here } // set the flags to false, but ensure one final // realignment even if the setResizeCallback didn't fire if (this.resized) { this.resized = false; this.resizedDoubleCheck = true; } else if (this.resizedDoubleCheck) { this.resizedDoubleCheck = false; } } Link to comment Share on other sites More sharing options...
Recommended Posts