Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phaser on iOS (sometimes) stay paused #668

Open
SBCGames opened this issue May 14, 2020 · 2 comments
Open

Phaser on iOS (sometimes) stay paused #668

SBCGames opened this issue May 14, 2020 · 2 comments
Labels

Comments

@SBCGames
Copy link

This issue may be similar to #663.

Problem is, that when you click icon for browsing tabs (top right corner - see image below) and immediately click on tab with game, then game stays paused=true and looks like frozen. All buttons work, but game stays paused. It looks like resume is not called.
BrowseTabs

It does not happen always. Usually, it happens when you just opend browser and loaded game. I shot video of what happens and it is in .zip below (my iOS version is 12.4.6, I also tried Phaser engine version you attached to case #665, but without success):
paused.zip

As a fix I subscribed to onPause signal in Boot state:

game.onPause.add(this.onPauseHandler, this);

onPauseHandler() looks like this:

    onPauseHandler: function() {
        if (game.device.iOS) {
            this.addMyCanvasListener();
        }
    },

and finally addMyCanvasListener() like this:

    addMyCanvasListener: function() {
        var can = document.getElementById('game-container');
        can.addEventListener('touchstart', function _listener() {
            game.paused = false;
            can.removeEventListener('touchstart', _listener, false);
        }, false);
    },

With this setup I can unpause game if it is still paused after selecting tab.

@samme
Copy link
Collaborator

samme commented May 14, 2020

You could try logging; see notes in https://photonstorm.github.io/phaser-ce/Phaser.Stage.html#visibilityChange.

@SBCGames
Copy link
Author

Yes, I did so... but that is the problem - only blur event is fired when you click that browser button. It pauses game, but there is no other event when you return. So game stays paused. As I wrote, it does not happen always, but I can simulate it now every time if I fresh open browser and load game.

While testing, I created simple on-screen console, so I can see console output directly on screen. Here is small part of it:
OnScreenConsole
and I noticed, that focus event is fired, when I touch some of its elements. So: I run the game, pres tab button in browser, return to game and game is paused (I can see only blur event in console). I can wait any time, game does not unpause. I can touch game canvas and nothing happens. But if I touch any button from my on-screen console then it logs focus event and game unpauses.

Seeing this, I came up with that workaround above - if other HTML elements work and send their events, I can attach touchstart event directly to canvas to unpause game (it works, but focus or any other event is not sent).

This issue and other (#667) I sent recently comes from fact, that I am fixing for sponsor larger number of games made by various developers that failed in testing. Sponsor sent me tester logs to see what was wrong. I am doing lot of testing (including engine debugging) before posting as issue here. I think, that this one is something ugly with browser, not Phaser, but I had to solve it somehow :-) - fortunately, that workaround works for now.

@samme samme added the bug label May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants