SFML community forums

Help => Graphics => Topic started by: Mad Engineer on January 12, 2014, 10:55:02 pm

Title: Pass RenderWindow to function
Post 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.
Title: Re: Pass RenderWindow to function
Post by: Assassin0795 on January 12, 2014, 11:58:19 pm
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).
Title: Re: Pass RenderWindow to function
Post by: Mad Engineer on January 13, 2014, 12:31:32 am
omg thank you so much, i used drawable so now i can put player in draw call :D . Thanks man
Title: AW: Pass RenderWindow to function
Post by: eXpl0it3r on January 13, 2014, 08:01:40 am
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.
Title: Re: Pass RenderWindow to function
Post by: Raincode on January 13, 2014, 03:17:22 pm
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)
{
    //...
}