So I have this interesting problem with my tile engine. My nested for loops start rendering the tiles from the upper-left ([0][0] of the array), but OpenGL starts rendering at the bottom left. So whenever I create a level, and then render it, it renders sideways. If that makes any sense…
This is how I initialize the level:
//the tiles[][] array refers to my Tile class tiles, the ids[][] array is an int array containing tile ids passed by the constructor,
//and Tile.tiles is an ArrayList containing all the tiles that exist
for(int x = 0; x < ids[0].length; x++){
for( int y = 0; y < ids.length; y++){
//iterate through tile IDs
for(int i = 0; i < Tile.tiles.size(); i++){
if(Tile.tiles.get(i).getID() == ids[x][y]){ //check for match
tiles[x][y] = Tile.tiles.get(i); //the tile matched an id in the array, so set that tile to the one it matched
}
}
}
}
And how I render it:
//pos is a vector representing the position of the level
for(int x = 0; x < ids[0].length; x++){
for(int y = 0; y < ids.length; y++){
//set x and y coords of tiles before rendering
tiles[x][y].getPos().setX(pos.getX() +(x * tileSize); //set X
tiles[x][y].getPos().setY(pos.getY() +(y * tileSize); //set Y
//render tile
tiles[x][y].render();
}
}
}
I’m pretty sure I could just change the origin to be the top left instead of bottom left using glOrtho, but I don’t really like thinking that way.
Hopefully you guys understand the problem. Any help?