Jump to content
  • Advertisement
Sign in to follow this  
samanrz

Untitled

This topic is 3317 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 i've got a question on using keyboard when i have my keyboard function this way it works fine when pressing q : void keyboard (unsigned char key, int x, int y) { switch (key) { case 27: // esc -> exit exit(0); case 'q': posx++; } } but when i add another case for w as i showed below, although w works well, but i see no change in posx when i press q. void keyboard (unsigned char key, int x, int y) { switch (key) { case 27: // esc -> exit exit(0); case 'q': posx++; case 'p': posx--; } } What's wrong here ? Thanks

Share this post


Link to post
Share on other sites
Advertisement
You need a break in there:

void keyboard (unsigned char key, int x, int y)
{
switch (key)
{
case 27: // esc -> exit
exit(0);
break;

case 'q':
posx++;
break;

case 'p':
posx--;
break;
}
}

Without that, it "falls through" to the next statement. I'd also recommend having a read of This article on using your debugger, since it'll help you track down these sort of bugs.

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!