You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
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.
Version
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:
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.
The text was updated successfully, but these errors were encountered: