Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Pass RenderWindow to function  (Read 3916 times)

0 Members and 1 Guest are viewing this topic.

Mad Engineer

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Pass RenderWindow to function
« 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.

Assassin0795

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Pass RenderWindow to function
« Reply #1 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".

Mad Engineer

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: Pass RenderWindow to function
« Reply #2 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
AW: Pass RenderWindow to function
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Raincode

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: Pass RenderWindow to function
« Reply #4 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)
{
    //...
}