Hello!
First: Sry for my bad english
I wrote a class to load a map from my map1.txt.
Every value in the maparray is
correct.
But i cant see anything in my window except my playercharacter and a black screen behind him, not one single tile.
#include <iostream>
#include <fstream>
#include <vector>
#include <SFML/Graphics.hpp>
using namespace std;
class Map
{
public:
int map_x, map_y;
static int tile;
int map[100][100];
sf::Image image;
sf::Texture textur;
vector<sf::Sprite> tiles;
sf::RenderTexture rMap;
sf::Sprite sMap;
public:
Map()
{
map_x = 0;
map_y = 0;
image.loadFromFile("graphics/boden.png");
if(!image.loadFromFile("graphics/boden.png"))
{
std::cout << "boden.png konnte nicht geladen werden!\n";
}
textur.loadFromImage(image);
};
~Map(){};
void loadMap(const char *filename)
{
int loadCounterX = 0, loadCounterY = 0;
std::ifstream file(filename);
if(file.is_open())
{
file >> map_x >> map_y;
while(!file.eof())
{
file >> map[loadCounterX][loadCounterY];
loadCounterX++;
if(loadCounterX >= map_x)
{
loadCounterX = 0;
loadCounterY++;
}
}
}
for(int x = 0; x < map_x; x++)
{
for(int y = 0;y < map_y; y++)
{
int tileId = map[x][y];
sf::Sprite tile;
tile.setTexture(textur);
tile.setTextureRect(sf::IntRect(map[y][x]*32, 0, 32, 32));
tile.setPosition(x*32, y*32);
tiles.push_back(tile);
}
}
for(int x = 0; x < tiles.size(); x++)
{
rMap.draw(tiles.at(x));
cout << "x";
}
}
sf::Sprite drawMap()
{
rMap.display();
sMap.setTexture(rMap.getTexture());
return sMap;
}
};
first i called this out of the mainloop:
Map map1;
map1.loadMap("map1.txt");
And in my mainloop i call:
Spiel.draw(map1.drawMap());
Hope you can help me.
Greetings!