Using more than one texture

I am trying to use more than one texture image when drawing tiles to my game screen.
I have a map file with 1’s and 0’s which correspond to the 2 textures i have.

I created an array of two slick2d textures, like so: Texture[2] tex; …And loaded the into tex[0] and tex[1].
When i load the map file to an array and then try passing the texture with the array index being the current index of the map array which passes either 1 or 0 as the texture index.

		
for (int yTile = 0; yTile < 640 / 64; yTile++) {
	for (int xTile = 0; xTile < 768 / 64; xTile++) {
		int i = 0;
		Tile tile = (Tile)tiles.get(i);
		tile.render(tex[map[i]], xTile * Tile.TILE_WIDTH, yTile * Tile.TILE_HEIGHT);
		i++;
	}
}

All i get is one of the tile textures rendered.

Here is the tile class’s render method:


	public void render(Texture bindTex, int xOff, int yOff) {
		bindTex.bind();
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f);
			glVertex2i(xOff, yOff);
			glTexCoord2f(1.0f, 0.0f);
			glVertex2i(xOff + TILE_WIDTH, yOff);
			glTexCoord2f(1.0f, 1.0f);
			glVertex2i(xOff +TILE_WIDTH, yOff + TILE_HEIGHT);
			glTexCoord2f(0.0f, 1.0f);
			glVertex2i(xOff, yOff +TILE_HEIGHT);
		glEnd();
	}

What is happening?

You aren’t drawing with the second texture. The variable i is always 0, as you never use it when it is 1. >_>

I don’t quite get what you mean, how am I not using the second texture?

for (int xTile = 0; xTile < 768 / 64; xTile++) {
      int i = 0;
      Tile tile = (Tile)tiles.get(i);
      tile.render(tex[map[i]], xTile * Tile.TILE_WIDTH, yTile * Tile.TILE_HEIGHT);
      i++;
   }

He’s talking about this i = 0; You’re establishing an int i = 0; then incrementing it at the end of the loop… then when the loop restarts you recreate it at 0 :smiley: you need to put the int i = 0 elsewhere, probably at the very beginning of the method (haven’t read it all)

Faaaaaark I’ve been looking at that loop for ages and still didnt see it.
Thanks for your help.

also, your drawing one quad for every tile
very slow with many tiles

maybe it doesnt matter to you; but if you experience performance issues - just so you know

rookie error mate

Interesting first post…

Mike

i’ll be contributing in due time, don’t you worry :wink:
i’m researching networking atm, then moving onto Java 2D.
I’ve been messing with 2D side scrollers and pokemon styled games but decided i want to progress further.
haha, i’ve been reading this forum for a while and forgot to register. my name will be known… hopefully :slight_smile: