So I am trying to draw a tile map to the screen. My initial idea was to create a text file using numbers to represent certain tiles. It works for certain ones but if I have a file like this drawn
2 0 2 2 2 0 0 2 2 2 0 0 0 0 0 0 2 2 2
1 1 1 1 1 1 1 1 1 1 1 1 0 0 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 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 1 1 1 1 1 1 1 1 1 1 1 1
It turns out like this
I can't seem to understand why. My current process is I create an instance of my level class. Then within each instance of a level is an array to store all of my numbered tiles for any given level, a 2d array to store the numbers from any tilemap txt file like above. Then an array to store all the sprites for the tilemap.
So the code to load the tiles is this
void Level::LoadTiles()
{
int i = 0;
// DEBUG ///////
tileIds[i] = agk::LoadImage("/Users/maxmarze/Documents/AGK_BETA/AGK/IDE/templates/template_mac_xcode4/air.png");
cout << i << endl;
i++;
tileIds[i] = agk::LoadImage("/Users/maxmarze/Documents/AGK_BETA/AGK/IDE/templates/template_mac_xcode4/dirt_resize.png");
i++;
tileIds[i] = agk::LoadImage("/Users/maxmarze/Documents/AGK_BETA/AGK/IDE/templates/template_mac_xcode4/grass_top_resize.png");
cout << i << endl;
tileNumber = i;
cout << endl << endl;
}
The code to load the file is this
void Level::LoadTileMap(const string& filename)
{
fstream mapFile(filename.c_str());
for(int r = 0; r < MAX_TILES; r++)
{
for(int c = 0; c < MAX_TILES; c++)
{
int temp = 0;
if(!mapFile.eof())
{
mapFile >> temp;
tileMap[r][c] = tileIds[temp];
} else
{
tileMap[r][c] = tileIds[0];
}
}
}
}
And to draw the tiles is this
void Level::DrawTiles()
{
cout << tileIds[0] << endl;
cout << tileIds[1] << endl;
float height = 400.f;
//float height = 0.f;
float width = 0.f;
//int i = 0;
numOfTileSprites = 0;
for(int r = 0; r < MAX_TILES; r++)
{
for(int c = 0; c < MAX_TILES; c++)
{
if(tileMap[r][c] != tileIds[0])
{
tileSprites[numOfTileSprites] = agk::CreateSprite(tileMap[r][c]);
agk::SetSpriteScale(tileSprites[numOfTileSprites], SCALE, SCALE);
agk::SetSpritePhysicsOn(tileSprites[numOfTileSprites], 1);
//agk::SetSpriteGroup(tileSprites[numOfTileSprites], 1);
//agk::SetSpritePhysicsMass(tileSprites[numOfTileSprites], 100.f);
//agk::FixSpriteToScreen(tileSprites[numOfTileSprites], 1);
agk::SetSpritePosition(tileSprites[numOfTileSprites], width, height);
}
width += (16.f * SCALE);
//i++;
numOfTileSprites++;
}
height += (16.f * SCALE);
width = 100.f;
}
}
If I keep it under a certain number of rows and columns then it draws correctly but like the picture shows, it does not draw correctly here.