SFML community forums
Help => Graphics => Topic started by: Fortas on December 12, 2013, 08:05:41 pm
-
Hello.
I use 4 classes in my project atm:
-ScreenMenager: use to menage screens;
-VirtualClass: using virtual methods;
-GameScreen: main screen which I want to use for interactions between other classes;
-PlayerClass;
ScreenMenager has a pointer to VirtualClass. I use it to display GameScreens methods by virtual ones. PlayerClass has private Sprite and Texture which I want to display. Its going like:
GameScreen class has no Texture and no Sprite.
void GameScreen::Draw(sf::RenderWindow &window)
{
players.Draw(window); // <-- PlayerClass object;
}
void PlayerClass::Draw(sf::RenderWindow &window)
{
window.draw(playerSprite);
}
I loaded texture in PlayerClass by using constructor.
My question is how can I transfer the texture to PlayerClass or how can I display it from PlayerClass level? Is it even possible or I have to find other way?
-
I don't quite understand your question...
Just load the texture once into your program (if your game is something bigger I'd make a class for managing them) and simply set the texture to the sprite, which is a member of your PlayerClass (probally in the constructor, or a setTexture function). No need to transfer anything or store the texture itself in playerClass.
-
You mighr want to look into resource managment. The SFML Game Dev book has a nice approach to this. If you can't buy it, I suggest you simply take a look at the source code, which is located on Laurent's GitHub account.
Optionally you could look at Thor's system, but that one might be too complex for your needs.
Generally you shouldn't store the texture within you entity/player.
For a simple way to handle screens you could look at my SmallGameEngine on my GitHub account.