从另一个函数控制RenderWindow
Control RenderWindow from another function
这可能听起来像一个非常简单的问题,但我有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);
相关文章:
- 控制允许动态运行c++的并发操作数
- 从控制台中删除最后打印的元素
- 是否可以使用if constexpr删除控制流语句
- 无法在windows控制台中为C++程序提供必要的输入
- SFML RenderWindow打开窗口需要很长时间
- 控制到达非空函数clang(-Wreturn-type)的末尾
- 查找 GCD:并非所有控制路径都返回值
- 通过 API 控制 DJI 相机
- 禁止在控制台上记录谷神星
- 是否可以使用一个类来控制 C++ 中另一个类的对象?(阿杜伊诺)
- 初学者问题:如何使用这些晦涩难懂的命令,例如C++中的'RenderWindow'
- 如何删除列出的"QGraphicsPathItem"对象以控制进程内存使用情况?
- 我在 C++ 代码中遇到错误警告:控制到达非空函数 [-Wreturn 类型] 的末尾
- C++ Python 模块在 Blender 中崩溃,但在 Python 控制台中不会崩溃
- wx通用目录控制错误"wxTheFileIconsTable was nullptr"
- main() 中的 std::cout 在调试期间不会在调试控制台中打印任何内容
- Cython通过浮点数的最快方式,用于高频控制回路
- 用户控制从 c++ 到 java 脚本的 Webassembly 访问调用
- C ++,如何从控制台中输入的字符串中删除字母?
- 从另一个函数控制RenderWindow