按下两个键后如何暂停sdl

时间:2018-12-31 14:04:23

标签: c sdl

我想在按键后暂停sdl。 在我的代码中,按下 ALT + G ALT + V 后,打印“暂停”重复。

bool quit = false;
SDL_Event event1;
//SDL 관련 초기화   
SDL_Init(SDL_INIT_VIDEO);
TTF_Init();
const Uint8 *keystate = SDL_GetKeyboardState(NULL);
SDL_Window *window1 = SDL_CreateWindow("window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 400, 225, 0);
SDL_Renderer * renderer = SDL_CreateRenderer(window1, -1, 0);
SDL_Color color = { 255, 255, 255 };
SDL_Surface * surface = SDL_LoadBMP("left.bmp"); // 방향표지판;
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_Rect image_dstrect = { 150, 50, 100, 100 };

SDL_SetWindowPosition(window1, 700, 150);

//Make transparency window
SDL_SetRenderDrawColor(renderer, 255, 0, 255, 255);
SDL_RenderClear(renderer);
MakeWindowTransparent(window1, RGB(255, 0, 255));
while (!quit)
{
    SDL_PollEvent(&event1);
    if (event1.window.event == SDL_WINDOWEVENT_CLOSE) {
        quit = true;
        break;
    }

    if (strcmp(data.check, "1") == 0) {
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);
        SDL_DestroyRenderer(renderer);
        renderer = SDL_CreateRenderer(window1, -1, 0);
        SDL_SetRenderDrawColor(renderer, 255, 0, 255, 255);
        SDL_RenderClear(renderer);
        surface = SDL_LoadBMP("message.bmp"); // 메세지 아이콘
        texture = SDL_CreateTextureFromSurface(renderer, surface);
        if ((keystate[SDL_SCANCODE_LALT] && keystate[SDL_SCANCODE_G]) || (keystate[SDL_SCANCODE_LALT] && keystate[SDL_SCANCODE_V])) {
            printf("puase");
        }
    }
    if (strcmp(data.check, "0") == 0) {
        SDL_DestroyTexture(texture);
        SDL_FreeSurface(surface);
        SDL_DestroyRenderer(renderer);
        renderer = SDL_CreateRenderer(window1, -1, 0);
        SDL_SetRenderDrawColor(renderer, 255, 0, 255, 255);
        SDL_RenderClear(renderer);
        surface = SDL_LoadBMP("left.bmp"); // 방향표지판
        texture = SDL_CreateTextureFromSurface(renderer, surface);
    }

    SDL_RenderCopy(renderer, texture, NULL, &image_dstrect);
    SDL_RenderPresent(renderer);
}

SDL_DestroyTexture(texture);
SDL_FreeSurface(surface);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window1);

return 0;

包括行if (strcmp(data.check, "1") == 0)
printf("puase");

我认为在按下 ALT + G ALT + V 键后,此输出显示为“ pause”一旦。 但输出为“ puasepuasepuasepuase”。 怎么了?

0 个答案:

没有答案