Results 1 to 4 of 4

Thread: Keydown problem - Help!!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    16

    Keydown problem - Help!!

    I have beenn pulling my hair out all night about this. Ok. I'm making a PacMan game using BitBlt. Here's my code for the form thats the problem:

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case vbKeyLeft
    MLeft
    Case vbKeyRight
    MRight
    Case vbKeyUp
    MUp
    Case vbKeyDown
    MDown
    End Select
    End Sub
    
    Sub Render()
    'blit it on the buffer, mask first
    BitBlt BackBuffer.hDC, PacMan2.x, PacMan2.y, 56, 58, SpriteMask.hDC, 0, 0, vbMergePaint
    BitBlt BackBuffer.hDC, PacMan2.x, PacMan2.y, 56, 58, Sprite.hDC, 0, 0, vbSrcAnd
    End Sub
    
    Private Sub Form_Load()
    'Show the form
    Show
    
    Draw
    MainLoop
    End Sub
    
    Sub Draw()
    'Set where the pacman starts
    PacMan2.x = 40
    PacMan2.y = 40
    End Sub
    
    Sub MainLoop()
    Do
    DoEvents
    BackBuffer.Cls
    
    Render
    Loop
    End Sub
    
    Sub MDown()
    PacMan2.y = PacMan2.y + 15
    End Sub
    
    Sub MUp()
    PacMan2.y = PacMan2.y - 15
    End Sub
    
    Sub MLeft()
    PacMan2.x = PacMan2.x + 15
    End Sub
    
    Sub MRight()
    PacMan2.x = PacMan2.x - 15
    End Sub
    As you can see, when you press up, the sprite moves up, etc.

    HOWEVER, nothing happens when I do. Even if I type the wrong thing, for example: MUp22 (which is not a Sub or anything), I dont get an error message, meaning that the program isnt responding to the key at all, none of them actually.

    What am i doing wrong? thanks in advance.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Keydown problem - Help!!

    Is the KeyPreview property of the Form set to True?

  3. #3
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    The Netherlands
    Posts
    386

    Re: Keydown problem - Help!!

    Also, I don't see you refreshing the form either

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Keydown problem - Help!!

    Quote Originally Posted by Venom555
    Also, I don't see you refreshing the form either
    Well the code he posted is not using any continious loop or anything so the Form will refresh itself since most of the time none of the code will run at all.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width