VB.net - while keydown

Discussion in 'Programming' started by Silver89, Jun 27, 2009.

  1. #1
    Hey,

    I'm trying to create my first sort of VB.net game after learning it for a few months, I can do games in flash/actionscript but picking up the movement techniques in VB.net is proving slightly more complex with items such as velocity as physics?

    One such problem I'm having is how to do movement on holding a key, I'm trying to get the item to move accross the screen while the right arrow is held down on the keyboard, I can get the character to move one space per right key press but guess I need a while(keypress).

    Do you know how this can be done or am I using the wrong approach?

    Thanks,
    -Dan
     
    Silver89, Jun 27, 2009 IP
  2. brian65

    brian65 Active Member

    Messages:
    1,172
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    88
    #2
    Hi Dan,
    I guess you're handling the KeyDown event at the moment to know that the key is pressed. Could you set a flag to indicate the key is down then repeatedly fire a timer. When the timer fires, if your keydown flag is set, do the move. When a KeyUp event is handled for the key, clear the flag so your timer stops the move.
     
    brian65, Jun 29, 2009 IP