1

これは非常に単純な質問のように聞こえるかもしれませんが、私は 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 <----
    }
}

これが私のコードですが、atmainmenu から「アプリ」を制御したいと考えています。何かしなければならないことはありますか?ありがとう

waco001

4

1 に答える 1

1

次のように、renderwindow をパラメーターとして関数に渡します。

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

参照としてウィンドウを忘れないでください&

次に、メインで関数を呼び出します

printmessage(atmainmenu,app);
于 2013-03-22T19:28:45.807 に答える