KeyPress, make sure function only runs once.

Started by
5 comments, last by bitshifter 15 years, 8 months ago
Basic, i have made my FPS Engine that is taking lines as walls with a height. instead of in the game place my player within a loaded level at a corner and then write down the position for the beginning of that wall and move to the position where i want the end of the line and write that position down i want a procedure like this: move to a position and then press 'A', then within a textfile this text will be generated: planes.add(new types.cplane(new vector3(x,y,z), and then move the player to the end of the line and press 'B' then this text will be generated and then create new linespace. new vector3(x,y,z),height); so in my textfile then i have planes.add(new types.cplane(new vector3(x,y,z),new vector3(x,y,z),height)); then i can just copy that code into my app and run it, this will save me lots and lots of time. But when i just slightly press 'A' this will generate lost of lines: planes.add(new types.cplane(new vector3(x,y,z),planes.add(new types.cplane(new vector3(x,y,z),planes.add(new types.cplane(new vector3(x,y,z),planes.add(new types.cplane(new vector3(x,y,z),planes.add(new types.cplane(new vector3(x,y,z), how can i make sure that only ONE line is created when pressing A. The same problem with open door in game. Press space and if closed then open and if open the close. but when pressing space it will open and close so fast i have no control. i need some sort of delay? plz help, my game is starting to look pretty good, soon i will cope with lights and shaders etc... =)
Advertisement
You need to record the state of the button on the last frame. Then it's just a case of:
if(!buttonWasDown && buttonIsDown) // Button has become pressed
How do you handle the frames?

when moving in my scenes i don´t use frame, i only have a direction vector with a certain speed that is corrected by the collidion detection.

Quote:Original post by Meshboy
How do you handle the frames?

when moving in my scenes i don´t use frame, i only have a direction vector with a certain speed that is corrected by the collidion detection.
Well, you know the last time you checked a keypress, so just use that as the last status for the key.
okey i will try this after work, thanks for your help.
Moving to General Programming.
If you are using a Win32 WindowProc then you can just handle the WM_KEYUP msg.

This topic is closed to new replies.

Advertisement