plicatibu Posted November 18, 2013 Share Posted November 18, 2013 Hi, all. I'm trying to handle the landscape / portrait mode in Phaser. At first I thought to use the game.stage.enableOrientationCheck(false, true, 'please-rotate');as show in this post but there is a problem: I could not find the enableOrientationCheck method. It's not part of stage anymore. I performed a grep into Phaser folder but the only reference to this function is in phaser/wip/TS Tests/mobile/sprite test 1.jsIn short,it seems that this method was wiped out of Phaser's source code. Is there any other reliable method I can force users to use device in either portrait or landscape mode or at least notify him to change device orientation? I'm using Phaser 1.1.2. Regards. Link to comment Share on other sites More sharing options...
rich Posted November 18, 2013 Share Posted November 18, 2013 http://gametest.mobi/phaser/docs/Phaser.StageScaleMode.html Link to comment Share on other sites More sharing options...
haden Posted November 18, 2013 Share Posted November 18, 2013 To force portrait orientation, use the following:game.stage.scale.forceOrientation(false, true, 'orientationImage');Please note that forcing the portrait orientation doesn't work correctly, I reported the issue here. To fix it, just add the following line at the beginning of StageScaleMode.forceOrientation():this.forcePortrait = forcePortrait; Link to comment Share on other sites More sharing options...
plicatibu Posted November 18, 2013 Author Share Posted November 18, 2013 @haden There is no functionforceOrientationon Phaser 1.1.2. @rich Shame on me. I should have looked more carefully on source code. Any way I put the codegame.stage.scaleMode.forceLandscape = true;in the create method of each and every state class but I saw no difference. The game continues to being re-sized in portrait mode. Could you please tell me what am I missing? Link to comment Share on other sites More sharing options...
haden Posted November 18, 2013 Share Posted November 18, 2013 forceOrientation is available in dev branch. Link to comment Share on other sites More sharing options...
plicatibu Posted November 21, 2013 Author Share Posted November 21, 2013 I updated the Phaser repository and then I switched to dev branch. The device I used to test is Motorola Razor i XT890 (Android 4.1.2). Then I used the following code in order to both force landscape and use full screen: this.game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL; this.game.stage.scale.minWidth = 480; this.game.stage.scale.minHeight = 260; this.game.stage.scale.maxWidth = 1024; this.game.stage.scale.maxHeight = 768; this.game.stage.scale.forceOrientation(true, false, 'r'); this.game.stage.scale.pageAlignHorizontally = true; this.game.stage.scale.pageAlignVertically = true; this.game.stage.scale.refresh(); this.game.stage.scale.maxIterations = 1; if (this.game.device.android && this.game.device.chrome == false) { this.game.stage.scaleMode = Phaser.StageScaleMode.EXACT_FIT; } this.game.input.maxPointers = 1; this.game.stage.disableVisibilityChange = true; this.game.stage.scale.pageAlignHorizontally = true; this.game.stage.scale.pageAlignVertically = true;The point is that using device's stock browser the behavior from application was very strange when I stared changing it's position from portrait to landscape and vice-verse. It doesn't happens when using Chrome browser in this Motorola device nor when using Safari on iPhone with iOS 6.1.3. As my English is not enough to explain it, I made a video (just 1 minute) to show what is happening. You can watch it here. Any help is very much appreciated. Edit: For a while the game can be played here in case anyone would like to test it and see the problem. Link to comment Share on other sites More sharing options...
plicatibu Posted November 23, 2013 Author Share Posted November 23, 2013 No one have a hint? Link to comment Share on other sites More sharing options...
rich Posted November 24, 2013 Share Posted November 24, 2013 The issue in the video is the pageAlignHorizontally/Vertically call not working. Disable those and do them via CSS yourself in the page. Something about that browser basically doesn't like the method we use to center a canvas. Link to comment Share on other sites More sharing options...
rich Posted November 24, 2013 Share Posted November 24, 2013 Just to add: in the latest dev branch there are 2 new events you can listen to:game.stage.scale.enterIncorrectOrientationgame.stage.scale.leaveIncorrectOrientationSo you can now listen to those to handle anything you need to do yourself. For example I had a requirement for a game where it should display a custom div over the top of the game when it the wrong orientation, so the above allowed me to do that. I could have done it with media queries too but I needed the game to pause while it was going on. Link to comment Share on other sites More sharing options...
Recommended Posts