从另一个函数控制RenderWindow

Control RenderWindow from another function

本文关键字:RenderWindow 控制 函数 另一个      更新时间:2023-10-16

这可能听起来像一个非常简单的问题,但我有SFML 1.6,我想控制我的RenderWindow从另一个函数…我不太擅长c++或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 <----
    }
}

这是我的代码,但我想控制'App'从atmainmenu。有什么需要我做的吗?由于

waco001

将renderwindow作为参数传递给函数,如下所示:

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

不要忘记将窗口作为参考&

然后调用main

中的函数
printmessage(atmainmenu,app);