在Win32 API中的游戏循环 [英] Game loop in Win32 API
本文介绍了在Win32 API中的游戏循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在win32 GDI中创建游戏马里奥。我已经实现了游戏的新循环:
I'm creating game mario like in win32 GDI . I've implemented the new loop for game :
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(鼠标光标滚动)。
But my game just running until I press Ctrl + Alt + Del ( mouse cursor is rolling ).
推荐答案
我一直使用类似的东西:
I've always been using something like that:
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会关闭游戏。
onIdle is actual game lopp implementation, onError() is an error handler (takes error description as argument), and "running" is either a global bool variable or a class member. Setting "running" to false shuts down the game.
这篇关于在Win32 API中的游戏循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文