I have a game class with a function to load my sprite into a stack and a function to draw the stack of sprites. I have set it up this way so when I have more sprites it is easier to program.
I also have a floor class that makes the sprite and the texture in the constructor, then loads it into my vector of sprites.
My problem is that my texture doesn't display on the screen, not even a white box. Is there an obvious mistake? Or am I just not understanding how textures work.
Floor.cpp
Floor::Floor()
{
Game game;
sf::Sprite floor;
sf::Texture* pointerToFloorTexture = new (sf::Texture);
pointerToFloorTexture->loadFromFile("floor.png");
game.LoadSpriteIntoStack(floor, pointerToFloorTexture);
}
Game.cpp
void Game::LoadSpriteIntoStack(sf::Sprite sprite, sf::Texture *texture)
{
sprite.setTexture(*texture);
stackOfSprites.push_back(sprite);
}
void Game::DrawStackOfSprites(sf::RenderWindow& window)
{
for (unsigned int i = 0; i < stackOfSprites.size(); i++)
{
window.draw(stackOfSprites[i]);
}
}
main.cpp (just the loop)
while (window.isOpen())
{
// Handle Events
game.HandleEvents(window);
window.clear();
// Draw Sprites
game.DrawStackOfSprites(window);
window.display();
}
Game.h
#pragma once
class Game
{
public:
Game();
// Handle Events
void HandleEvents(sf::RenderWindow& window);
void LoadSpriteIntoStack(sf::Sprite sprite, sf::Texture *texture);
void DrawStackOfSprites(sf::RenderWindow& window);
private:
std::vector<sf::Sprite> stackOfSprites;
};