Hi there!
I'm new to SFML, and I experience my first troubles...
I try to do things well: I created a StateManager, and a simple SplashScreenState. I also have an AssetManager that is a factory and creates me sf::Sprites (or other things) when I need one. It takes care of the textures and memory management.
But I have a problem...
My SplashScreenState creates a simple Sprite with an image inside. Then my main loop calls "currentState->draw()"... But nothing shows on the screen! However, if I get a pointer to that sprite, and call "renderWindow.draw()" directly from my main loop, it works like a charm.
What on earth is happening? I tried to debug references and pointers, but they are all valid and identical. AssetManager works well, because I can display the sprite properly in one case, therefore the sprite is ok.
I don't understand what is going on...
// Main loop :
void Game::loop()
{
JLE::StateManager stateManager = JLE::StateManager(*this);
stateManager.push(SplashScreenState::instance());
sf::Sprite* sprite;
while (m_window.isOpen())
{
JLE::AState* currentState = stateManager.current();
if (!currentState)
break;
sprite = currentState->m_splashImg; // I added splashImg in AState for debug purposes
std::cout << sprite << " / " << this << " / " << &this->m_window << std::endl;
m_window.clear();
// I switch between these two options to test...
//currentState->draw(); // This one does not work
m_window.draw(*sprite); // This one works
m_window.display();
}
}
// Init splash screen
void SplashScreenState::init(JLE::AGame& game)
{
m_game = &game;
m_active = true;
m_splashImg = JLE::AssetManager::factorySprite("splash.jpg");
LOG_S() << "splash : " << m_splashImg << std::endl;
}
// Draw splash screen
void SplashScreenState::draw()
{
LOG_S() << "draw..." << m_splashImg << " / " << m_game << " / " << &m_game->m_window << std::endl;
m_game->m_window.draw(*m_splashImg);
}
Please, help me!
PS : also, do not hesitate to tell me if I do things that are not best practices. I try to do my best, but I haven't touched C++ for like 10 years
and I was just some beginner at the time
Thanks in advance!