pressing left seems to make my block go to the right (and it doesnt stop when i let go of the key).
pressing right also makes it go to the right (but it does stop).
it also seems kind of 'sticky'
Last edited by keless on Fri Jan 02, 2004 4:36 pm, edited 1 time in total.
Thats definately wanted for the size of the array (realized sizeof() was wrong last night)..
so, it works just fine now. Which is wierd, because I would have thought any problems from not having the correct size would have meant I was accessing outside of the array.. and accessing outside of a static array should give me a crash, right? Wierd..
since this thread has been linked to as an example of proper key input handling, I will recap with the finalized code:
1) define a boolean keys array:
bool keys[irr::KEY_KEY_CODES_COUNT] ;
2) initialize it all to false:
for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++) keys[x] = false;
3) in your event handler, set the incoming key to true or false in the array:
(dont do any acting on input here, except things you want to happen immediately such as quit on ESC)
4) in your update function, act on the values in the array:
if(keys[irr::KEY_DOWN]) m_currBlob.Fall(10);
*NOTE: some people new to the engine have been sending their events to the Camera and returning that result. Then they complain that their key-handling code is never run. THATS BECAUSE THE CAMERA IS RETURNING WHETHER ITS HANDLING THE INPUT OR NOT. You have two options: put your key handling functions above camera, and if you dont handle the key, send the event to camera, or send the event to camera first, and if that returns false, then run your key handling code.
I've always used the bool key[] method in all my Win32 but for some reason with Dev-C++ it crashes (even in Debug) with the for loop. I've never seen any other method of doing keypress (that is smooth) but does anyone know of one? With using the tutorial method movement is too... jittery.
Programmer of the Irrlicht Scene Editor: Homepage - Forum Thread
Version 2 on its way!!
DarkWhoppy I used to use this method in Dev-C++ and it seemed to work just as well as in Visual C++. I would give you the code but I trashed it after switching everything over to VS 2003
Does this mean that each call to OnEvent registers only one key press or mouse action?
Is it possible to have an EventReceiver register multiple keypresses and mouse actions (simultaneously) in the one call, or would that require multiple EventReceivers - one for each potntial event type?
Or is there some way of using multiple instances of SEvent within the one EventReceiver?