SFML community forums

General => General discussions => Topic started by: Xenavar on June 01, 2010, 05:21:53 am

Title: Passing a render window to a class?
Post by: Xenavar 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)'|
Title: Passing a render window to a class?
Post by: Walker 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.
Title: Passing a render window to a class?
Post by: Xenavar 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)
Title: Passing a render window to a class?
Post by: Xenavar on June 01, 2010, 08:57:36 pm
bump
Title: Passing a render window to a class?
Post by: panithadrum 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?