我正在像在 win32 GDI 中一样创建游戏马里奥。我已经为游戏实现了新的循环:
PeekMessage(&msg,NULL,0,0,PM_NOREMOVE);
while (msg.message!=WM_QUIT)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else // No message to do
{
gGameMain->GameLoop();
}
}
但我的游戏一直在运行,直到我按下 Ctrl + Alt + Del(鼠标光标滚动)。
最佳答案
我一直在使用类似的东西:
MSG msg;
while (running){
if (PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
try{
onIdle();
}
catch(std::exception& e){
onError(e.what());
close();
}
}
onIdle 是实际的游戏 lopp 实现,onError() 是错误处理程序(将错误描述作为参数),“running”是全局 bool 变量或类成员。将“running”设置为 false 会关闭游戏。
关于c++ - Win32 API 中的游戏循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2817139/