Hi there,
I'm a hobbyist programmer and SFML beginner, I've done some easy project in the past like pong, now I'm trying to write a map system for more advanced games.
I'm just started with it but have already encountered a problem: apparently the tile sprites are drawn but not the image I set to them.
I have a Load() function which works like a constructor for my Map class, basically it should fill the "tiles" vector with stuff for testing since I haven't done a map reading/writing system yet. In this function I have an Image var and I set it with Image.LoadFromFile() like this:
sf::Image Image;
if (!Image.LoadFromFile("../img.png")) {
std::cout << "Could not load file: ../img.png" << std::endl;
return false;
}
then I have the loop which "creates" the sprites and sets them to the tiles vector, like this:
for (int i = 0; i < 255; i++) {
sf::Sprite Sprite;
Sprite.SetImage(Image);
Sprite.SetPosition(x * tileWidth, y * tileHeight);
Sprite.SetColor(sf::Color(200,100,100,255));
tiles.push_back(Sprite);
}
I have this which I call in the main loop between RenderWindow.Clear() and RenderWindow.Display() to draw stuff on screen:
void Map::Draw(sf::RenderWindow &window) {
for (int tile = 0; tile < tiles.size(); tile++) {
window.Draw(tiles[tile]);
}
}
For some reason the tiles are displayed as pink-ish squares (the 200,100,100 RGB color I set in the code) but the image is not displayed.
I'm using Microsoft Visual C++ 2010 and have read
this thread but it seems not to be my case.
What am I doing wrong and can anyone reccomend me any kind of reference for a project like this? Thank you.