Event capture, need help

Ok I posted earlier that I was getting a seg fault. I have since fixed it, but
now, I can only do events if I hold the key for 1 sec or more.

/**** My event function made simple *****/
int key_events()
{
Uint8 *keys;
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
keys = SDL_GetKeyState(NULL);

       if ( keys[SDLK_ESCAPE] )
            {
              exit(1);
            }

}
}

/****** The animal movement loop *******/
void scen_1()
{
for(x=1;x<=110;x=x+5)SDL_Delay(100), blit_background(),
blit_deer(x,420), key_events();

 SDL_Delay(2000);

}

/**** Then main *****?
int main()
{
srand(time(NULL));
initialize();
load_images();
setcolormap();
blit_background();
blit_toolbar();
trans_image();
which_scen();
exit(1);
}

I know my code might me ancient, but It’s my first game. I’m learning every
day. Thanks in advance…

Doing thing in this way, you can block the game as there all always
can be new events. Do it in a for instead.

Take a look at Arianne ( http://www.arianne.cx ) The file is called
Input.cpp
I have done this in two functions, one get events and the other test
the keys.

If it doesn’t help you or you don’t understand it feel free to write
again.

This is also my first big development.
BTW By pressing in the banner of the main screen you help me to
mantain the cost of the development.

Miguel.

Quoting “Tony M.” :

Ok I posted earlier that I was getting a seg fault. I have since
fixed it,
but
now, I can only do events if I hold the key for 1 sec or more.

/**** My event function made simple *****/
int key_events()
{
Uint8 *keys;
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
keys = SDL_GetKeyState(NULL);

       if ( keys[SDLK_ESCAPE] )
            {
              exit(1);
            }

}
}

/****** The animal movement loop *******/
void scen_1()
{
for(x=1;x<=110;x=x+5)SDL_Delay(100), blit_background(),
blit_deer(x,420), key_events();

 SDL_Delay(2000);

}

/**** Then main *****?
int main()
{
srand(time(NULL));
initialize();
load_images();
setcolormap();
blit_background();
blit_toolbar();
trans_image();
which_scen();
exit(1);
}

I know my code might me ancient, but It’s my first game. I’m
learning> every
day. Thanks in advance…

Ok I posted earlier that I was getting a seg fault. I have since fixed it, but
now, I can only do events if I hold the key for 1 sec or more.

/****** The animal movement loop *******/
void scen_1()
{
for(x=1;x<=110;x=x+5)SDL_Delay(100), blit_background(),
blit_deer(x,420), key_events();

 SDL_Delay(2000);

}

Well, you’re sleeping for 2 seconds here, so that may be your problem. :slight_smile:

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

The sleep only occurs after “x” has reached 110,
there’s only a 100th of a second delay actually.
How do I include the event catch in the program and
make it watch all the time regardless of it moving
soemthing on the screen?

— Sam Lantinga wrote:

Ok I posted earlier that I was getting a seg
fault. I have since fixed it, but
now, I can only do events if I hold the key for 1
sec or more.

/****** The animal movement loop *******/
void scen_1()
{
for(x=1;x<=110;x=x+5)SDL_Delay(100),
blit_background(),
blit_deer(x,420), key_events();

 SDL_Delay(2000);

}

Well, you’re sleeping for 2 seconds here, so that
may be your problem. :slight_smile:

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment
Software__________________________________________________
Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger.
http://im.yahoo.com/

Ok I posted earlier that I was getting a seg fault. I have since fixed it, but
now, I can only do events if I hold the key for 1 sec or more.

/**** My event function made simple *****/
int key_events()
{
Uint8 *keys;
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
keys = SDL_GetKeyState(NULL);

       if ( keys[SDLK_ESCAPE] )
            {
              exit(1);
            }

}
}

That while loop is really, really tight. I’d have it do a delay of something
like a 100th of a second:

SDL_Delay(10);

-bill!