Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

6 years ago by Rungo73

Hi all,

I'm targeting mobile and my game is in portrait. I want to tell players to rotate their device if theyre in landscape.

I've looked at this post where Dominic outlines what he did in X-Type. I just don't know where I should put this snippet. In my main update? in my index.html? somewhere else?

Can someone point me in the right direction?

http://impactjs.com/forums/help/keep-screen-in-landscape-mode-on-mobiles

6 years ago by jerev

You can place this in your main.js file, outside the game

ig.Game.extend({

});

var isPortrait = function() {
    return (!ig.ua.mobile || window.innerHeight > window.innerWidth);
};

var checkOrientation = function() {    
    if( isPortrait() ) {
        // all good
       // show game, unpause if needed, startrunloop
    }
    else {
        // display rotate message
       // Hide the game, pause the game, stoprunloop
    }
};

// Listen to resize and orientationchange events
window.addEventListener( 'orientationchange', checkOrientation, false );
window.addEventListener( 'resize', checkOrientation, false );

6 years ago by Rungo73

ha ha!

Thank you, works a treat.

Much appreciated.
Page 1 of 1
« first « previous next › last »