1
Window / Re: Drawing/Displaying sprites from another function
« on: October 22, 2012, 09:24:01 am »You can for instance pass the render window as reference to the function and draw things from there.
I tried to pass it as reference but whenever i use a command such as *Window.draw(Sprite) in the function i get this error: error: request for member 'draw' in 'Window', which is of non-class type 'sf::RenderWindow*'
Why do i get this error?
Here's the code. It is just a test code with only 2 functions. soooo, it's really easy to understand.
#include <SFML/Graphics.hpp>
#include <iostream>
void Test(sf::RenderWindow *Window)
{
sf::Texture Texture;
Texture.loadFromFile("GreenCircle.png");
sf::Sprite Sprite;
Sprite.setTexture(Texture);
Sprite.setPosition(300, 300);
*Window.draw(Sprite);
}
int main()
{
//Declaring and defining the window
sf::VideoMode VMode (640, 480, 32);
sf::RenderWindow Window (VMode, "Standard window application", sf::Style::Default);
//Declaring the Event
sf::Event Event;
//The main loop
while (Window.isOpen())
{
Test(&Window);
while (Window.pollEvent(Event))
{
// Escape key : exit
if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
Window.close();
}
Window.display();
}
return 0;
}
#include <iostream>
void Test(sf::RenderWindow *Window)
{
sf::Texture Texture;
Texture.loadFromFile("GreenCircle.png");
sf::Sprite Sprite;
Sprite.setTexture(Texture);
Sprite.setPosition(300, 300);
*Window.draw(Sprite);
}
int main()
{
//Declaring and defining the window
sf::VideoMode VMode (640, 480, 32);
sf::RenderWindow Window (VMode, "Standard window application", sf::Style::Default);
//Declaring the Event
sf::Event Event;
//The main loop
while (Window.isOpen())
{
Test(&Window);
while (Window.pollEvent(Event))
{
// Escape key : exit
if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
Window.close();
}
Window.display();
}
return 0;
}