Jump to content

Device orientation redraw canvas


GoodOldSnoopy
 Share

Recommended Posts

I've seen this topic and question asked a few times before but I've been unable to find anything that I'm looking for (or I've just not looked good enough).

 

So when I draw my game

 
var w           = window.innerWidth;
var h           = window.innerHeight;

var game = new Phaser.Game(w, h, Phaser.AUTO, document.getElementById('game'));
 

I have a function below that displays an image when the user rotates the device which looks like this

 
window.addEventListener('orientationchange', doOnOrientationChange);

function doOnOrientationChange() {
    if(/Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
        switch(window.orientation) {
            case -90:
            case 90:
                w = window.innerWidth;
                h = window.innerHeight;
                portraitDiv.className += " portrait_hide";
                game.state.start('boot');
                break;
            default:
                w = window.innerWidth;
                h = window.innerHeight;
                portraitDiv.className += " portrait_display";
                break;
        }
    } else {
        game.state.start('boot');
    }
}

The thing is, I display and hide the image based on the device orientation fine, but I need to pause the game and update the width and height variables and redraw the canvas without refreshing the whole game.

 

Does anyone know how I might do this?

 

Thaks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...