waco001
waco001

Reputation: 61

Control RenderWindow from another function

this may sound as a really simple question, but I have SFML 1.6 and I want to control my RenderWindow from another function... I'm not very good at C++ or SFML... :)

////////////////////////////////////////////////////////////
// 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

waco001

Upvotes: 1

Views: 998

Answers (1)

Syntactic Fructose
Syntactic Fructose

Reputation: 20084

Pass your renderwindow as a parameter to the function like so:

void printmessage(bool thing, sf::RenderWindow& app)
{
    app.doSomething();
}

Dont forget to the window as a reference&

Then call the function in main

printmessage(atmainmenu,app);

Upvotes: 1

Related Questions