|
-
Sep 28th, 2003, 02:14 PM
#1
Thread Starter
New Member
GetAsyncKeyState problem *resolved*
I am working on the game pong. I cannont get my paddle to move up and down. I think there is more than one problem with my code, but I know that I must be using GetAsyncKeyState incorrectly because it doesn't change the values. Here is my code.
VB Code:
Private Sub Main()
lngTick = GetTickCount
Do While blnGameLoop
lstTick = GetTickCount
If lstTick - lngTick >= 50 Then
movepaddle
BitBlt frmPong.hDC, 0, 0, Picture1.Width, Picture1.Height, Picture1.hDC, 0, 0, SRCCOPY
BitBlt frmPong.hDC, x, y, 32, 89, Picture2.hDC, 34, 0 ,SRCAND
BitBlt frmPong.hDC, x, y, 33, 89, Picture2.hDC, 0, 0, SRCPAINT
DoEvents
lngTick = GetTickCount
End If
Loop
End Sub
Private Sub movepaddle()
If (GetAsyncKeyState(vbKeyUp)) = True Then
y = y - 10
End If
If (GetAsyncKeyState(vbKeyDown)) = True Then
y = y + 10
End If
End Sub
Last edited by 0wnd; Sep 29th, 2003 at 08:42 PM.
-
Sep 28th, 2003, 07:12 PM
#2
-
Sep 28th, 2003, 07:35 PM
#3
Thread Starter
New Member
Hmm, I tried the code they had, and it doesn't work. The value of y is not changing. This is what I changed the code to.
VB Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Keys(KeyCode) = True
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Keys(KeyCode) = False
End Sub
Private Sub movepaddle()
If Keys(38) = True Then 'I also tried vbKeyUp instead of 38
y = y - 10
End If
If Keys(40) = True Then 'I also tried vbKeyDown instead of 40
y = y + 10
End If
End Sub
-
Sep 29th, 2003, 03:36 AM
#4
Do you have the KeyPreview property of your form set to true???
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|