Jump to content

A Real Orientation Fix


jjwallace
 Share

Recommended Posts

I am trying to prevent my game from starting unless in landscape.

I looked at a couple methods but none of them seemed to work.

The problem is my game renders all objects and sizes them when it starts.

I want to wait for the correct orientation but that takes a second from the variable being set and the actual dimensions changing.

Is there a better way to do this?

update: function () {
        if (this.cache.isSoundDecoded('sfxPredator') && this.ready == false){
            this.ready = true;
            console.log('Preload Complete');
        }
        
        if(IApp.platform == 'tablet-l' || IApp.platform == 'phone-l' || IApp.platform == 'desktop'){
            BGame.onLandscape = true;
        }
        
        if(BGame.onLandscape == true && this.ready == true && BGame.onCanStart == true){
            console.log('Timer Start');
            BGame.onCanStart = false;
            this.time.events.add(Phaser.Timer.SECOND * 0.3, this.startRenderGame, this);
        }
        console.log('Game Started');
        this.state.start('Game');
    },

 

Link to comment
Share on other sites

Add an event listener on to the resize event and only run your initialisation code when the orientation matches whatever you want.

You'd probably want to show something during that time, and you'd also have to handle dimension changes during the lifetime of your app as well.

Oh, and you can't stop an orientation change from the web either.

Link to comment
Share on other sites

Ok so i have tried over 9 different methods here.

What happends is some how the width and height are original pulled in via portaite mode and then when landscape occurs it still falls back to the original centerX and centerY from orientation change?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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