Results 1 to 8 of 8

Thread: Animati0n over BG, going reaLLy slow

  1. #1

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720

    Animati0n over BG, going reaLLy slow

    I have a bitmap being animated over a background (bmp). But it goes really slow. I included the code, can someone please check for anything that can be causing it to go sLow (I think its in the bLitter sub)

    VB Code:
    1. Option Explicit
    2.     Private Type AnimationFrame
    3.         Top As Long
    4.         Left As Long
    5.     End Type
    6.  
    7.     Dim DX As New DirectX7  'dEclare DX7 object, dont forget the 'new'
    8.     Dim DD As DirectDraw7
    9.  
    10.     Dim PrimarySurface As DirectDrawSurface7 'The main surface user sEEs
    11.     Dim PrimeDesc As DDSURFACEDESC2
    12.  
    13.     Dim OSPbackGround As DirectDrawSurface7   'OffscreenPlain background
    14.     Dim BackDesc As DDSURFACEDESC2
    15.  
    16.     Dim OSPsprite As DirectDrawSurface7       'OffscreenpLain sprite
    17.     Dim SpriteDesc As DDSURFACEDESC2
    18.  
    19.     Dim Clippa As DirectDrawClipper
    20.  
    21.     Dim rPrime As RECT
    22.     Dim rBG As RECT
    23.     Dim rSprite As RECT
    24.  
    25.     Dim Frame(3) As AnimationFrame
    26.     Dim curFrame As Long
    27.     Dim GoGoGo As Boolean
    28.     Dim ReturnValue As Long
    29.     Dim Temp As Long
    30.  
    31.     Dim bBLT As Boolean     'tells whether to animaTe or not
    32.     Dim bINT As Boolean     'True if init is succesfuLL
    33.  
    34. Private Sub Form_Load()
    35.     Me.Height = 5000     'Set form height and width
    36.     Me.Width = 5000      'tHats the kid -_-
    37.    
    38.     Init_DX_Stuff        'call this sub to set all variabLes/obj
    39.    
    40.     Do While bBLT = True 'Loop while bBLT is true,
    41.         DoEvents
    42.         BitBlitter       'This is the main loop, that will animate
    43.         DoEvents
    44.     Loop
    45. End Sub
    46.  
    47. Private Sub Init_DX_Stuff()
    48.     'DX objects-
    49.         Set DD = DX.DirectDrawCreate("")
    50.         Call DD.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)
    51.    
    52.     'Primary----
    53.         PrimeDesc.lFlags = DDSD_CAPS
    54.         PrimeDesc.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
    55.         Set PrimarySurface = DD.CreateSurface(PrimeDesc)
    56.        
    57.     'Background--
    58.         BackDesc.lFlags = DDSD_CAPS
    59.         BackDesc.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
    60.         Set OSPbackGround = DD.CreateSurfaceFromFile(App.Path & "\bg.bmp", BackDesc)
    61.        
    62.     'Sprite------
    63.         SpriteDesc.lFlags = DDSD_CAPS
    64.         SpriteDesc.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
    65.         Set OSPsprite = DD.CreateSurfaceFromFile(App.Path & "\sprite.bmp", SpriteDesc)
    66.        
    67.     'kLipper-----
    68.         Set Clippa = DD.CreateClipper(0)
    69.         Clippa.SetHWnd Me.hWnd
    70.         PrimarySurface.SetClipper Clippa
    71.        
    72.     'CreateTable-
    73.         LookUpTable
    74.        
    75.     'variabLes---
    76.         bINT = True
    77.         bBLT = True
    78.         GoGoGo = True
    79.         Form1.Show
    80. End Sub
    81.  
    82. Private Sub BitBlitter()
    83.     'Check------
    84.         If bINT = False Then Exit Sub
    85.  
    86.     'RectangLes-
    87.         Call DX.GetWindowRect(Me.hWnd, rPrime)
    88.        
    89.         rSprite.Top = Frame(curFrame).Top
    90.         rSprite.Left = Frame(curFrame).Left
    91.         rSprite.Right = rSprite.Left + 36
    92.         rSprite.Bottom = rSprite.Top + 62
    93.        
    94.         rBG.Bottom = BackDesc.lHeight
    95.         rBG.Right = BackDesc.lWidth
    96.         'rBG.Left = BackDesc.lWidth
    97.         'rBG.Top = BackDesc.lHeight
    98.        
    99.     'AnimatioN
    100.         If DX.TickCount >= Temp + 1000 / 30 Then 'Check to see if Xmilliseconds passed or not
    101.             Temp = DX.TickCount
    102.             If GoGoGo = True Then
    103.                 curFrame = curFrame + 1
    104.                 If curFrame > UBound(Frame) Then
    105.                     curFrame = UBound(Frame)
    106.                     GoGoGo = False
    107.                 End If
    108.             Else
    109.                 curFrame = curFrame - 1
    110.                 If curFrame < LBound(Frame) Then
    111.                     curFrame = LBound(Frame)
    112.                     GoGoGo = True
    113.                 End If
    114.             End If
    115.         End If
    116.        
    117.     'BlitterIt--
    118.         ReturnValue = OSPbackGround.BltFast(150, 150, OSPsprite, rSprite, DDBLTFAST_WAIT)
    119.         ReturnValue = PrimarySurface.Blt(rPrime, OSPbackGround, rBG, DDBLT_WAIT)
    120. End Sub
    121.  
    122. Private Sub LookUpTable()
    123.     Frame(0).Left = 0
    124.     Frame(1).Left = 35
    125.     Frame(2).Left = 70
    126.     Frame(3).Left = 105
    127. End Sub
    128.  
    129. Private Sub Form_Unload(Cancel As Integer)
    130.     bBLT = False
    131.     Unload Me
    132. End Sub
    asdf

  2. #2

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    CAn someone please check this for me, the bLT sub at least, I dont know whats wrong, I tried a smaller BMP file but it didnt work, both of these are 24bit.. i tried it with a loop at 1secodn interval.. and doEvents all over the place, no luck.
    asdf

  3. #3

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720

    ~

    Here, I uploaded the project, can anyone *pleasE* help so I can move on.

    http://wordbirdturd.tripod.com/Animation_overa_BG.zip

    Paste the URL in IE.
    asdf

  4. #4

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    Ok ok, I added "Or DDSCAPS_SYSTEMMEMORY" to the background buffer and now its really fast but it flickers a little, how would I fix that? The animation is really smooth now tho, what does that line do?
    asdf

  5. #5
    Addicted Member Sonikku`'s Avatar
    Join Date
    Oct 2002
    Location
    NyC~
    Posts
    165

    LinE

    OlD:
    That line makes your App use System Memory(RaM), over Video Memory(Video Card). Which usually has more memory available and is alot faster. Check your frame(s). I used to have the frame flickering problem only because I set the frame to a totally white part of the bMP. Other then that you could be doing something wrong. Post the whole thing and I can see.
    oK, I remembered how I fixed this when it happened to me. Somewhere between your frame timing and the actual blt'inG your doing something. This is what causes the flickering, maybe you have a DoEvents somewhere, thats what caused the flickering for me. Reorganize the code so it BLT right after the frame timing. This is most likely whats causing it

    VB Code:
    1. Do While bBLT = True 'Loop while bBLT is true,
    2.         DoEvents
    3.         BitBlitter       'This is the main loop, that will animate
    4.         DoEvents
    Remove the DoEvents before BitBlitter keep the one after that should fix it
    Last edited by Sonikku`; Mar 19th, 2003 at 12:34 AM.
    Sonikku`- First Days of VB
    [vbcode]
    Dim Text1.Text as String
    [/vbcode]
    <Sonikku`> Whats wrong with this code, i keep getting an error about reserved keyword?
    <od`Sinchro> LOL!
    <Sonikku`> ?

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    It depends. If your CPU is the bottleneck (which it usually is), use Video Memory. If your graphics card is the bottleneck, use System Memory. However, it's more of a bottleneck in terms of memory speed.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    I do not think my videocard/CPU are bottlenecks, I think its somewhere in the software, because Sonikku's examples don't run so slow. uMm, I will remove that dOEvents when I get home. ThanKs.

    Sonikku`, "Last edited by Sonikku` on 03-19-2003 at 05:34 AM" why didn't you go to school?
    asdf

  8. #8
    Addicted Member Sonikku`'s Avatar
    Join Date
    Oct 2002
    Location
    NyC~
    Posts
    165

    UM

    I tried your example on my pC and others, no flickering problem watsoever. Maybe theres something wrong with your hardware or software?
    Sonikku`- First Days of VB
    [vbcode]
    Dim Text1.Text as String
    [/vbcode]
    <Sonikku`> Whats wrong with this code, i keep getting an error about reserved keyword?
    <od`Sinchro> LOL!
    <Sonikku`> ?

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