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

Reset nextCategory value on game destroy #4333

Closed
clesquir opened this issue Jan 30, 2019 · 1 comment
Closed

Reset nextCategory value on game destroy #4333

clesquir opened this issue Jan 30, 2019 · 1 comment

Comments

@clesquir
Copy link
Contributor

clesquir commented Jan 30, 2019

Version

  • Phaser Version: 3.15.1

Description

MatterJS nextCategory variable should be reset on game destroy. If it is not, the next game created will continue from the last number until it reaches the maximum. When it reaches maximum, it ignores the categories.

Example Test Code

Starting with the example at https://labs.phaser.io/edit.html?src=src/game%20config/game%20destroy.js I've modify it for that:

var config = {
    type: Phaser.AUTO,
    width: 400,
    height: 400,
    parent: 'phaser-example',
    scene: {
        preload: preload,
        create: create
    },
    physics: {
        default: 'matter',
        matter: {
            gravity: {
                x: 0,
                y: 0.6
            },
            setBounds: true,
             debug: true
        }
    }
};

var game = new Phaser.Game(config);

function preload ()
{
    this.load.image('stone', 'assets/particles/stone.png');
    this.load.image('floor', 'assets/sprites/128x128.png');
}

function create ()
{
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    this.matter.world.nextCategory();
    var category = this.matter.world.nextCategory();
    var stone = this.matter.add.image(100, 100, 'stone');
    var floor = this.matter.add.image(100, 300, 'floor');
    floor.setStatic(true);

    stone.setCollisionCategory(category);
    stone.setCollidesWith([category]);
    floor.setCollisionCategory(category);
    floor.setCollidesWith([category]);

    this.input.on('pointerdown', function () {

        this.sys.game.destroy(true);

        document.addEventListener('mousedown', function newGame () {

            game = new Phaser.Game(config);

            document.removeEventListener('mousedown', newGame);

        });

    }, this);
}

Additional Information

With the example, the stone falls on the ground. Click to destroy the game then click again to reset the game. The stone doesn't collide anymore.

The example above is how to reproduce it. My real game has 9 categories but it quickly goes over the 32 allowed categories because each "match" is a game and I am using a Single Page Application. Anyway, I still think the categories should be reset when destroying the game as it was doing in Phaser 2.

@photonstorm
Copy link
Collaborator

Thanks for opening this issue, and for submitting a PR to fix it. We have merged your PR into the master branch and attributed the work to you in the Change Log. If you need to tweak the code for whatever reason please submit a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants