Jump to content
  • Advertisement
Sign in to follow this  
Daggerbot

About menu systems and input...

This topic is 3600 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

Would it be more practical to handle keyboard presses in the form of events, or just get the state of a given key and have a value containing the previous state in a menu system? For example:
void run()
{
  if( input->getKey( keyMap.up ))
    if( !lastStateUp )
      moveUp();

  if( input->getKey( keyMap.down ))
    if( !lastStateDown )
      moveDown();
}


...or...
void init()
{
  input->addKeyListener( this );
}

void keyPressed( Input* input, int key )
{
  if( key == keyMap.up )
    moveUp();
  else if( key == keyMap.down )
    moveDown();
}
I hope I was clear enough on my question. Any help is appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Personally, I'd take the former since it is simpler. Just a straightforward function that saves old kb state, gets new kb state, then processes keys should be fine. I don't think it makes a huge difference either way though.

Share this post


Link to post
Share on other sites
I like to use both; I use the former for movement and such and I use the ladder so I don't have to keep track of lastStateDown.

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!