Hello i am new to SFML and i am using codingmadeeasy's tutorials on YouTube as well as the written tutorials for SFML to help me get started. Everything was going good till i got to one of his tutorials that deal with loading maps from a file where you can decide what tiles are using 1's and 0's. Well before i even try implementing code into my own games i copy and paste them and make sure the work at first. So when i tried to compile the code he had put on his site, the code compiled fine but the 1's on the map file wont appear which are orange color but the blue tiles which are 0's do appear, Can you figure out what is wrong with the code?
// C++ Sfml Made Easy Tutorial 29 - Loading Tile Maps [Easy]
// CodingMadeEasy
#include<SFML/Graphics.hpp>
#include<iostream>
#include<fstream>
#define ScreenWidth 800
#define ScreenHeight 600
#define BLOCKSIZE 40
int loadCounterX = 0, loadCounterY = 0;
int mapSizeX, mapSizeY;
int MapFile[100][100];
void LoadMap(const char *filename)
{
std::ifstream openfile(filename);
if(openfile.is_open())
{
openfile >> mapSizeX >> mapSizeY;
while(!openfile.eof())
{
openfile >> MapFile[loadCounterX][loadCounterY];
loadCounterX++;
if(loadCounterX >= mapSizeX)
{
loadCounterX = 0;
loadCounterY++;
}
}
}
}
void DrawMap(sf::RenderWindow &Window)
{
sf::Shape rect = sf::Shape::Rectangle(0, 0, BLOCKSIZE, BLOCKSIZE, sf::Color(255, 255, 255, 255));
sf::Color rectCol;
for(int i = 0; i < mapSizeX; i++)
{
for(int j = 0; j < mapSizeY; j++)
{
if(MapFile[i][j] == 0)
rectCol = sf::Color(44, 117, 255);
if (MapFile[i][j] == 1)
rectCol = sf::Color(255, 100, 17);
rect.SetPosition(i * BLOCKSIZE, j * BLOCKSIZE);
rect.SetColor(rectCol);
Window.Draw(rect);
}
}
}
int main()
{
sf::RenderWindow Window(sf::VideoMode(ScreenWidth, ScreenHeight, 32), "SFML Made Easy");
LoadMap("Map.txt");
while(Window.IsOpened())
{
sf::Event Event;
while(Window.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed || Event.Key.Code == sf::Key::Escape)
Window.Close();
}
Window.Clear();
DrawMap(Window);
Window.Display();
}
return 0;
}
By the way my Map.txt file looks like this
10 10
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
1111111111