Results 1 to 11 of 11

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

  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.

  2. #2
    Addicted Member
    Join Date
    Dec 2000
    Posts
    135
    Maybe you should try and get out of your little house and do something BESIDES programming on friday night

  3. #3
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Maybe you should try helping instead of giving such wise advice...
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  4. #4
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    Originally posted by sam0010
    Maybe you should try and get out of your little house and do something BESIDES programming on friday night


    Night? What, are you in Europe?

  5. #5
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    I used to have the same problem in a similar program... Let me see if I can find it...
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229
    Commmoooon...Someone knows how to make this work!

  7. #7
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    It would have helped if you at least told me all the APIs I had to declare and what to do with the retval.

    I got it running but it does nothing so I don't know what happens. I need to see it running so I can tell and understand the algorithm.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229
    To Tec-Nico,

    I mean this in the nicest way possible but if you don't know what the BitBlt api returns, then i doubt you can help me. You're not really suppose to do anything with it other than check for errors.

    What you need to decale is the 2 functions in there, which are LoadImage, and BitBlt. Then you need to make a frmMain. Put a picture box on it with the name "MapTiles" and set its index value to 0 to create a control array. Now it should work!

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    229
    OMG...don't tell me that no1 knows how to do this. THIS IS BASIC. I know how to do it, but I can't figure out why it does the same thing over and over... Common, someone must have a slightly different version out there.

  10. #10
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    I know what Bitlt returns... And I did not need to follow your instructions to add the picturebox and the API functions... But what happens is that it won't do anything.

    If I did not know what to do I would have said which errors I had, but I simply ran it and it wouldn't do anything... First I thought it might be that the file needed to be BMP... So I changed the JPG I had (And yes, I made a new folder "Maps" in the same folder where the project is and I put the image)

    But what I meant is you should have said which the requirements were before. There is a thing called documentation and it really helps debugging. I have another version of this Tile thing... Yes, with BitBtl... But I would have to search for it.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  11. #11
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Here it is.. I found the example from where I learned to use it... Enjoy.
    Attached Files Attached Files
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

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