Bad Code, Bad Method, or Bad Choice Of Programming Language? [RESOLVED]
Hi, and thank you for attempting to help me with my problem. I'm trying to make a tile game and I made some code to load graphics from a tiled BMP. It works and all, but not always. It can load the same section of the picture over and over, but when you try to load a different section, it doesn't load it! So what do I do?
Please test it for me and help me out please!
VB Code:
Public Function LoadGraphics(FileName As String, PosX As Long, PosY As Long, Width As Long, Height As Long) As Boolean
On Error GoTo ErrHandler
Dim RetVal As Long
Dim DC As Long
Dim Image As Long
Dim NewTile As Integer
NewTile = frmMain.MapTiles.Count
Load frmMain.MapTiles(NewTile)
frmMain.MapTiles(NewTile).Visible = True
frmMain.MapTiles(NewTile).Move frmMain.MapTiles(NewTile - 1).Left + (Width * Screen.TwipsPerPixelX), frmMain.MapTiles(NewTile - 1).Top + (Height * Screen.TwipsPerPixelY), Width * Screen.TwipsPerPixelX, Height * Screen.TwipsPerPixelY
FileName = App.Path & "\Maps\" & FileName
DC = CreateCompatibleDC(frmMain.MapTiles(NewTile).hdc)
' If DC = 0 Then
' Unload frmMain.MapTiles(NewTile)
' NewTile = NewTile - 1
' MsgBox "Error Loading Tile!", , "ERROR"
' End If
Image = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
' If Image = 0 Then
' Unload frmMain.MapTiles(NewTile)
' NewTile = NewTile - 1
' MsgBox "Error Loading Tile!", , "ERROR"
' End If
SelectObject DC, Image
RetVal = BitBlt(frmMain.MapTiles(NewTile).hdc, 0, 0, Width, Height, DC, PosX, PosY, SRCCOPY)
' If RetVal = 0 Then
' LoadGraphics = False
' Unload frmMain.MapTiles(NewTile)
' NewTile = NewTile - 1
' MsgBox "Error Loading Tile!", , "ERROR"
' End If
DeleteDC DC
DeleteObject Image
LoadGraphics = True
Exit Function
ErrHandler:
MsgBox Err.Number & Err.Description
End Function