无法轮询 SDL 中的鼠标单击事件
我的代码
int userinput()
{
while(hasquit == false)
{
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT )
{
hasquit = true;
}
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE )
{
hasquit = true;
}
if(event.type == SDL_MOUSEBUTTONDOWN)
{
if(event.button.button == SDL_BUTTON_LEFT)
{
//do something
}
}
}
}
}
}
几乎是从这些教程复制的事件结构。我可以获得 SDL_QUIT 和 SDLK_ESCAPE 事件,但如果我尝试
hasquit = true
使用任一鼠标按钮 if 语句,则不会发生任何情况。
I have the code
int userinput()
{
while(hasquit == false)
{
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT )
{
hasquit = true;
}
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE )
{
hasquit = true;
}
if(event.type == SDL_MOUSEBUTTONDOWN)
{
if(event.button.button == SDL_BUTTON_LEFT)
{
//do something
}
}
}
}
}
}
which is pretty much an event structure I copied from these tutorials. I can get the SDL_QUIT and SDLK_ESCAPE events, but if I try to make
hasquit = true
with either of the mousebutton if statements, nothing happens.
你拥有
街区内部
。它应该是分开的。
这应该有效:
You have the
inside the
block. It should be separate.
This should work: