SFML community forums
Help => Graphics => Topic started by: Mad Engineer on January 12, 2014, 10:55:02 pm
-
Lets say i have main function and there i have declared a RenderWindow window.
In my player class i have Draw function to draw everything relevant to player. How can i pass window from my main function to my draw function in player class so i can draw player stuff, and then just call player.draw( render window) in main game loop.
-
If I understand what you're saying, why wouldn't you just use window.draw(player)? It calls the draw() method from your Player class.
You can find more here under "Creating a SFML-like Entity" (http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array).
-
omg thank you so much, i used drawable so now i can put player in draw call :D . Thanks man
-
In general, if you have to pass something to a function, you should use a reference. For standard types you can pass it by value.
-
The best Version is probally, as you already have done it, make your Player drawable. If you want to use the RenderWindow in a function:
void foo(sf::RenderWindow &window)
{
//...
}