gpt4 book ai didi

c++ - SDL 不检测箭头键

转载 作者:太空宇宙 更新时间:2023-11-04 12:25:54 25 4
gpt4 key购买 nike

我正在学习 http://lazyfoo.net/SDL_tutorials/index.php 上的 SDL 教程我一直停留在教程 8 中,我正在使用按键操作。

我正在使用以下代码:

//Our Main application loop
while(!quit){
if(SDL_PollEvent(&curEvents)){
if(curEvents.type == SDL_QUIT){
quit = true;
}

//If a key was pressed
if( curEvents.type == SDL_KEYDOWN )
{
//Set the proper message surface
switch( curEvents.key.keysym.sym )
{
case SDLK_UP:
message = upMessage;
break;
case SDLK_DOWN:
message = downMessage;
break;
case SDLK_LEFT:
message = leftMessage;
break;
case SDLK_RIGHT:
message = rightMessage; break;
default:
message = TTF_RenderText_Solid(font, "Unknown Key", textColor);
break;
}
}
}

if( message != NULL )
{
//Apply the background to the screen
applySurface( 0, 0, background, screen );

//Apply the message centered on the screen
applySurface( ( SCREEN_WIDTH - message->w ) / 2, ( SCREEN_HEIGHT - message->h ) / 2, message, screen );

//Null the surface pointer
message = NULL;
}

//Update the screen
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
}

在工作正常的地方,达到了默认情况,除了按下箭头键之外的所有内容。我想知道是否有人能发现我做错了什么。

最佳答案

我发现了上面发布的代码中没有的错误。错误是对于箭头按键消息,我在打开字体之前使用了 RenderText。到达发布的代码块时,字体已经打开,这就是显示该消息的原因。

关于c++ - SDL 不检测箭头键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2557664/

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