Key releasing

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
CyberP1708
Posts: 10
Joined: Sat Feb 19, 2005 6:37 pm

Key releasing

Post by CyberP1708 »

I'm using this code :

Code: Select all

if (event.KeyInput.PressedDown)
  getMainCharacter()->Move();
else
  getMainCharacter()->Stop();
The main character should move when you stay on the key and stop when you release the key but it doesn't work and as there are no "isKeyPressed" function or something like that, I don't know how to do
metalseb
Posts: 15
Joined: Tue Mar 01, 2005 8:50 am
Location: Lille - France
Contact:

Post by metalseb »

You should use an array reflecting the state of each key. There is a FAQ entry for this :

Alternative Input For Keys | Describes how to handle an alternative method of input retrieval that is more accurate | http://irrlicht.sourceforge.net/phpBB2/ ... .php?t=808
CyberP1708
Posts: 10
Joined: Sat Feb 19, 2005 6:37 pm

Post by CyberP1708 »

Your method uses event.KeyInput.PressedDown just like mine
It still doesn't work as event.KeyInput.PressedDown seems to be always true (so I can't detect if the user stopped pressing a key)
Quall
Posts: 154
Joined: Mon Mar 07, 2005 10:16 pm

Post by Quall »

You have to define a key to be pressed. Something like this:

Code: Select all

if (event.KeyInput.PressedDown)
     {
     if(event.KeyInput.Key==KEY_UP)
          getMainCharacter()->Move();  
     }
else
     getMainCharacter()->Stop();

I would suggest you do what metalseb said though, is better for movement. Although, the animation might keep repeating the first frame over and over. I think that was a problem I came across.
Post Reply