So... you did this in your game&
039;s #init()
:
this.loadLevel(this.levels[this.level]);
...
this.cloudMap = this.backgroundMaps[0];
this.backgroundMaps.erase( this.cloudMap );
Your game&
039;s #init()
is executed
once at game start. It loads the level, then erases the first map from the
.backgroundMaps
array. That's all fine and dandy.
When the second level is loaded however, the old
.backgroundMaps
array is thrown away and re-created with all maps from the second level. This of course means that the first map from this second level is still in the
.backgroundMaps
array. It&
039;s not erased from the #.backgroundMaps
array like for your first level, because you only do this in your
init()
.
Hence, in my example I overwrote the
.loadLevel()
method, so that
each time a level is loaded, the first map from the
.backgroundMaps
is erased.
loadLevel: function( data ) {
this.parent( data );
this.cloudMap = this.backgroundMaps[0];
this.backgroundMaps.erase( this.cloudMap );
},
Some related remarks: if some example code posted here doesn't work, please first check if you followed it closely. If you did and it still doesn't work, it's quite likely that there's a error in the code. Nobody has the source to your game and is able to
try the code they post, but it still may gives viable pointers on how to implement something. Try to understand what the code does and why it may fail in your case.
Get familiar with Firebug or Chrome's Dev Tools or whatever else you use. These tools allow you to inspect your game at runtime. You can place break points and manipulate the game.
In this case for instance, your level has 4 background layers. If one layer is erased (the cloud layer) your
ig.game.backgroundMaps.length
should report
3
. This is true for the first level, but not for the second - why not? Why didn&
039;t the cloud layer didn't get erased? Place a breakpoint at the #.erase()
method and observe if it is called when you think it should be.
Also, if you have a problem, try to make it as easy as possible for everyone else to understand and respond to it. That means:
1) Tell us what you want to achieve
2) Tell us what you did try already and how it failed
3) Maybe post some code and tell us exactly where you're stuck
There's also an excellent article called
How To Ask Questions The Smart Way - it's quite long and somewhat over the top, but it's well worth skimming through.