How to detect no buttons being depressed
Blitz3D Forums/Blitz3D Beginners Area/How to detect no buttons being depressed
| ||
I am using Blitz3D I am using the keypad to move a figure around a platform game, but need to detect when there is no keypress, so's I can use a "standing still" sprite. Souns simple but can't seem to figure it out. Thanks Dicon |
| ||
What I do is before checking what direction key is being pressed, set the direction to 0 (standing). If after checking all direction keys, if the direction is still 0, then your character is standing. [bbcode]Graphics 800,600 SetBuffer BackBuffer() Positionx = 400 positiony = 300 While Not KeyHit(1) Directionx = 0 ;set the direction to 0 Directiony = 0 ;check for up If KeyDown(200) Directiony = -1 EndIf ;check for down If KeyDown(208) Directiony = 1 EndIf ;check for left If KeyDown(203) Directionx = -1 EndIf ;check for right If KeyDown(205) Directionx = 1 EndIf ;set the color to red if still, blue if moving If Directionx = 0 And Directiony = 0 Color 255,0,0 Else Color 0,255,0 EndIf ;update position Positionx = Positionx + Directionx Positiony = Positiony + Directiony ;draw rectangle Cls Rect Positionx-10,Positiony-10,20,20 Flip Wend[/bbcode] |