SDL_EventState 切换

发布于 2024-10-09 03:58:43 字数 1575 浏览 0 评论 0原文

我一直在使用 SDL_EventState 来禁用和启用某些事件。然而,由于某种原因,一旦我将任何状态设置为打开或关闭,程序中的其他位置都无法更改它。为了进一步解释,这是我的循环。

void game::startLoop()
{
    while(QUIT == false)
    {
        getRoomUpdate();
        applySurface(-15, 280, zombie_lefthand, buffer);
        applySurface(455, 280, zombie_righthand, buffer);

        SDL_Flip(buffer);

        SDL_WaitEvent(&gameEvent);
        {
            switch(gameEvent.type)
            {
                case SDL_QUIT:
                QUIT = true;
                break;

                case SDL_KEYUP:
                switch(gameEvent.key.keysym.sym)
                {
                    case SDLK_LEFT:
                    if(isTwoWay == true)
                        SDL_EventState(SDL_KEYUP, 1);
                        startLoop();
                        log("Left key pressed.");
                        SDL_EventState(SDL_KEYUP, 0);

                    case SDLK_RIGHT:
                    if(isTwoWay == true)
                        SDL_EventState(SDL_KEYUP, 1);
                        startLoop();
                        log("Right key pressed.");
                        SDL_EventState(SDL_KEYUP, 0);

                    case SDLK_UP:
                    if(isTwoWay == false)
                        SDL_EventState(SDL_KEYUP, 1);
                        startLoop();
                        log("Up key pressed.");
                        SDL_EventState(SDL_KEYUP, 0);

                    default:
                    SDL_EventState(SDL_KEYUP, 0);
                }
            }
        }
    }
}

I've been using SDL_EventState as to disable and enable certain events. However for some reason once I set any state to either on or off, no where else in the program can I change it. To explain further, here is my loop.

void game::startLoop()
{
    while(QUIT == false)
    {
        getRoomUpdate();
        applySurface(-15, 280, zombie_lefthand, buffer);
        applySurface(455, 280, zombie_righthand, buffer);

        SDL_Flip(buffer);

        SDL_WaitEvent(&gameEvent);
        {
            switch(gameEvent.type)
            {
                case SDL_QUIT:
                QUIT = true;
                break;

                case SDL_KEYUP:
                switch(gameEvent.key.keysym.sym)
                {
                    case SDLK_LEFT:
                    if(isTwoWay == true)
                        SDL_EventState(SDL_KEYUP, 1);
                        startLoop();
                        log("Left key pressed.");
                        SDL_EventState(SDL_KEYUP, 0);

                    case SDLK_RIGHT:
                    if(isTwoWay == true)
                        SDL_EventState(SDL_KEYUP, 1);
                        startLoop();
                        log("Right key pressed.");
                        SDL_EventState(SDL_KEYUP, 0);

                    case SDLK_UP:
                    if(isTwoWay == false)
                        SDL_EventState(SDL_KEYUP, 1);
                        startLoop();
                        log("Up key pressed.");
                        SDL_EventState(SDL_KEYUP, 0);

                    default:
                    SDL_EventState(SDL_KEYUP, 0);
                }
            }
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋叶绚丽 2024-10-16 03:58:43

也许如果您尝试了别人的代码。
如果它有效,你可以尝试将他们的代码转换为类似你的代码(功能上)

祝你好运!
ps我认为你应该使用SDL_ENABLE和SDL_DISABLE。

Perhaps if you tried someone else's code.
If it worked you could try to transform their code to something like yours(functionally wise)

Good Luck!
p.s. I think you should use SDL_ENABLE and SDL_DISABLE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文