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

Author Topic: How do I get the RenderWindow in another Class?  (Read 2377 times)

0 Members and 1 Guest are viewing this topic.

kim366

  • Newbie
  • *
  • Posts: 35
    • View Profile
How do I get the RenderWindow in another Class?
« on: January 09, 2014, 04:04:02 pm »
Hello, I wanted to ask how I get the RenderWindow to another Class, do i have to make getter-Functions or how can I sove it with Pointers?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: How do I get the RenderWindow in another Class?
« Reply #1 on: January 09, 2014, 04:14:41 pm »
Pass it to a function.

class MyClass
{
public:
     void FooBar(sf::RenderWindow& Window)
     {
          // Do something
     }
}
 
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

amir ramezani

  • Jr. Member
  • **
  • Posts: 81
  • i'm a programmer who can't see well
    • View Profile
    • download useful software!
    • Email
Re: How do I get the RenderWindow in another Class?
« Reply #2 on: January 09, 2014, 05:09:30 pm »
you can created publicly!
Code: [Select]
class myclass: public RenderWindow
{
//your codes goes here
};
if you can't see well, you can't test your applications and operating system well
my game engine:
allegro game creator
my operating system:
AmirOS

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: How do I get the RenderWindow in another Class?
« Reply #3 on: January 09, 2014, 05:27:19 pm »
you can created publicly!
No, don't inherit if it's not necessary. Composition is mostly the better alternative.

See also here.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

amir ramezani

  • Jr. Member
  • **
  • Posts: 81
  • i'm a programmer who can't see well
    • View Profile
    • download useful software!
    • Email
Re: How do I get the RenderWindow in another Class?
« Reply #4 on: January 09, 2014, 08:47:27 pm »
you can of course, but use it inside functions
if you can't see well, you can't test your applications and operating system well
my game engine:
allegro game creator
my operating system:
AmirOS

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11035
    • View Profile
    • development blog
    • Email
Re: How do I get the RenderWindow in another Class?
« Reply #5 on: January 10, 2014, 09:56:34 am »
you can of course, but use it inside functions
Of course you "can", but composition instead of inheritance is considered a better design. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/