SFML community forums

Help => Window => Topic started by: waco001 on March 22, 2013, 08:20:22 pm

Title: Control RenderWindow from another function.
Post by: waco001 on March 22, 2013, 08:20:22 pm
Hi guy,  this may sound as a really simple question, but I have SFML 1.6 and I want to control my RenderWindow from another function...

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

using namespace std;



int main()
{

    // Create the main window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Guessing Game");
    App.SetFramerateLimit(60); //Set FPS limit to 60 FPS
    //Variables
    bool atmainmenu = true;
    //End Variables

    // Start main loop
    while (App.IsOpened())
    {
        printmessage(atmainmenu);
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::M)){

            }
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::F)){

            }
        }
        // Display window on screen
        App.Display();

    }
    return EXIT_SUCCESS;
}

void printmessage(bool atmainmenu)
{
    if(atmainmenu){
        //$$$$$$$################# HERE <----
    }
}
 

That is my code, but I want to control 'App' from atmainmenu. Is there anything I have to do? thanks :D

waco001
Title: Re: Control RenderWindow from another function.
Post by: binary1248 on March 22, 2013, 09:39:34 pm
I know it may seem harsh, but you should really spend a bit of time reading through this: http://www.cplusplus.com/doc/tutorial/

If you don't grasp basic C++, it is not recommended to try SFML yet.
Title: Re: Control RenderWindow from another function.
Post by: Ruckamongus on March 22, 2013, 09:43:03 pm
I know it may seem harsh, but you should really spend a bit of time reading through this: http://www.cplusplus.com/doc/tutorial/

If you don't grasp basic C++, it is not recommended to try SFML yet.

Specifically, look at references and pointers; both are valid ways to pass the window around. (References being the more "C++" approach and pointers being the more "C" approach.)