【发布时间】:2014-12-21 22:02:16
【问题描述】:
代码如下:
引擎.h
#include <SFML/Audio.hpp>
#include <SFML/Config.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
class Engine
{
public:
Engine(sf::RenderWindow & wd);
void run(sf::RenderWindow & wd);
sf::Sprite player;
sf::Texture playerTexture;
};
Engine.cpp
#include "Engine.h"
Engine::Engine(sf::RenderWindow & wd) : player(), playerTexture()
{
}
void Engine::run(sf::RenderWindow & wd)
{
if (!playerTexture.loadFromFile("image/char.png")) {}
player.setTexture(playerTexture);
while (wd.isOpen())
{
sf::Event event;
while (wd.pollEvent(event))
{
if (event.type == sf::Event::Closed)
wd.close();
}
wd.clear();
wd.draw(player);
wd.display();
}
}
main.cpp
#include <SFML/Audio.hpp>
#include <SFML/Config.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include "Engine.h"
int main()
{
sf::RenderWindow * wd = new sf::RenderWindow(sf::VideoMode(800, 600), "Lumia");
Engine * eg = new Engine(*wd);
eg->run(*wd);
return EXIT_SUCCESS;
}
如果我删除 wd.draw(player);从Engine.cpp,这个错误不会发生,好像我什么都画不了,我是在定义一个默认构造函数而不是调用它吗?还是我以错误的方式传递论点?请解释我为什么会出现这个错误并给我一个合理的解决方案,感谢您的进一步回答。
OBS:SFML 2.1、Microsoft Visual Studio 2013、i7、8gb 内存、geforce gtx850M 4gb 视频内存、Windows 8.1。
【问题讨论】: