[SDL] esc detector wont run -- 'out of scope'

Clangray clangray at fastmail.com
Sat Mar 18 10:23:07 PDT 2017


Ok, I introduced a window



#include"SDL.h" 

using namespace std;



const char* WINDOW_TITLE = "SDL Start";



int main(int argc, char **argv)

{

SDL_Init(SDL_INIT_EVERYTHING);



SDL_Window * window = nullptr;

        window = SDL_CreateWindow("Hello World!",

                                  SDL_WINDOWPOS_CENTERED,

                                  SDL_WINDOWPOS_CENTERED,

                                  640,480,

                                  SDL_WINDOW_SHOWN);



        SDL_Delay(2000); // Delay so that we can see the



SDL_Event event;



cout<<"flag 0";



   bool gameRunning = true;



   while (gameRunning)

   {

   cout<<"flag 1"<<endl;

      while (SDL_PollEvent(&event))

      {

       gameRunning = false;

       cout<<"flag 2";

       if (event.type == SDL_QUIT)

          {

       cout<<"flag 3";

       gameRunning = false;

       }



         while (event.type == SDL_KEYDOWN)

         {

          cout<<"flag 2";

            SDL_Keycode keyPressed = event.key.keysym.sym;



            switch (keyPressed)

            {

               case SDLK_ESCAPE:

                  gameRunning = false;

                  break;

            }

         }



      }



   }



   SDL_Quit();



   cout<<endl<<"end flag";

   return 0;







}



I'm getting flag2 constantly.

Esc and other keys seem to have no effect



**if I substitute if for while (below)



change while back to if

if (SDL_PollEvent(&event))



output:



flag 0flag 1 

flag 2

end flag





--

  Gray Family

  clangray at fastmail.com







On Sat, Mar 18, 2017, at 12:44 PM, Brian Puthuff wrote:

> I agree also. I thought there was some caveat that you needed a window
> open to receive input events.
> 

> 

> On Mar 18, 2017 9:17 AM, "DLudwig" <dludwig at pobox.com> wrote:

>> __

>> 

>>
>>
>> capehill wrote:
>>
>>
>> Do you have a window open? Does Control-C work?
>>
>>
>> 

>> 

>> I'd like to second the above.

>> 

>>  Many platforms need a window open, before input can be received.
>>  Using either SDL_CreateWindowAndRenderer, or just SDL_CreateWindow,
>>  once beforehand at app init, may be sufficient to fix this.
>> 

>>  -- David L.

>> 

>> _______________________________________________

>>  SDL mailing list

>> SDL at lists.libsdl.org

>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

>> 

> _________________________________________________

> SDL mailing list

> SDL at lists.libsdl.org

> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20170318/bf7aaf44/attachment.htm>


More information about the SDL mailing list