Page 2 of 2 FirstFirst 12
Results 41 to 44 of 44

Thread: [RESOLVED] [VB6] - DIB's - Tiles an image

  1. #41
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [VB6] - DIB's - Tiles an image

    Hey long time no see

    Ill do my best to help ya since I at work on my phone. I assume this stuff is part of your graphics class.
    • If you want a tremendous boost in speed, I suggest you not use any calls to functions and subs in your main gameloop that are from a class module. The reason is cause it executes twice as slow than the same function and sub from a regular module.
    • Another thing to boost your speed are conversions. If you are storing data in a variable thats a different data type, itll execute slower. So get ready to treat vb6 as "vb.net with option strict on" taking advange of CLng, CStr, Cint, CSng, etc.
    • Also dont test your program in IDE mode. Test it as an exe. Youll notoce a huge speed boost.
    • Another way to boost speed is to try your best to avoid using / operator unless you absolutely need it. If its being stored in a long or integer variable, use \ instead.
    • Another way to boost speed is to avoid as many functions and sub calls as possible. Instead put all the code the function or sub had where the call was made. Doing this is known as Inlining, similar to adding an Inline statement prior to a function in C++. This will dramatically boost the speed of your program.
    • In your project properties, you can remove a bunch of things in your compiler options that could potentially slow your program down such as overflow checks. And never compile it to pcode. Do native code instead.
    • Error checking tremendously slows down your program. Worst of all, On Error Resume Next


    I can go on and on about optimization techniques. But this will step you in the right direction.

  2. #42

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,959

    Re: [VB6] - DIB's - Tiles an image

    Quote Originally Posted by Jacob Roman View Post
    Hey long time no see

    Ill do my best to help ya since I at work on my phone. I assume this stuff is part of your graphics class.
    • If you want a tremendous boost in speed, I suggest you not use any calls to functions and subs in your main gameloop that are from a class module. The reason is cause it executes twice as slow than the same function and sub from a regular module.
    • Another thing to boost your speed are conversions. If you are storing data in a variable thats a different data type, itll execute slower. So get ready to treat vb6 as "vb.net with option strict on" taking advange of CLng, CStr, Cint, CSng, etc.
    • Also dont test your program in IDE mode. Test it as an exe. Youll notoce a huge speed boost.
    • Another way to boost speed is to try your best to avoid using / operator unless you absolutely need it. If its being stored in a long or integer variable, use \ instead.
    • Another way to boost speed is to avoid as many functions and sub calls as possible. Instead put all the code the function or sub had where the call was made. Doing this is known as Inlining, similar to adding an Inline statement prior to a function in C++. This will dramatically boost the speed of your program.
    • In your project properties, you can remove a bunch of things in your compiler options that could potentially slow your program down such as overflow checks. And never compile it to pcode. Do native code instead.
    • Error checking tremendously slows down your program. Worst of all, On Error Resume Next


    I can go on and on about optimization techniques. But this will step you in the right direction.
    hi friend
    thanks for the tips
    Code:
    If Draw = DrawWayTiles Then
            lngTilesX = outWidth
            Do While lntTileLimitX >= lngTilesX
                BitBlt DoubleBuffer.handleDC, lngTilesX, 0, lngTilesX, outWidth, DoubleBuffer.handleDC, 0, 0, vbSrcCopy
                lngTilesX = lngTilesX * 2
                Debug.Print "original size: " & outWidth & "  Controlsize: " & lntTileLimitX & " actual position:  " & lngTilesX
            Loop
        End If
    but can you help me fix these code?
    by debug seems that i have the right positions, but the bitblt() don't draw me the image
    and i recive '1' in biblt(), that seems working... so what i miss?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #43
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [VB6] - DIB's - Tiles an image

    Well after looking at your code, I believe the if statement needs swapped just so it makes more sense:

    lngTilesX <= lntTileLimitX

    Also its better you use a For Loop rather than the Do Loop to draw out the tiles. They both practically execute the same speed. And I'm not so sure about this:

    lngTilesX = lngTilesX * 2

    Lets say you start the outwidth at 1, and your lntTileLimitX at 10. Since you are storing outwidth in lngTilesX, it now has 1. Then when you run the loop, this is whats happening to lngTilesX:

    1) 1
    2) 2
    3) 4
    4) 8
    5) 16
    6) 32
    7) 64
    8) 128
    9) 256
    10) 512

    It just doesn't make any sense because all its doing is going further and further and further away (is this what you are after?). What would make sense if you are making a tile engine is lngTilesX = lngTilesX + outwidth, assuming outwidth is the tile width. because then your values would be this, assuming the tile width is 15:

    1) 0
    2) 15
    3) 30
    4) 45
    5) 60
    6) 75
    7) 90
    8) 105
    9) 120
    10) 135

    And it would all be together. However there is a much better way of drawing tiles. I practically invented a way of doing it to where you can draw worlds as massive as you want with zero slowdown, similar to World of Warcraft or Grand Theft Auto sized worlds, only in 2D. If you need some code on how to do this, I'm more than willing to offer it to you.

    As for BitBlt, is the Double_Buffer from memory or is it a picturebox? If its a picturebox, set the AutoRedraw to True. And you made your destination of where its to be drawn is drawing in the Double_Buffer again. I don't think the source and destination should be the same DC.

  4. #44

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,959

    Re: [VB6] - DIB's - Tiles an image

    now works fine.. thanks.
    Code:
    Public Sub DrawImage(Picture As Object, Optional X As Long = 0, Optional Y As Long = 0, Optional Width As Long = 0, Optional Height As Long = 0, Optional Draw As DrawWay = DrawWayNormal)
        Dim lngTilesX As Long
        Dim lngTilesY As Long
        Dim lntTileLimitX As Long
        Dim lntTileLimitY As Long
        
        Call ChangeImage
        
        If Draw = DrawWayStretch Then
            Width = Picture.ScaleWidth
            Height = Picture.ScaleHeight
        ElseIf Draw = DrawWayNormal Then
            Width = outWidth
            Height = outHeight
        ElseIf Draw = DrawWayTiles Then
            Width = outWidth
            Height = outHeight
            lntTileLimitX = Picture.ScaleWidth
            lntTileLimitY = Picture.ScaleHeight
        End If
        
        With bi32BitInfo.bmiHeader
            .biBitCount = 32
            .biPlanes = 1
            .biSize = Len(bi32BitInfo.bmiHeader)
            .biWidth = outWidth
            .biHeight = outHeight
            .biSizeImage = 4 * outWidth * outHeight
        End With
       
        'create a DC
        Dim DoubleBuffer As DC
        
        DoubleBuffer.handleDC = CreateCompatibleDC(Picture.hdc)
        
        If Draw = DrawWayTiles Then
            DoubleBuffer.handleBMP = CreateCompatibleBitmap(Picture.hdc, Picture.ScaleWidth, Picture.ScaleHeight)
        Else
            DoubleBuffer.handleBMP = CreateCompatibleBitmap(Picture.hdc, Width, Height)
        End If
        
        DoubleBuffer.handleRefBMP = SelectObject(DoubleBuffer.handleDC, DoubleBuffer.handleBMP)
           
        
        If msMirrorState = None Then
            StretchDIBits DoubleBuffer.handleDC, 0, 0, Width, Height, 0, 0, _
                outWidth, outHeight, ChangedImage(0, 0), bi32BitInfo, 0, vbSrcCopy
        ElseIf msMirrorState = Vertical Then
            StretchDIBits DoubleBuffer.handleDC, 0, Height, Width, -Height, 0, 0, _
                outWidth, outHeight, ChangedImage(0, 0), bi32BitInfo, 0, vbSrcCopy
        ElseIf msMirrorState = Horizontal Then
            StretchDIBits DoubleBuffer.handleDC, Width, 0, -Width, Height, 0, 0, _
                outWidth, outHeight, ChangedImage(0, 0), bi32BitInfo, 0, vbSrcCopy
        ElseIf msMirrorState = HorizontalVertical Then
            StretchDIBits DoubleBuffer.handleDC, Width, Height, -Width, -Height, 0, 0, _
                outWidth, outHeight, ChangedImage(0, 0), bi32BitInfo, 0, vbSrcCopy
        End If
        
        If Draw = DrawWayTiles Then
            For lngTilesX = outWidth To lntTileLimitX
                BitBlt DoubleBuffer.handleDC, lngTilesX, 0, lngTilesX, outHeight, DoubleBuffer.handleDC, 0, 0, vbSrcCopy
                lngTilesX = (lngTilesX * 2) - 1
            Next
            
            For lngTilesY = outHeight To lntTileLimitY
                BitBlt DoubleBuffer.handleDC, 0, lngTilesY, lntTileLimitX, lngTilesY, DoubleBuffer.handleDC, 0, 0, vbSrcCopy
                lngTilesY = (lngTilesY * 2) - 1
            Next
        End If
            
        
        If blnTransparent = True Then
            If Draw = DrawWayTiles Then
                TransparentBlt Picture.hdc, X, Y, lntTileLimitX, lntTileLimitY, DoubleBuffer.handleDC, 0, 0, lntTileLimitX, lntTileLimitY, lngBackColor
            Else
                TransparentBlt Picture.hdc, X, Y, Width, Height, DoubleBuffer.handleDC, 0, 0, Width, Height, lngBackColor
            End If
        Else
            If Draw = DrawWayTiles Then
                BitBlt Picture.hdc, X, Y, lntTileLimitX, lntTileLimitY, DoubleBuffer.handleDC, 0, 0, vbSrcCopy
            Else
                BitBlt Picture.hdc, X, Y, Width, Height, DoubleBuffer.handleDC, 0, 0, vbSrcCopy
            End If
        End If
        
        'delete a DC
        DeleteObject SelectObject(DoubleBuffer.handleDC, DoubleBuffer.handleRefBMP)
        DeleteObject DoubleBuffer.handleBMP
        DeleteDC DoubleBuffer.handleDC
    End Sub
    i did several errors, but now works. the speed still not be the best. but i think i know why... i have tested and now i know that i need more speed on my FileName property. but, for now, it's cool
    thanks for all
    VB6 2D Sprite control

    To live is difficult, but we do it.

Page 2 of 2 FirstFirst 12

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