Results 1 to 11 of 11

Thread: Bad Code, Bad Method, or Bad Choice Of Programming Language? [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229

    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:
    1. Public Function LoadGraphics(FileName As String, PosX As Long, PosY As Long, Width As Long, Height As Long) As Boolean
    2.   On Error GoTo ErrHandler
    3.  
    4.   Dim RetVal As Long
    5.  
    6.   Dim DC As Long
    7.   Dim Image As Long
    8.   Dim NewTile As Integer
    9.  
    10.   NewTile = frmMain.MapTiles.Count
    11.   Load frmMain.MapTiles(NewTile)
    12.   frmMain.MapTiles(NewTile).Visible = True
    13.   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
    14.  
    15.   FileName = App.Path & "\Maps\" & FileName
    16.  
    17.   DC = CreateCompatibleDC(frmMain.MapTiles(NewTile).hdc)
    18.  
    19. '  If DC = 0 Then
    20. '    Unload frmMain.MapTiles(NewTile)
    21. '    NewTile = NewTile - 1
    22. '    MsgBox "Error Loading Tile!", , "ERROR"
    23. '  End If
    24.  
    25.   Image = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
    26.  
    27. '  If Image = 0 Then
    28. '    Unload frmMain.MapTiles(NewTile)
    29. '    NewTile = NewTile - 1
    30. '    MsgBox "Error Loading Tile!", , "ERROR"
    31. '  End If
    32.  
    33.   SelectObject DC, Image
    34.  
    35.   RetVal = BitBlt(frmMain.MapTiles(NewTile).hdc, 0, 0, Width, Height, DC, PosX, PosY, SRCCOPY)
    36. '  If RetVal = 0 Then
    37. '    LoadGraphics = False
    38. '    Unload frmMain.MapTiles(NewTile)
    39. '    NewTile = NewTile - 1
    40. '    MsgBox "Error Loading Tile!", , "ERROR"
    41. '  End If
    42.  
    43.   DeleteDC DC
    44.   DeleteObject Image
    45.  
    46.   LoadGraphics = True
    47.  
    48.   Exit Function
    49.    
    50. ErrHandler:
    51.   MsgBox Err.Number & Err.Description
    52. End Function
    Last edited by INF3RN0666; May 18th, 2003 at 03:12 PM.

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