Jump to content
  • Advertisement
Sign in to follow this  
rocktribute

Input help

This topic is 3471 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, im creating a game in Open Gl... and right now there is problem with my input function, im moving a sphere, here it is void Input( float elapsed ) { static SDL_Event event; SDL_PollEvent( &event ); if( event.type == SDL_KEYUP ) { if( event.key.keysym.sym == SDLK_ESCAPE ) g_ExitProgram = GL_TRUE; } if( event.type == SDL_KEYDOWN ) { if( event.key.keysym.sym == SDLK_RIGHT ) spherePos.x += 20.0f * elapsed; if( event.key.keysym.sym == SDLK_LEFT ) spherePos.x -= 20.0f * elapsed; if( event.key.keysym.sym == SDLK_UP ) spherePos.z -= 20.0f * elapsed; if( event.key.keysym.sym == SDLK_DOWN ) spherePos.z += 20.0f * elapsed; } memset( &event, 0, sizeof(SDL_Event) ); } +++++++++++++++ I want to be able to move in a diagonal way, i mean be able to press the key UP and DOWN at the same time with any problem, thank you all

Share this post


Link to post
Share on other sites
Advertisement
Try making state variables to keep track of the keys. Something like this:



bool isKeyUpPressed;

while(SDL_PollEvent(&event))
{
if(event.type == SDL_KEYDOWN)
{
if(event.key.keysym.sym == SDLK_UP)
{
isKeyUpPressed = true;
}
}
if(event.type == SDL_KEYUP)
{
if(event.key.keysym.sym == SDLK_UP)
{
isKeyUpPressed = false;
}
}
doSomething();
}



Something like that. Then in the doSomething function, check if the state of each key is true, and if it is, do what you want it to do.

That's my suggestion.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!