gpt4 book ai didi

c - SDL:定时器和 WaitEvent

转载 作者:太空宇宙 更新时间:2023-11-04 02:00:52 26 4
gpt4 key购买 nike

因此,我的游戏的主循环基于 SDL_WaitEvent 类型,它等待用户输入新字母,同时尝试发现一个随机单词。我的游戏需要这个才能正常工作,但看起来 SDL_WaitEvent 一直处于空闲状态,直到用户按下某些东西。问题是我需要我的计时器不断刷新以便玩家跟踪它,但是当游戏到达事件循环时,我的计时器保持空闲并且我无法找到一个保持刷新的方法,任何提示将不胜感激。

总结:

计时器开始:59(秒)...

它只会在我按下某些东西时刷新并显示耗时。

最佳答案

SDL_AddTimer() with a callback that uses SDL_PushEvent() to post a user message to the event queue :

/* Start the timer; the callback below will be executed after the delay */

Uint32 delay = (33 / 10) * 10; /* To round it down to the nearest 10 ms */
SDL_TimerID my_timer_id = SDL_AddTimer(delay, my_callbackfunc, my_callback_param);

...

Uint32 my_callbackfunc(Uint32 interval, void *param)
{
SDL_Event event;
SDL_UserEvent userevent;

/* In this example, our callback pushes an SDL_USEREVENT event
into the queue, and causes our callback to be called again at the
same interval: */

userevent.type = SDL_USEREVENT;
userevent.code = 0;
userevent.data1 = NULL;
userevent.data2 = NULL;

event.type = SDL_USEREVENT;
event.user = userevent;

SDL_PushEvent(&event);
return(interval);
}

关于c - SDL:定时器和 WaitEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27414548/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com