1 decade ago
by TigerJ
I'm working with an artist and we would like to change out several close looking tilesets as we play through a level in our game.
Is there away to access the tileset location property/value of a layer of a level from inside the main.js?
Or a can someone direct me to a sample or another thread that covers this?
Thank you for your time.
1 decade ago
by TigerJ
Maybe it's too vague of a question or there just is not an answer. Let me try to give an example:
Extend the class to contain a state value for the selected index BG
SelectedBgIndex:0,
Bind a key in the main.js like:
ig.input.bind(ig.KEY.N,'nextbgtiles');
also in the init() section create an array of locations
Var MyBgLocations = New Array();
MyBgLocations[0] = 'place/place/tileset1.png';
MyBgLocations[1] = 'place/place/tileset2.png';
MyBgLocations[2] = 'place/place/tileset3.png';
Then somewhere in the update() listen for the 'nextbgtiles' and change them out
if(ig.input.pressed('nextbgtiles'))
{
this.SelectedBgIndex++;
**some way to access a layer in a level' s tileset property here and set it to**
**MyBgLocations[this.SelectedBgIndex] **
if(this.SelectedBgIndex > MyBgLocations.length)
{
this.SelectedBgIndex=0;
}
}
So my current work around is to use LoadLeveldeffered and copy/paste the same level several times with different tilesets, then reload and reset the level with each set.
It would be much better if I could just access and refresh the tilesets whenever I wanted, and maybe even useful if a game changed environments as the player moved.
Like in Terraria if you go from one land type to another the background layers change.
1 decade ago
by Arantor
Well, a level is just a JS object. All that happens is that it instantiates an instance of ig.backgroundMap and that during its declaration is has the relevant tilesets loaded automatically as they're just declared as new instances of ig.Image.
All you need to do is call the level's setTileset method to update the tileset. It accepts either an ig.Image instance (i.e. your new images) or a path to load (in which case it instantiates ig.Image for that)
Page 1 of 1
« first
« previous
next ›
last »