Hi,
All my tiles are in one texture. I then use sprite batch to render them.
batch.begin();
// Draw the map - only draw what camera sees
worldMap.drawMap(debug, batch, regions, camX - 2, camY, endX + 2, endY,
WORLDWIDTH, WORLDHEIGHT);
batch.end();
and my drawMap method:
public void drawMap(boolean bDebug, SpriteBatch batch,
TextureRegion[][] region, int sx, int sy, int ex, int ey, int w,
int h) {
if (bDebug) { // debug mode - brute force draw everything
for (int row = 0; row < h; row++)
for (int col = 0; col < w; col++)
if (getEntity(col, row) != null)
worldMap[col][row].draw(batch, region);
} else { // draw what we can see
for (int row = sy; row < ey + 1; row++)
for (int col = sx; col < ex + 1; col++)
if (getEntity(col, row) != null) // THIS NEEDS REMOVING AT
// SOME POINT!!!!!
{
BlankEntity entity = getEntity(col, row);
if (entity instanceof WaterEntity)
batch.setColor(0, 0, 0.4f, 1);
else if (entity.lightUp)
batch.setColor(entity.r, entity.g, entity.b, 1);
else
batch.setColor(0.4f, 0.4f, 0.8f, 1);
worldMap[col][row].draw(batch, region);
}
}
}
and draw method for each entity is like this (t[.][.] is location of the tile in the texture region):
public void draw(Batch batch, TextureRegion[][] t) {
batch.draw(t[1][0], x << size, y << size); // 0,0
}
I assume this is ok? The setColor code in here is a dirty way of lighting blocks up near the player.
Thanks