The game I'm working on has a lot of scenes, so the scene list in the main file is getting pretty long. Here's how long it is now and be advised that with the plans I have it will get longer:
scene: [Title, Credits, BedRoomTutorial, ClosetTutorial, InventoryDay1, LivingRoomDay1, DiningRoomDay1, StairRoomDay1, TVRoomDay1, KitchenDay1, KitchenBackDay1, FrontDoorRoomDay1, FishTankRoomDay1, UpStairRoomDay1, HallWayDay1, WayEndDay1, BedRoomDay1, ClosetDay1, BathRoomDay1, LaundryRoomDay1, PlayRoomDay1, InventoryDay2, LivingRoomDay2, DiningRoomDay2, StairRoomDay2, TVRoomDay2, KitchenDay2, FrontDoorRoomDay2, FishTankRoomDay2, UpStairRoomDay2, HallWayDay2, WayEndDay2, BedRoomDay2, ClosetDay2, BathRoomDay2, LaundryRoomDay2, PlayRoomDay2]
I want to split this list into multiple lines so that reading and adding to it will be easier, but my previous attempt just broke the game. Anyone out there know how to split the list?
If it helps, I'm using Phaser 3 in VSCode employing arcade physics.
Well splitting an array in multiple lines should work well and easy, you just have to watchout for the commas.
scene: [
Title, Credits, BedRoomTutorial, ClosetTutorial,
InventoryDay1, LivingRoomDay1, DiningRoomDay1,
StairRoomDay1, TVRoomDay1, KitchenDay1,
KitchenBackDay1, FrontDoorRoomDay1,
FishTankRoomDay1, UpStairRoomDay1, HallWayDay1,
WayEndDay1, BedRoomDay1, ClosetDay1, BathRoomDay1,
LaundryRoomDay1, PlayRoomDay1, InventoryDay2,
LivingRoomDay2, DiningRoomDay2, StairRoomDay2,
TVRoomDay2, KitchenDay2, FrontDoorRoomDay2,
FishTankRoomDay2, UpStairRoomDay2, HallWayDay2,
WayEndDay2, BedRoomDay2, ClosetDay2, BathRoomDay2,
LaundryRoomDay2, PlayRoomDay2]
Or you could group scenes in seperat array's and merge them in the config
, with the concat
function (link to the documentation), something like this:
let tutorial = [BedRoomTutorial, ClosetTutorial];
let firstDay = [
InventoryDay1, LivingRoomDay1, DiningRoomDay1,
StairRoomDay1, TVRoomDay1, KitchenDay1,
KitchenBackDay1, FrontDoorRoomDay1,
FishTankRoomDay1, UpStairRoomDay1, HallWayDay1,
WayEndDay1, BedRoomDay1, ClosetDay1, BathRoomDay1,
LaundryRoomDay1, PlayRoomDay1];
// ...
let config = {
// ...
scene: [ Title, Credits, ].concat(tutorial, firstDay /*, ...*/)
}
Or you could simply add the scenes programatical, like this:
let config = {
//...
// basic / essential Scenes
scene: [ Title, Credits ]
};
// for example
const game = new Phaser.Game(config);
//... here the rest
game.scene.add('BedRoomTutorial', BedRoomTutorial, false);
game.scene.add('ClosetTutorial', ClosetTutorial, false);
// ...
With this method you can even lazy-load the scene later in game, if this would be needed.