Jump to content

Game turns black after tab switch.


Recommended Posts

Hey guys, I have a weird issue. 

After my game has stayed idle for a while and I am currently using another tab, the game turns black. And the weird thing is that if I switch back to another tab quickly and move back to the game - it fixes itself o_0.

Also on android the game does not want to turn back from black. The buttons in the game are clickable, I believe this is render related, but I have no idea what could it be.


What could be the reason? 
 

Link to post
Share on other sites
<script>
   ////Game init
    var atlasScaleFactor = 1;

    window.onload = function() {

        /**Determine Screen Size and Device Type*/
        this.w = window.screen.width;
        this.h = window.screen.height;

        if(this.w < this.h)
        {
            this.w = window.screen.height;
            this.h = window.screen.width;
        }
        else if(this.w > this.h)
        {
            this.w = window.screen.width;
            this.h = window.screen.height;
        }

        if(this.w * RatioUtil.getDPR() > 1200)
        {
            atlasScaleFactor = 1;
        }

        if(this.w * RatioUtil.getDPR() < 1200)
        {
            atlasScaleFactor = 0.5;
        }

        if(this.w * RatioUtil.getDPR() < 1000)
        {
            atlasScaleFactor = 0.25;
        }

        /**Determine proper Renderer and Game Dimensions*/
        var deviceRender;
        var forcedTimeOut;

        if(getMobileOperatingSystem() == 'iOS')
        {
            forcedTimeOut = false;
            deviceRender = Phaser.WEBGL;
            this.w = this.w * RatioUtil.getDPR();
            this.h = this.h * RatioUtil.getDPR();
        }
        else if(getMobileOperatingSystem() == 'Android')
        {
            forcedTimeOut = false;
            deviceRender = Phaser.CANVAS;
            this.w = this.w * RatioUtil.getDPR();
            this.h = this.h * RatioUtil.getDPR();
        }
        else if(getMobileOperatingSystem() == 'unknown')
        {
            forcedTimeOut = false;
            deviceRender = Phaser.CANVAS;
            this.w = window.screen.width;
            this.h = window.screen.availHeight;
        }

        console.log(this.w + "X" + this.h + " " + getMobileOperatingSystem());
        /**Create Phaser Configuration Object*/
        var config = {
            "width": this.w,
            "height": this.h,
            "renderer": deviceRender,
            "parent": 'game',
            "transparent": forcedTimeOut,
            "forceSetTimeOut": false
        };

        /**Initialize new Phaser instance*/
        var game = new Phaser.Game(config);
        game.forceSingleUpdate = true;
        /**
         * Determine the mobile operating system.
         * This function either returns 'iOS', 'Android' or 'unknown'
         *
         * @returns {String}
         */
        function getMobileOperatingSystem() {
            var userAgent = navigator.userAgent || navigator.vendor || window.opera;

            if( userAgent.match( /iPad/i ) || userAgent.match( /iPhone/i ) || userAgent.match( /iPod/i ) )
            {
                return 'iOS';

            }
            else if( userAgent.match( /Android/i ) )
            {

                return 'Android';
            }
            else
            {
                return 'unknown';
            }
        }

        /**Add Game States*/
        game.state.add('Boot', Game.Boot);
        game.state.add('Preloader', Game.Preloader);
        game.state.add('MainMenu', Game.MainMenu);
        game.state.add('GameMachine', Game.GameMachine);

        /**Start Booting*/
        game.state.start('Boot');
    };

This is in my index.html
And this is the create function in boot
 

        this.game.renderer.renderSession.roundPixels = false;
        this.game.input.maxPointers = 1;
        this.game.stage.disableVisibilityChange = true;
        this.game.scale.setUserScale(1,1);
        this.game.plugins.add(Fabrique.Plugins.InputField);

I had the disableVisibilityChange = true. 
Do you see any other problems?

Link to post
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...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...