[RESOLVED] Image problems with game
Hi everyone! I'm new here and new to VB/programming. I'm currently trying to write a game, with an Image (killer - the player) and a PictureBox for the background (picBackground) when I load the game, and when none of the arrow keys are being pressed, the image gets moved behind picBackground. When I move the the player with the arrow keys, the image is re-drawn on top of the background. What I want is to have the Image drawn ontop of the picture box at all times, so any help would be appreciated.
Here is my code:
Code:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim Running As Boolean
Dim Pause As Boolean
Dim Fps As Double
Const Interval As Long = 50
Private Sub Form_Load()
Me.Show
Running = True
Main
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode < 41 Then keyarray(KeyCode) = True 'remember the key is down
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode < 41 Then keyarray(KeyCode) = False 'remember the key is up
End Sub
Private Sub Main()
Dim TempTime As Long
Dim FpsTimer As Long
While Running
If TempTime <= GetTickCount Then
TempTime = GetTickCount + Interval
While Pause
DoEvents
Wend
FpsTimer = GetTickCount - FpsTimer
Fps = 1000 / FpsTimer
Me.Caption = Fps
FpsTimer = GetTickCount
BitBlt Me.hDC, 0, 0, Me.Width, Me.Height, picBackground.hDC, BGCut, 0, vbSrcCopy
BGCut = BGCut + 8
If keyarray(37) = True Then 'when left key is held
If killer.Left > 0 Then 'if player hasn't reach left limit
killer.Left = killer.Left - 10 'move player left
End If
End If
If keyarray(39) = True Then 'when right key is held
If killer.Left < 2000 Then 'if player hasn't reach right limit
killer.Left = killer.Left + 10 'move player right
End If
End If
If keyarray(38) = True Then
If killer.Top > 0 Then
killer.Top = killer.Top - 10
End If
End If
If keyarray(40) = True Then
If killer.Top < 5500 Then
killer.Top = killer.Top + 10
End If
End If
End If
DoEvents
Wend
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Running = False
End Sub