【发布时间】:2019-04-09 05:13:44
【问题描述】:
这是我的程序的结构:
class Game
{
public:
unsigned int progressFlags;
sf::RenderWindow appWindow;
Screen* currentScreen;
Game(const unsigned int& width, const unsigned int& height,
const unsigned int& bitsPerPixel, const std::string& windowName);
~Game();
void drawScreen();
};
游戏包含一个屏幕,定义为:
class Screen
{
public:
std::vector<sf::Drawable*> sceneElements;
sf::Sprite backgroundSprite;
Screen();
virtual ~Screen();
protected:
sf::Texture backgroundTexture;
};
std::vector sceneElements 的元素是从这样的屏幕中收集的:
sceneElements.push_back(&backgroundSprite);
最后,我尝试用一个简单的方法来绘制我所有的图形对象:
void Game::drawScreen()
{
for (unsigned int i = 0; i < currentScreen->sceneElements.size(); i++)
appWindow.draw(*currentScreen->sceneElements(i));
}
但是 appWindow.draw() 失败了。我认为这与取消引用指针有关(一些我记不得的基本 c++ 知识),但我不知道如何解决它。我将不胜感激。
【问题讨论】:
-
sceneElements(i)是如何编译的? -
你是对的!最近我的 matlab 编码太多了……该死的 :)
标签: c++ pointers drawing sfml dereference