在 Allegro 5 中编写游戏循环的最佳方法是什么,它总是以相同的速度运行,并且正确地将绘图逻辑与更新逻辑分开?我应该使用线程吗?我应该使用新的 Allegro 事件系统吗?
最佳答案
取自快板维基:
al_install_timer(1.0 / FPS);
...
while (1) {
al_wait_for_event(queue, &event);
/* handle input events */
if (event.type == ALLEGRO_EVENT_TIMER) {
handle_game_tick();
need_redraw = true;
}
if (need_redraw && al_event_queue_is_empty(queue)) {
render_last_frame();
need_redraw = false;
}
}
如果您想要跳帧,请在检测到帧落后时跳过 render_last_frame() 命令(例如,通过使用 al_current_time() 函数)。
关于c - 快板5游戏: game loop that runs at constant speed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1212046/