Thank you for the reply.
Now we know the problem, I'm going to post the bigger picture.
First of all, how my program works is that in the MainGameState's constructor, Map->load() function is called, which look like this.
void Map::load(std::string filename){
// this->texture->loadFromFile("resources/" + filename);
std::ifstream openMap("resources/" + filename);
std::getline(openMap,this->tileset);
this->tile_width = 64; // there are no methods of converting string to integer in 32 bitMinGW, so let's just fix it to 64 bits.
this->tile_length = 64;
this->width = 20;
this->length = 12;
this->tile->loadFromFile("resources/tiles.png");
this->data = new int[this->width * this->length];
for(int y = 0;y < this->length;y++){
for(int x =0;x < this->width;x++){
char temp;
openMap >> this->data[x + y * this->width] >> temp;
// std::cout << this->data[x+y*this->width];
// manage.add("stone",stone);
}
}
openMap.close();
sf::Image tile1,tile2,tile3,tile4,tile5;
tile1.create(64,64);
tile2.create(64,64);
tile3.create(64,64);
tile4.create(64,64);
tile5.create(64,64);
tile1.copy(*this->tile,0,0,sf::IntRect(0,0,this->tile_width,tile_width)); // stone
tile2.copy(*this->tile,0,0,sf::IntRect(64,0,this->tile_width,tile_width)); // dark stone
tile3.copy(*this->tile,0,0,sf::IntRect(0,64,this->tile_width,tile_width));
tile4.copy(*this->tile,0,0,sf::IntRect(64,64,this->tile_width,tile_width));
tile5.copy(*this->tile,0,0,sf::IntRect(128,0,this->tile_width,tile_width));
for(int y = 0;y<this->length;y++){ //runs through all of the data[] and assigns each to a texture.
for(int x =0;x < this->width;x++){
switch(this->data[x+y*this->width]){
case 1:
/* this->texture->loadFromImage(tile1);
this->tiles->setTexture(*this->texture);
this->tiles->setPosition(x*64,y*64);
manage.add("tile2",tiles);*/
this->texture->loadFromImage(tile1);
break;
case 2:
/* this->texture->loadFromImage(tile2);
this->tiles->setTexture(*this->texture);
this->tiles->setPosition(x*64,y*64);
manage.add("tile2",tiles); */
this->texture->update(tile2,x*64,y*64);
break;
case 3:
/*this->texture->loadFromImage(tile3);
this->tiles->setTexture(*this->texture);
this->tiles->setPosition(x*64,y*64);
manage.add("tile3",tiles); */
this->texture->update(tile3,x*64,y*64);
break;
case 4:
/*this->texture->loadFromImage(tile4);
this->tiles->setTexture(*this->texture);
this->tiles->setPosition(x*64,y*64);
manage.add("tile4",tiles);*/
this->texture->update(tile4,x*64,y*64);
break;
case 5:
/*this->texture->loadFromImage(tile5);
this->tiles->setTexture(*this->texture);
this->tiles->setPosition(x*64,y*64);
manage.add("tile5",tiles);*/
this->texture->update(tile5,x*64,y*64);
break;
default:
break;
}
}
}
this->setTexture(*this->texture);
}
the reason I use copy is that the "tiles.png" is the tileset, and each tile is supposed to represent the different parts of the tile.
Surely, if the problem is that the file is loaded over and over, it wouldn't happen in this case where the map is rendered only once?