Hello everybody,
So I had a working program before but it only consisted of a header file and a cpp file. It basically created a player sprite that moved using the arrow keys.
But now I'm splitting things up into different classes and I've encountered a problem. In my game loop I can call:
window.draw(playerImage);
but I can't do that in the player class (at least I don't know how to).
What's giving me trouble is that I can't access the window variable from another class. I've tried adding this in my setup class and calling it from the player class, but it doesn't work:
//Setup class:
void CSetup::Render(sf::Texture texture, sf::Sprite sprite, std::string path, float x, float y)
{
if (!texture.loadFromFile(path))
std::cout << "Could not find " << path << std::endl;
sprite.setTexture(texture);
sprite.setPosition(x, y);
window.draw(sprite);
}
//Player class
void CPlayer::RenderPlayer(void)
{
setup -> Render(pTexture, pImage, "player.png", 384, 284);
}
When I try to do this, the screen just appears white and I can't exit the window except by closing the debug console.
How can I draw a Sprite from the player class?
Thanks for your time!