Results 1 to 7 of 7

Thread: BitBlt Refresh / Game Loop suggestions

  1. #1

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    BitBlt Refresh / Game Loop suggestions

    I have an somewhat large image, refreshing repeditivly, it manages to flicker, is there any simple ways of fixing this? Thanks,
    ___
    Dan
    Last edited by MeTTa@; Aug 3rd, 2006 at 08:43 PM.

  2. #2
    Member Shadow503's Avatar
    Join Date
    Apr 2006
    Posts
    37

    Re: BitBlk Refresh

    I think you mean BitBlt, here's what I did:
    Set form1.autorefresh = true
    Now set that for all of your source images.
    Then at the end of all your BitBlt procedures (I assume your're running this in a loop) add form1.refresh

    That should remove the flicker. If not please post a zip of your project and I'll see if I can help.

  3. #3

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Re: BitBlk Refresh

    Im not one to put my game in a entire loop (which im told is a good idea), i just dont like the thought of no control of speed/time, anyways il try it.

  4. #4

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Re: BitBlk Refresh

    beautiful, thanks, but that loop think sparked my mind, anyone feel like they can explain a little about it?

  5. #5
    Member Shadow503's Avatar
    Join Date
    Apr 2006
    Posts
    37

    Re: BitBlt Refresh / Game Loop suggestions

    Sure.
    You have the program continuing to run through this loop and it calls all your subs in a certain order. Here's an example from one of my games:
    VB Code:
    1. Private Sub Timer1_Timer() 'This timer is the backbone of the whole program, it controlls all of its functions
    2. If GamePaused = True Then 'Don't run this loop if the game is paused
    3.     Exit Sub
    4. End If
    5. BitBlt Form1.hDC, 0, I, picback1.ScaleWidth, _
    6.        picback1.ScaleHeight, picback1.hDC, 0, 0, vbSrcCopy 'Draws the background
    7. I = I + 1 'This moves the background down a pixel, I have a nice scrolling background in this game
    8. BitBlt Form1.hDC, 0, J, picBack2.ScaleWidth, _
    9.        picBack2.ScaleHeight, picBack2.hDC, 0, 0, vbSrcCopy 'Draws the second frame of the background, don't bother asking
    10. J = J + 1 'Moves it back a pixel, again, don't ask why I'm doing this twice
    11. If I = 539 Then 'Just ignore this, you'd have to see my project to understand this
    12.     I = -600
    13. End If
    14. If J = 539 Then 'Ignore this too!
    15.     J = -600
    16. End If
    17. 'Ship Move 'I hardcoded the ship movement procedure in to this sub
    18. If Pause = False And GameOver = False Then
    19.     If Up = True And ShipY - ShipSpeed(ShipType) > 0 Then
    20.         ShipY = ShipY - ShipSpeed(ShipType)
    21.     End If
    22.     If Down = True And ShipY + ShipHeight + ShipSpeed(ShipType) < Form1.ScaleHeight Then
    23.         ShipY = ShipY + ShipSpeed(ShipType)
    24.     End If
    25.     If vLeft = True And ShipX - ShipSpeed(ShipType) > 0 Then
    26.         ShipX = ShipX - ShipSpeed(ShipType)
    27.     End If
    28.     If Right = True And ShipX + ShipWidth + ShipSpeed(ShipType) < 397 Then
    29.         ShipX = ShipX + ShipSpeed(ShipType)
    30.     End If
    31. End If
    32. ExplosionDrift 'Moves the explosions down a pixel
    33. AnimateGameOver 'If it is the game over this will run the game over image through it's frames (if check is located in the procedure)
    34. EnemyFire 'Enemy firing procedure
    35. RenderExplosions 'Explosion Rendering procedure
    36. RenderEnemies 'Enemy Rendering procedure
    37. MoneyDrift 'drifts the money down a pixel
    38. RenderMoney 'Renders the Money power up procedure
    39. MoveBullets 'Move Bullets procedure
    40. RenderBullets 'Render Bullets procedure
    41. If RenderShip = True Then 'Hard coded the rendering of the ship in here
    42.     BitBlt Form1.hDC, ShipX, ShipY, picshipMask(ShipType).ScaleWidth, _
    43.            picshipMask(ShipType).ScaleHeight, picshipMask(ShipType).hDC, 0, 0, vbSrcAnd 'Draw Ship
    44.     BitBlt Form1.hDC, ShipX, ShipY, picShip(ShipType).ScaleWidth, _
    45.            picShip(ShipType).ScaleHeight, picShip(ShipType).hDC, 0, 0, vbSrcPaint 'Draw Ship
    46. End If
    47. RenderGameOver 'This sub shows the game over image if the game is over (the if check is located in the sub)
    48. Form1.Refresh
    49. End Sub

    Hope this helps, ask questions if you must.

  6. #6

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Re: BitBlt Refresh / Game Loop suggestions

    Why wouldnt u get rid of the timer and put a do loop, everyone says loops are better than timers, is this true?

  7. #7
    Member Shadow503's Avatar
    Join Date
    Apr 2006
    Posts
    37

    Re: BitBlt Refresh / Game Loop suggestions

    I'm actually planning on using a do loop when I rewrite this to use API timing.

    However, for my game it was simpler to just put the code in the timer. Then I know pretty much exactly how often this code would execute. As opposed to in a Do loop the code would be executed as fast as it could, with no wait time in between executions. That would eat up resources and slow down the whole computer.

    So I just followed the KISS rule, Keep It Super Simple.

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