Game crashes unexpectedly on mobile

I have made a simple mobile game following this tutorial:


The only major difference is that I used Phaser.CANVAS instead of Phaser.AUTO as Phaser.AUTO doesn’t work on my phone for some reason, neither does Phaser.WEBGL.

The problem is that the game crashes within half a minute if you move and shoot continuously. It even crashes if you pause between shoots and then continue, although then the game works for a little bit longer.

I have tried decreasing bullet life time and increasing the duration between shots but this only helped to extend play time by a few seconds.

Also the joysticks freeze when both of them are used simultaneously in non-fullscreen mode as this triggers the fullscreen call and on entering fullscreen mode they freeze. You can safely enter full screen mode by double tapping the game or single tapping the background.

You can try out the game here:
https://princewael100.000webhostapp.com/Phaser3/Top%20Down%20Dual%20Stick/index.html

All game code is in the index.html itself.

Any help would be appreciated.

Crashes how?

Everything freezes. The joystick, player and bullets freeze. The game takes no more input. Even the scaling gets messed up when entering full screen and then rotating the device.

I don’t seem to be getting any errors.

Remove onclick="fullscreen()".

1 Like

Thanks, that solves the problem of the joysticks getting stuck on going full screen but the game still freezes within 15~20 seconds of continuous moving and shooting.
I’ll make a separate button to call full screen.

Commenting out the below two lines in the update loop seems to fix the problem.

if (this.shootJoyStick.force) {
        this.player.setAngle(this.shootJoyStick.angle);
        if (this.shootJoyStick.force >= this.shootJoyStick.radius && this.bulletCooldown <= 0) {
            //const bullet = this.bullets.get().setActive(true).setVisible(true);
            //bullet.fire(this.player);
            this.bulletCooldown = FIRE_RATE;
        }
    }

I think it’s because of the way shooting was implemented in the tutorial. They made a class Bullet and kept creating objects of that every time I shoot. Is there a fix to this? Or is there a better way to implement shooting?

Even if i destroy the bullets as soon as they leave the screen, the game still freezes within 15 seconds. This is how I am deleting them in the update loop.

this.bullets.children.each(function(b){
    if (!this.cameras.main.worldView.contains(b.x,b.y))
        b.destroy();
    },this);

The game runs anywhere between 15~30 seconds no mater what I try.

Would it be better if I used groups or pools? I really can’t continue without fixing this… Any help?

I’ll take another look. I haven’t been able to make it freeze.

I tried this on my laptop as well and it didn’t freeze on that. Maybe its just my old phone. But is there a better way to implement shooting? Or should I just use my laptop for testing?

Remove the try/catch.

Yes, try recycling the bullets.

Ok so I think I’ve fixed it by using groups. Thanks for the help. :grinning:

2 Likes