1

I have been recently working on a game using VB.net 2008 and everything is going well.

In my game the application listen for left arrow keys to move the character to the left and listen to right arrow key to move the character to the right but if i hold down the right key and then rapidly moved up my hand on left arrow and clicked on the left key the character just stop moving for about approximately 0.75 second. This lag is making the feeling of using my application really bad. What can I do?

CODE:

Private Sub eb7chimie_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        switcher(e.KeyCode)
    End Sub
Private Sub switcher(ByVal keycode As String)

        Select Case True
            Case keycode.Equals(String.Format(Keys.Left))
                'Left Arrow
                leftarrow()
            Case keycode.Equals(String.Format(Keys.Up))
                'UpArrow
            Case keycode.Equals(String.Format(Keys.Right))
                'RightArrow
                RightArrow()
            Case keycode.Equals(String.Format(Keys.Down))
                'DownArrow
            Case keycode.Equals(String.Format(Keys.Escape))
                'Escape
                pause()
        End Select  

P.S.:

  1. This form name is eb7chimie
  2. the select case might look odd previuosly I was using a normal switch by i followed this advice: VB.NET How give best performance "Select case" or IF... ELSEIF ... ELSE... END IF

What I did try and do:

I searched for the problem and tried to turn on KeyPreview proprety of my form and tried to open and Application.DoEvents() but none worked.

Community
  • 1
  • 1
Jamil Hneini
  • 545
  • 3
  • 13
  • You are now depending on the keyboard repeat to get your game object to move. Yes, doesn't work so well, it only starts repeating after the key was held down for a while. You need a very drastic rewrite, one that uses both the KeyDown and KeyUp events. They should only set the variable that indicates the object's moving directory. And move the object yourself in your code. Google ".NET game loop" to get started. – Hans Passant Mar 28 '14 at 12:44

0 Answers0