Jump to content
  • Advertisement
Sign in to follow this  
Degorath

OpenGL OpenGL Keyboard Functions

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

I'm busy writing a Bubble Bobble style game with OpenGL. The only thing is, when the character moves (lets say to the right) and you make the character jump, he stops moving. You then have to release then repress the right key. Why is this and what can I do? The character moves with the left and right directional keys (caught in glutSpecialFunc and jumps with 'z' caught in glutKeyboardFunc). Please help before I meticulously start tearing out hair.

Share this post


Link to post
Share on other sites
Advertisement
with c++ and win32 you can call:


void CheckInput()
{
if(GetKeyState(VK_UP) & 0x80 || GetKeyState('W') & 0x80) {
MovePlayerForward();
}
if(GetKeyState(VK_DOWN) & 0x80 || GetKeyState('S') & 0x80) {
MovePlayerBack();
}
if(GetKeyState(VK_LEFT) & 0x80 || GetKeyState('A') & 0x80) {
MovePlayerLeft();
}
if(GetKeyState(VK_RIGHT) & 0x80 || GetKeyState('D') & 0x80) {
MovePlayerRight();
}
}
and in your message loop
case WM_KEYDOWN:
switch(wParam)
{
case VK_SPACE:
PlayerJump();
break;
}
break;

for example...

Hope that helps:)

Share this post


Link to post
Share on other sites
I would keep an array of keys that you set/unset with key up and down events. Then in your update loop, you check the state of the keys you care about and set your motion appropriately.

You may also want to post your key handling code so people can better judge what is happening in your particular case.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!