I want to create a random tiled map for my game, this is what I have so far:
switch(MathUtils.random(2)){
case 0:
tileX+=16;
loadedTiles ++;
//game.batch.draw(tile1, tileX, tileY);
System.out.print("tile1");
currentTile = tile1;
break;
case 1:
tileX+=16;
loadedTiles ++;
//game.batch.draw(tile2, tileX, tileY);
System.out.print("tile2");
currentTile = tile2;
break;
case 2:
tileX+=16;
loadedTiles ++;
//game.batch.draw(tile3, tileX, tileY);
System.out.print("tile3");
currentTile = tile3;
break;
}
game.batch.begin();
game.batch.draw(currentTile, tileX, tileY);
game.batch.end();
}
Instead of rendering them each individually i would like to add them to an array and render them all together, so if i have an array such as this:
ArrayList<Texture> tiles;
Then add something to all of he case options like:
tiles.add(tile1);
Problem:
How do i render the array and get the relevent co-ordinates for them to be rendered, does this get added to the array?
tileX+=16; loadedTiles++;
is always executed, so you could put that outside the switch statement to avoid duplicated code. – SimonTexture
when what you basically want to do is have one global texture, select the requiredTextureRegion
for the Tiles, create aSprite
for each tile you want to display while asSprite
is not a serializable class or at least it should be transient as it has Texture on its object graph ( github.com/libgdx/libgdx/wiki/Saved-game-serialization ), so you're supposed to have a class that shares the resource only for rendering the object. If I understand your problem properly, anyways. – EpicPandaForce