2011-08-23 39 views
3

轮询鼠标点击事件我的代码无法在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 
        } 
       } 
      } 
     } 
    } 
} 

这是相当多的事件结构,我从these tutorials复制。我可以得到SDL_QUIT和SDLK_ESCAPE事件,但如果我尝试做

hasquit = true 

与任mousebutton的if语句,什么都不会发生。

回答

3

你有

if(event.type == SDL_MOUSEBUTTONDOWN) 

if (event.type == SDL_KEYDOWN) 

块内。它应该是分开的。

这应该工作:

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 
       } 
      } 
     } 
    } 
} 
+0

哇,这真是令人沮丧。哦,它现在可以工作。谢谢! – ahota