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

Author Topic: Passing a render window to a class?  (Read 6894 times)

0 Members and 1 Guest are viewing this topic.

Xenavar

  • Newbie
  • *
  • Posts: 40
    • View Profile
Passing a render window to a class?
« on: June 01, 2010, 05:21:53 am »
What is the correct syntax to do that? In both the .h and .cpp. because right now I am getting the following error:

C:\Users\Steven\Desktop\SFML-1.5\include\SFML\System\NonCopyable.hpp|57|error: `sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private|

followed by:

C:\Users\Steven\Desktop\RPG\main.cpp|21|error:   initializing argument 2 of `void PC::Handle_event(sf::Event, sf::RenderWindow)'|

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Passing a render window to a class?
« Reply #1 on: June 01, 2010, 05:35:00 am »
I believe this is known as passing by reference. Could be that it's not though... ;)

Anyway, it works:

Code: [Select]
void CLASS::draw(sf::RenderWindow &target)
{
    target.Draw(sprite);
}



To call it:

Code: [Select]
class.draw(App);

Obviously, you might not be doing this for a drawing routine, but you should be able to see how it works.

Xenavar

  • Newbie
  • *
  • Posts: 40
    • View Profile
Passing a render window to a class?
« Reply #2 on: June 01, 2010, 09:36:55 am »
Is there a reason that when I pass a window to a class and then use events that use the window's elapsed time to make a sprite move, it has some lag spikes?

The first time I did it I had no classes at all and it worked perfecly fine on a normal function (in main)

Xenavar

  • Newbie
  • *
  • Posts: 40
    • View Profile
Passing a render window to a class?
« Reply #3 on: June 01, 2010, 08:57:36 pm »
bump

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Passing a render window to a class?
« Reply #4 on: June 01, 2010, 09:30:19 pm »
Quote from: "Xenavar"
Is there a reason that when I pass a window to a class and then use events that use the window's elapsed time to make a sprite move, it has some lag spikes?

The first time I did it I had no classes at all and it worked perfecly fine on a normal function (in main)

Not at all. What's the code?