Hello,
I’m trying to add a new feature on a HTML5 game and I can’t find a way to do it.
I try to change the game orientation during the game itself. When the player rotate the screen (Portrait > Landscape or Landscape > Portrait) I want to change the dimensions of the canvas to fit the new orientation.
I am able to do this with a refresh, but I can’t find a way to do it “live” so far.
Here is a snippet from my game config :
if(isPortrait()){ config = { type : Phaser.CANVAS, parent:'game', scale:{ mode : Phaser.Scale.FIT, autoCenter: Phaser.Scale.CENTER_BOTH, width: 735, height: 1310, }, backgroundColor: "#000000", physics: { default: "arcade", arcade: { gravity: { x:0, y:0 } } }, scene: [ Boot, SceneIntro, ScenePresentation, SceneMainMenu, SceneMain, SceneScore, SceneSocialMedia ] }; } else{ config = { type : Phaser.CANVAS, scale:{ parent:'game', mode : Phaser.Scale.FIT, autoCenter: Phaser.Scale.CENTER_BOTH, width: 1310, height: 735, }, backgroundColor: "#000000", physics: { default: "arcade", arcade: { gravity: { x:0, y:0 } } }, scene: [ Boot, SceneIntro, ScenePresentation, SceneMainMenu, SceneMain, SceneScore, SceneSocialMedia ] }; }
the isPortrait function (pretty dumb and I suspect there is a builtin function)
function isPortrait(){ if(window.innerWidth < window.innerHeight){ return true; } else{return false;} }
Is there a way to do it “live” ?
I already tried to resize the canvas via vanilla JS (changing the DOM properties of it) without any success.