so i’m trying to switch levels but i have a problem.
when i load the assets like this :
// Load Tileset for Level{s} { 1 }
this.load.image ( 'lvl-1', 'assets/tilesets/platformPack_tilesheet.png' );
// Load Tileset for Level{s} { 2 }
this.load.image ( 'lvl-2', 'assets/tilesets/platformPack_tilesheet-2.png' );
// Load Level { 1 }
this.__load.tilemapTiledJSON ( 'lvl-1', 'assets/tilemaps/levels/lvl-1.json' );
// Load Level { 2 }
this.__load.tilemapTiledJSON ( 'lvl-2', 'assets/tilemaps/levels/lvl-2.json' );
& use this class :
class LevelManager {
constructor ( __scene ) {
this.__scene = __scene;
this.__level = 0;
this.__data = [
{ enemies : 10, },
{ enemies : 20, },
];
}
nextLevel ( __scene, __sceneKey ) {
this.__level++;
this.__scene = __scene;
this.__sceneKey = __sceneKey;
this.__scene.scene.start (
this.__sceneKey,
this.__data [ this.__level ]
);
if ( this.__level > 0 ) {
console.log ( 'SCENE' + ' :: ' + ' { ' + '\'' + ( this.__level + 1 ) + '\'' + ' } ' + 'WITH' + ' ' + 'SCENE KEY' + ' ' + '::' + ' { ' + '\'' + this.__sceneKey + '\'' + ' } ' + 'HAS BEEN STARTED!' );
console.log ( 'Data :: ' + '\r\n', this.__data [ this.__level ] );
}
}
}
& call it like this :
this.physics.add.overlap ( this.hero.sprite, this.__goal, function ( objectA, objectB )
{
if ( ! ( this.__hasOverlapped ) )
{
// this.sound.play ( 'detach-camera' );
// objectB.destroy ( );
this.__level.nextLevel ( this, 'lvl-2' );
this.__hasOverlapped = true;
}
}, null, this );
i get a blank scene even though i load my tileset & JSON files for lvl-1 & lvl-2…
i just want it to switch & load my new JSON level.