First of all, I am new to Java and LibGDX..
What I am trying to do is Load my texture images into an array so that I can reference them in my drawing code by number, rather than by name. I am drawing a tile map.
Instead of this:
tile1 = new Texture(Gdx.files.internal("grass.png"));
tile2 = new Texture(Gdx.files.internal("dirttile.png"));
tile3 = new Texture(Gdx.files.internal("watertile.png"));
I would like it to be more like:
tile[1] = new Texture(Gdx.files.internal("grass.png"));
tile[2] = new Texture(Gdx.files.internal("dirttile.png"));
tile[3] = new Texture(Gdx.files.internal("watertile.png"));
..so that later I can draw them by which tile I need..such as
tileType = worldMap[i][j]; //will be an int number
batch.draw(tile[tileType], tileX, tileY);
I can't figure out how to initialize array and load textures into it though in order to do this, without getting errors.
Basically I need to draw my map based on numbers I have in a tile map like this:
int worldMap[][] = {
{ 1,1,1,1,1,1,1,1,1,1 } ,
{ 1,1,1,1,1,1,1,1,1,1 } ,
{ 1,1,1,1,1,1,1,1,1,1 } ,
{ 1,1,1,3,3,3,1,1,1,1 } ,
{ 1,1,1,3,3,3,1,1,1,1 } ,
{ 1,1,1,3,3,3,1,1,1,1 } ,
{ 1,1,1,1,1,1,1,1,1,1 } ,
{ 1,1,1,1,1,1,1,1,1,1 } ,
{ 1,1,1,1,1,1,1,1,1,1 } ,
{ 1,1,1,1,1,1,1,1,1,1 } ,
};
I need to draw the map tile based on the numbers in that map... 1 = grass 2 = dirt 3 = water etc.... Still no luck getting the array working.