SFML 输入系统问题
因此,我将游戏引擎从 SDL 移植到 SFML,现在我的输入系统出现了问题。 Input.h
#ifndef BULLWHIP_INPUT_H
#define BULLWHIP_INPUT_H
#include
class bc_Input
{
public:
bool bm_KeyHit(sf::Key::Code key);
bool bm_KeyDown(sf::Key::Code key);
int bm_MouseX();
int bm_MouseY();
void bm_init(sf::RenderWindow app);
private:
sf::RenderWindow App;
const sf::Input& input;
};
#endif
Input.cpp
#include "Input.h"
bool bc_Input::bm_KeyDown(sf::Key::Code key)
{
return in.IsKeyDown(key)
}
bool bc_Input::bm_KeyHit(sf::Key::Code key)
{
sf::Event event;
while(App.GetEvent(event) && event.Type == sf::Event::KeyPressed)
{
switch(event.Key.Code)
{
case key: return true; break;
default:
break;
}
}
}
void bc_Input::bm_init(sf::RenderWindow app)
{
App = app;
in = App.GetInput();
}
int bc_Input::bm_MouseX()
{
return in.GetMouseX();
}
int bc_Input::bm_MouseY()
{
return in.GetMouseY();
}
我从中得到这些错误:
C:\c++\sdl\bullwhip\lib\Bullwhip\/Input.h:15: error: 'bc_Input::App'不能出现在常量表达式中 C:\c++\sdl\bullwhip\lib\Bullwhip\/Input.h:15: 错误: '.'不能出现在常量表达式中 C:\c++\sdl\bullwhip\lib\Bullwhip\/Input.h:15: 错误:函数调用不能出现在常量表达式中 C:\c++\sdl\bullwhip\lib\Bullwhip\/Input.h:15: 错误:ISO C++ 禁止初始化成员“输入” C:\c++\sdl\bullwhip\lib\Bullwhip\/Input.h:15: 错误:使“输入”静态 C:\c++\sdl\bullwhip\lib\Bullwhip\/Input.h:15: 错误:非整数类型“sf::Input&”的静态数据成员的类内初始化无效
c:\program files (x86)\codeblocks\mingw\bin../lib/gcc/mingw32/4.4.0/../../../../include/SFML/System/NonCopyable.hpp:57 : 错误: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' 是私有的 c:\program files (x86)\codeblocks\mingw\bin../lib/gcc/mingw32/4.4.0/../../../../include/SFML/Window/Window.hpp:56 :错误:在此上下文中
So I was porting my game engine from SDL to SFML, and now I have a problem with my input system.
Input.h
#ifndef BULLWHIP_INPUT_H
#define BULLWHIP_INPUT_H
#include
class bc_Input
{
public:
bool bm_KeyHit(sf::Key::Code key);
bool bm_KeyDown(sf::Key::Code key);
int bm_MouseX();
int bm_MouseY();
void bm_init(sf::RenderWindow app);
private:
sf::RenderWindow App;
const sf::Input& input;
};
#endif
Input.cpp
#include "Input.h"
bool bc_Input::bm_KeyDown(sf::Key::Code key)
{
return in.IsKeyDown(key)
}
bool bc_Input::bm_KeyHit(sf::Key::Code key)
{
sf::Event event;
while(App.GetEvent(event) && event.Type == sf::Event::KeyPressed)
{
switch(event.Key.Code)
{
case key: return true; break;
default:
break;
}
}
}
void bc_Input::bm_init(sf::RenderWindow app)
{
App = app;
in = App.GetInput();
}
int bc_Input::bm_MouseX()
{
return in.GetMouseX();
}
int bc_Input::bm_MouseY()
{
return in.GetMouseY();
}
I get these errors from this:
C:\c++\sdl\bullwhip\lib\Bullwhip\/Input.h:15: error: 'bc_Input::App' cannot appear in a constant-expression
C:\c++\sdl\bullwhip\lib\Bullwhip\/Input.h:15: error: '.' cannot appear in a constant-expression
C:\c++\sdl\bullwhip\lib\Bullwhip\/Input.h:15: error: a function call cannot appear in a constant-expression
C:\c++\sdl\bullwhip\lib\Bullwhip\/Input.h:15: error: ISO C++ forbids initialization of member 'input'
C:\c++\sdl\bullwhip\lib\Bullwhip\/Input.h:15: error: making 'input' static
C:\c++\sdl\bullwhip\lib\Bullwhip\/Input.h:15: error: invalid in-class initialization of static data member of non-integral type 'sf::Input&'
c:\program files (x86)\codeblocks\mingw\bin../lib/gcc/mingw32/4.4.0/../../../../include/SFML/System/NonCopyable.hpp:57: error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private
c:\program files (x86)\codeblocks\mingw\bin../lib/gcc/mingw32/4.4.0/../../../../include/SFML/Window/Window.hpp:56: error: within this context
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在此处调用复制构造函数:
请注意您的错误消息之一:
为了避免此问题,您应该为 sf::Input 对象使用实际的构造函数以及初始化列表。
或者,如果您已经在更高的子系统中初始化了 sf::RenderWindow (很可能是这种情况),只需将成员变量 App 更改为引用就可以解决问题。
You're calling the copy constructor here:
Note one of your error messages:
In order to avoid this problem, you should use an actual constructor for your sf::Input object along with an initialization list.
Alternatively, if you've already initialized a sf::RenderWindow in a higher subsystem (as is likely the case), simply changing your member variable App to a reference should do the trick.