I want that when I’m pressing a key , the sprites moves even I don’t press.
I have a sprite moving in the screen but I have to be pressing the same key
many times to walk.
void Teclado(void)
{
SDL_Event evento;
if (SDL_PollEvent(&evento))
{
if (evento.type == SDL_KEYDOWN)
{
switch (evento.key.keysym.sym)
{
case SDLK_UP: posy=posy-10 ; orientacion=norte; break;
case SDLK_DOWN: posy=posy+10 ; orientacion= sur; break;
case SDLK_LEFT: posx=posx-10 ; orientacion=oeste; break;
case SDLK_RIGHT: posx=posx+10 ; orientacion=este; break;
case SDLK_ESCAPE: encendido=false ; break;
}
}
}
return ;
}
Basically, you have to watch the SDL_KEYUP event, so you know when the key
is not being pressed.
SDL events occurs only once (SDL_KEYUP, SDL_KEYDOWN, etc), so when you have
an SDL_KEYUP, you know that the key was pressed and now it is released.
Take a look here:
http://gpwiki.org/index.php/SDL:Tutorials:Practical_Keyboard_Input
Leonardo.
2008/11/16 Carlitox > I want that when I’m pressing a key , the sprites moves even I don’t press.
I have a sprite moving in the screen but I have to be pressing the same key
many times to walk.
void Teclado(void)
{
SDL_Event evento;
if (SDL_PollEvent(&evento))
{
if (evento.type == SDL_KEYDOWN)
{
switch (evento.key.keysym.sym)
{
case SDLK_UP: posy=posy-10 ; orientacion=norte; break;
case SDLK_DOWN: posy=posy+10 ; orientacion= sur; break;
case SDLK_LEFT: posx=posx-10 ; orientacion=oeste; break;
case SDLK_RIGHT: posx=posx+10 ; orientacion=este; break;
case SDLK_ESCAPE: encendido=false ; break;
}
}
}
return ;
}
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Or you can use SDL_GetKeyState
Regards
Vinicius Jarina
viniciusjarina.googlepages.comOn Mon, Nov 17, 2008 at 9:10 AM, Leonardo Guilherme < leonardo.guilherme at gmail.com> wrote:
Basically, you have to watch the SDL_KEYUP event, so you know when the key
is not being pressed.
SDL events occurs only once (SDL_KEYUP, SDL_KEYDOWN, etc), so when you have
an SDL_KEYUP, you know that the key was pressed and now it is released.
Take a look here:
http://gpwiki.org/index.php/SDL:Tutorials:Practical_Keyboard_Input
Leonardo.
2008/11/16 Carlitox
I want that when I’m pressing a key , the sprites moves even I don’t press.
I have a sprite moving in the screen but I have to be pressing the same
key
many times to walk.
void Teclado(void)
{
SDL_Event evento;
if (SDL_PollEvent(&evento))
{
if (evento.type == SDL_KEYDOWN)
{
switch (evento.key.keysym.sym)
{
case SDLK_UP: posy=posy-10 ; orientacion=norte; break;
case SDLK_DOWN: posy=posy+10 ; orientacion= sur; break;
case SDLK_LEFT: posx=posx-10 ; orientacion=oeste; break;
case SDLK_RIGHT: posx=posx+10 ; orientacion=este; break;
case SDLK_ESCAPE: encendido=false ; break;
}
}
}
return ;
}
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
Hello !
I want that when I’m pressing a key , the sprites moves even I don’t press.
I have a sprite moving in the screen but I have to be pressing the same key
many times to walk.
A way to solve this is to define a boolean for every
direction :
bool up = false;
bool down = false;
bool left = false;
bool right = false;
Then when you get a KeyDown Event for as
an example the up key, then you set up = true
and when you get a KeyUp Event for the up Key
you set up = false
Now in your gameloop you ask okay is up == true
then move the sprite in the up direction.
CU
Basically, you have to watch the SDL_KEYUP event, so you know when the key
is not being pressed.
SDL events occurs only once (SDL_KEYUP, SDL_KEYDOWN, etc), so when you have
an SDL_KEYUP, you know that the key was pressed and now it is released.
Yet another way would be to enable SDL_EnableKeyRepeat.On Mon, Nov 17, 2008 at 6:10 AM, Leonardo Guilherme <leonardo.guilherme at gmail.com> wrote:
–
http://pphaneuf.livejournal.com/
Basically, you have to watch the SDL_KEYUP event, so you know when
the key
is not being pressed.
SDL events occurs only once (SDL_KEYUP, SDL_KEYDOWN, etc), so when
you have
an SDL_KEYUP, you know that the key was pressed and now it is
released.
Yet another way would be to enable SDL_EnableKeyRepeat.
In my experience, key repeat produces very not-smooth animations when
you use it to perform continuous movement. I use the boolean method.
– ScottOn Nov 17, 2008, at 8:21 AM, Pierre Phaneuf wrote:
On Mon, Nov 17, 2008 at 6:10 AM, Leonardo Guilherme <leonardo.guilherme at gmail.com> wrote: