我正在用C++编写游戏,使用Windows API,在开始游戏开始前有一个闪屏,并且可以暂停。为什么我的游戏暂停? (Windows C++键盘输入状态机)
我存储游戏的状态的枚举,game_state {PAUSED,PLAYING,溅射屏幕},并依靠输入的键盘来控制游戏。
游戏工作正常,已暂停和播放之间切换,但是当我试图添加一个启动画面,开始在比赛中,暂停功能停止工作,我不知道为什么......
if(Keyboard.GetKey(VK_RETURN) && game_state == SPLASHSCREEN)
{
game_state = PLAYING;
Keyboard.SetKey(VK_RETURN, false);
}
if(Keyboard.GetKey(VK_RETURN))
{
if(game_state == PAUSED)
{
game_state = PLAYING;
}
else
{
game_state = PAUSED;
}
Keyboard.SetKey(VK_RETURN, false);
}
//If Paused, go to Pause Screen
if(game_state == PAUSED)
{
pauseScreen();
}
//If Splash Screen, go to Splash Screen
if(game_state == SPLASHSCREEN)
{
splashScreen();
}
//If not paused, do game processing
if(game_state == PLAYING)
{
gamePlay();
}
如果按住键,GetKey()将返回true。 game_state是包含游戏当前状态的枚举全局。 setkey的()设置指定密钥是向下(真)或向上(假)
哦,和所有的启动画面()pauseScreen()和游戏()做的是代表各自国家(目前)显示精灵
setkey的
void Keyboard::SetKey(WPARAM key, bool key_down)
{
if(key_down)
{
m_keys[key] = true;
}
else
{
m_keys[key] = false;
}
}
信息getKey
bool Keyboard::GetKey(WPARAM key)
{
if(m_keys[key])
{
m_keys[key] = false;
return true;
}
else
{
return false;
}
}
我们可以看到GetKey和SetKey函数吗? – 2011-01-13 17:52:02
新增的setkey和信息getKey – Eilidh 2011-01-13 17:57:16