While the subject title sounds retarded and newbish, it's actually an interesting problem. I am a newbie at C++ coding, and SFML is just another layer of stuff for me to learn.
The general issue is simple enough; I create a Texture, load a .png file to it, then .setTexture it to a sprite object. I did this all in one method. Next, I try to use the aforementioned Sprite in another method, to be drawn to a window. It doesn't display.
Then I'm all like WTF and go crazy trying to fix it, then I end up putting it in the method that draws to the RenderWindow and it works fine. Why be this?
#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
return true;
// Let's create the background image here, where everything initializes.
if(!BackgroundTexture.loadFromFile("BattleGame.app/Contents/Resources/BG.png"))
throw "Failure!";
else
Background.setTexture(BackgroundTexture);
}
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::RenderFrame()
{
window->clear();
window->draw(Background); // And now we draw the background; but it doesn't work.
window->display();
}
void Engine::Go()
{
if(!Initialize())
throw "The engine failed to initialize.";
else
MainLoop();
}