Good evening,
I’m making a game similar to the Chrome dinosaur game with multiple levels using different assets. Because I’m learning JS and Phaser on-the-fly with this project, the levels/scenes are all standalone. Changing the update function for every single level for a small change makes me crazy, so now I want to change it.
At first it looked like this: Preload → Title → Level 1/2/3…
My goal is: Preload → Title → Base Level → Loading assets/objects for Level 1 to n
I’m trying to figure everything out via tutorials and examples, but the numerous ways to do something are very confusing.
// Level 1:
this.textures.remove("layer1");
this.load.image("layer1", "level1/layer1.png");
this.layer1.this.add.tileSprite(0, 0, 960, 640, "layer1");
// Level 2:
this.textures.remove("layer1");
this.load.image("layer1", "level2/layer1.png");
this.layer1.this.add.tileSprite(0, 0, 960, 640, "layer1");
That worked without problems. But if I now run Title → Base Level → Level 1, layer1 will either use the assets from “Title” or, if I use this.textures.remove(“layer1”), it will only show the black/green grid. Making layer1 global didn’t work, using a function “Level 1” within “Base Level” didn’t work either. (Because the images have to be loaded in the preload function? I was able to use another method to load the images so that they would show up in cache, but it still wouldn’t be possible to add them go the game objects.)
Unfortunately I can’t change the texture on its own either, because other parameters change as well.
I’m really confused, so I would be very thankful, if you could tell me how I should approach this.