I am making my first 'real' video game (back buffer, sound, etc.) and have come acrossed a very weird bug. When the game loads the first thing it does is to create the back buffer and then blit the background picture to it (the background always appears), the it does the same for 3 sprites. Once the game gets going tho (againonly on my machine it seems) sometimes a sprite will be invisible (it still intereacts with everything but its just not visibley there). I think the problem is in this code:
'Load ball image into the back buffer and create the ball object
Set csBall = New clsSprite
csBall.Transparent = True
If Not csBall.LoadFrames(App.Path & "\Ball.bmp", 0, 0, 26, 26, 1) Then
MsgBox "Error loading Ball image.", vbOKOnly, "Error" 'This isnt called even when I cant see the ball
Shutdown
End If
csBall.X = (Picture1.Width / 2) - (csBall.Width / 2)
csBall.Y = ((Picture1.Height + COMP) / 2) - (csBall.Height / 2) - 3
Public Function LoadFrames(ByVal sFilename As String, _
ByVal lStartX As Long, ByVal lStartY As Long, _
ByVal lWidth As Long, ByVal lHeight As Long, _
ByVal lNumFrames As Long, _
Optional bGenMasks As Boolean = True) As Boolean
On Error GoTo errorout
Dim cbSource As New clsBitmap
Dim lFrame As Long
Dim lCopyX As Long
Dim lCopyY As Long
Dim bFailed As Boolean
LoadFrames = False
'load the source bitmap file
If Not cbSource.Load(sFilename) Then Exit Function
'copy each frame out of the source image
For lFrame = 0 To lNumFrames - 1
'calculate the upper left corner
'lCopyX = lStartX + lFrame * (lWidth + 1)
lCopyX = lStartX + lFrame * lWidth
lCopyY = lStartY
'set the current frame
lCurrentFrame = lFrameCount + lFrame
'redimension the bitmap array to hold the new frame
ReDim Preserve cbFrames(0 To lCurrentFrame)
'instantiate the new sprite frame
Set cbFrames(lCurrentFrame) = New clsBitmap
'create the bitmap image based on sprite dimensions
If Not cbFrames(lCurrentFrame).Create(cbSource.hdc, _
lWidth, lHeight) Then
LoadFrames = False
Exit For
End If
'transfer frame from source image to sprite array
If BitBlt(cbFrames(lCurrentFrame).hdc, 0, 0, _
lWidth, lHeight, cbSource.hdc, lCopyX, lCopyY, _
vbSrcCopy) = 0 Then
LoadFrames = False
Exit For
End If
Next lFrame
'increment the frame count
lFrameCount = lFrameCount + lNumFrames
'generate masks
If bGenMasks Then
'only gen masks if hardware support is false
If Not HardwareTransparency Then
If Not GenerateAllMasks() Then Exit Function
End If
End If
'successful operation
Set cbSource = Nothing
LoadFrames = True
Exit Function
errorout:
End Function
my OS : XP Pro SP1 & graphics card: NVIDIA GEFORCE2 MX Version: 3.11.01.30.99
the thing i dont get is that sometimes it loads like a ball and one paddle, other times just a ball, none at all, or all 3 (yes the game is similar to pong). y would such a sporadic behavior exist? im so lost...
Enter your message below
Sign in or Join us (it's free).