Hello, I am trying to display sprites inside a class function to display to the screen. However I am getting nothing but a wall of white. Here's my code:
class Game
{
public:
sf::RenderWindow App;
sf::View View;
vector <sf::Sprite> SpriteFiles;
vector <int> MapData;
vector <int> CollisionData;
vector <int> TransitionData;
vector <sf::Image> ImageFiles;
void Setup();
void LoadMap(string);//Map to load ID
void Display();
//void Setup();
void MainMenu();
void GetEvents();
void LevelUp(string, int*);//Daemon name, pointer to Daemon stats array
//Game();
//~Game();
private:
bool FilesExist;
int MapWidth, MapHeight, ScreenWidth, ScreenHeight, PosX, PosY;
};
^ The class sf::Sprite and sf::Image are initialized in
void Game::Setup()
{
App.Create(sf::VideoMode(1024, 768), "Daemons");
App.UseVerticalSync(true);//Clearer graphics ftw
//sf::View View(sf::FloatRect(0,0,1024,768));
View.SetFromRect(sf::FloatRect(0,0,1024,768));
App.SetView(View);//Sets up the view. So you can see stuff
App.SetFramerateLimit(60);
FilesExist = true;
int ImageNum = 0;
ScreenWidth = 17;
ScreenHeight = 13;
PosX = -1;
PosY = -1;
stringstream PictureName;
for(ImageNum = 0; ImageNum < 10; ImageNum++)
{
PictureName << "data/images/map/" << ImageNum << ".png";
ImageFiles.resize(ImageNum + 1);
SpriteFiles.resize(ImageNum + 1);
if(ImageFiles[ImageNum].LoadFromFile(PictureName.str().c_str()))
{
ImageFiles[ImageNum].SetSmooth(false);
SpriteFiles[ImageNum].SetImage(ImageFiles[ImageNum]);
}
cout << "\n" << PictureName.str().c_str() << "\n";
PictureName.str(string());
}
return;
}
////////////////////
//DISPLAY
////////////////////
void Game::Display()
{
try
{
App.Clear();
for (int y=PosY; y<ScreenHeight; y++)
{
for (int x=PosX; x<ScreenWidth; x++)
{
if ((y >= 0 && x >= 0) && (y <= ScreenHeight && x <= ScreenWidth))
{
if (MapData[x + (y * MapWidth)] == -1)
continue;
int holder = MapData[x + (y * MapWidth)];
SpriteFiles[holder].SetPosition(x * 64, y * 64);
//cout << holder;
App.Draw(SpriteFiles[holder]);
}
}
}
App.Display();
}
catch(exception& e)
{
cout << e.what() << "\n";
}
return;
}
^Where they are used
So what exactly is causing the images to not display correctly and how can I fix it?
Thanks.