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

speartip clangray at fastmail.com
Fri Mar 17 15:41:16 PDT 2017


Thanks! That fixed it so it will compile. No more errors. The code still doesn't do what it is supposed to: abort when you press esc. I flagged it up. It never gets passed flag 1. 


Code:

#include<iostream>
#include"SDL.h"
using namespace std;

const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;
const char* WINDOW_TITLE = "SDL Start";

int main(int argc, char **argv)
{ cout<<"flag 0";
   SDL_Init( SDL_INIT_VIDEO );

   SDL_Event event;

   bool gameRunning = true;

   while (gameRunning)
   {
	   cout<<"flag 1"<<endl;
      if (SDL_PollEvent(&event))
      {
    	  cout<<"flag 2";
         if (event.type == SDL_QUIT)
         {
            cout<<"flag 3";
        	 gameRunning = false;
         }

         if (event.type == SDL_KEYDOWN)
         {

            SDL_Keycode keyPressed = event.key.keysym.sym;

            switch (keyPressed)
            {
               case SDLK_ESCAPE:
                  gameRunning = false;
                  break;
            }
         }

      }

   }

   SDL_Quit();

   cout<<endl<<"end flag";
   return 0;



}







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


More information about the SDL mailing list