I already read the section for this issue on the Tutorials page, and I've read some instances of this issue around the forums; the problem is that none of this helps me much.
Since I'm a newbie at C++, I don't know the proper way to "extend the texture's lifetime as long as they are used by sprites." I was hoping someone would be able to help me fix this.
I'm currently using just a temporary method (for the purpose of testing) to draw a sprite to the window. This is all taking place within Engine:
Engine.h#ifndef Engine_h
#define Engine_h
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include "TextureManager.h"
#include "Tile.h"
class Engine
{
private:
sf::RenderWindow* window;
bool Initialize();
void MainLoop();
void ProcessInput();
void RenderFrame();
void Update();
TextureManager textureManager;
void LoadImages();
Tile* testTile;
public:
Engine();
~Engine();
void Go();
sf::Texture BackgroundTexture;
sf::Sprite Background;
};
#endif
Engine.cpp#include <iostream>
#include "Engine.h"
Engine::Engine()
{
}
Engine::~Engine()
{
delete window;
}
bool Engine::Initialize()
{
window = new sf::RenderWindow(sf::VideoMode(800, 612, 32), "BattleGame - V2");
if(!window)
return false;
else if(!BackgroundTexture.loadFromFile("BattleGame.app/Contents/Resources/BG.png"))
return false;
else
Background.setTexture(BackgroundTexture);
LoadImages();
return true;
}
void Engine::ProcessInput()
{
sf::Event Event;
while(window->pollEvent(Event))
{
switch(Event.type)
{
case sf::Event::Closed:
window->close();
break;
}
}
}
void Engine::MainLoop()
{
while(window->isOpen())
{
ProcessInput();
Update();
RenderFrame();
}
}
void Engine::Update()
{
}
void Engine::LoadImages()
{
sf::Texture sprite;
sprite.loadFromFile("BattleGame.app/Contents/Resources/ConsoleGUI.png");
textureManager.AddTexture(sprite);
testTile = new Tile(sprite);
}
void Engine::RenderFrame()
{
window->clear();
window->draw(Background);
testTile->Draw(0, 486, window);
window->display();
}
void Engine::Go()
{
if(!Initialize())
throw "The engine failed to initialize.";
else
MainLoop();
}