尝试将引擎从SDL重写为SFML,sf::RenderWindow的范围是错误的

Try to rewrite engine from SDL to SFML, wrong scope of sf::RenderWindow?

本文关键字:sf 错误 RenderWindow SFML 范围是 引擎 重写 SDL      更新时间:2023-10-16

我的显示图像有问题(我试图将引擎从 SDL 重写为 SFML 2.0;引擎下载自:http://gamedevgeek.com/tutorials/managing-game-states-in-c/)

我对 introstate.cpp 中的那部分代码有问题。

程序编译并创建窗口(仅一秒钟),然后消失,没有任何反应,也没有渲染任何内容(它应该显示图像)。

我认为这与对象范围有关 sf::RenderWindow MarioClone。我的意思是它是在几个标题中声明的,并在各种方法中使用,所以我认为指向创建的特定窗口存在误解。我应该使用"extern"关键字somwhere还是什么?

我留下了指向 github 的链接,因为代码在许多文件中,甚至一个文件包含大量代码并且不想将其粘贴到此处(很难阅读)。https://github.com/shahar23/MarioClone(是的 - 代码有以前的原始 SDL 注释,以便轻松理解应该在方法中放入什么)

在游戏引擎.cpp文件的init方法中,创建一个与头文件中声明的变量同名的局部变量。那不是你想要的。您要更改现有变量:

void CGameEngine::Init(const char* title, int width, int height, bool fullscreen)
{
    // This line creates a NEW LOCAL variable of the same name. 
    // Your instance level variable remains unchanged:
    // sf::RenderWindow MarioClone(sf::VideoMode(width, height), title, sf::Style::Default);
    // instead, change your class level variable:
    MarioClone.create(sf::VideoMode(width, height), title, sf::Style::Default);