Results 1 to 13 of 13

Thread: I Got A Nasty Flicker

  1. #1
    NOMADMAN
    Guest

    I Got A Nasty Flicker

    I still make games by bitblt. How can I control the flicker? Seems if I use a desent refresh rate I start going into epileptic shock. I usually set the forms autoredraw = false else I don't see anything. I do all my screen refreshes in either timers or a function that a timer calls. Then set the timer to the approprate interval (usually 1)

    I'm just looking for tips on how I can more effectivly refresh. Oh yah is there an easier way to get the fps other than have to count the refreshes in a second?

    Thanks!

    NOMAD

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Use a backbuffer. What you do is .Cls an invisible autoredrawing picturebox and draw your stuff there (like you already do). Then, copy the whole picturebox to a visible picturebox, with NO .Cls calls. Use the SrcCopy method. Voila, you have no flicker.

    Also, don't use timers; fox says they're the devil, but I think they're okay for small projects. Use the GetTickCount API call:
    VB Code:
    1. Function GameLoop()
    2. Dim LastCount As Long
    3. Dim ThisCount As Long
    4.  
    5.     LastCount = GetTickCount
    6.     Do
    7.         ThisCount = GetTickCount
    8.         If ThisCount - LastCount >= (1000 / Game_Updates_Per_Second) Then
    9.             [attainedFPS] = 1000 / (ThisCount - LastCount)
    10.             'Do your BitBlt calls here.
    11.         End If
    12.         DoEvents
    13.     Loop
    14. End Function
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Lively Member
    Join Date
    Sep 2001
    Posts
    74

    backbuffer

    there are many tutorials on using a backbuffer also. Although I personally prefer to use the autoredraw property because then you don't need the extra picture box. I don't think either method produces better performance in terms of speed and picture quality though.
    All will fall before the might of the Black Sashi...

  4. #4
    Lively Member
    Join Date
    Sep 2001
    Posts
    74

    timers

    What would you suggest as a replacement? Games of any complexity require lots and lots of different time driven events, using timers seems to me much easier to follow then hard codeing timed events.
    All will fall before the might of the Black Sashi...

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Well timers create a pseudo-multithreaded program, but all they really do is nested GetTickCount loops:
    VB Code:
    1. Function GameLoop()
    2. Dim LastCount As Long
    3. Dim ThisCount As Long
    4.  
    5.     LastCount = GetTickCount
    6.     Do
    7.         ThisCount = GetTickCount
    8.         If ThisCount - LastCount >= Interval Then
    9.            'Timer Function
    10.         End If
    11.         ThisCount = GetTickCount
    12.         If ThisCount - LastCount >= Interval2 Then
    13.            'Timer Function
    14.         End If
    15.         DoEvents
    16.     Loop
    17. End Function
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6
    NOMADMAN
    Guest
    Thanks All!

    But Sastaxi, it doesn't seem to be working. This is more-or-less what I did.

    VB Code:
    1. picBuffer.Cls
    2.    
    3.     'My BitBlting
    4.  
    5.     'Imagine much code here
    6.     'displays everything
    7.  
    8.     'All I did was change the destination hDC to picbuffer.hDC from
    9.     'frmMain.hDC.  But the rest of the code is the same.
    10.  
    11.     RetVal = BitBlt(frmMain.hDC, 0, 0, 400, 600, picBuffer.hDC, 0, 0, SRCCOPY)

    I made a picture box called picBuffer gave it the redraw property. Made it also the size of the form and made it invisible. Its left/top properties are both 0. As my code said I just changed all the frmMain.hDC to picBuffer.hDC. Then added the two lines you see above. What did I forget?

    NOMAD

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Yeah, that's all fine. What's the specific error you're receiving? It's not blitting?
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8
    Zaei
    Guest

    Re: timers

    Originally posted by Zaknafein
    What would you suggest as a replacement? Games of any complexity require lots and lots of different time driven events, using timers seems to me much easier to follow then hard codeing timed events.
    Games of any real complexity would use a standard while loop to update, and render. Movement is calculated by taking the fraction of a second that it took the last frame to render, and moving an object, etc by that amount times their velocity. The easiest way is to be able to implement objects that have a Render() and Update() function, that gets called every frame. Something along these lines:
    Code:
    While bRunning
      UpdateAllObjects
      RenderAllObjects
    Wend
    To simplify this, you can limit the number of updates per second, and use a single set velocity for objects:
    Code:
    While bRunning
      If GetTickCount() >= lastUpdate + 50 Then
        lastUpdate = GetTickCount()
        UpdateAllObjects
      End If
      RenderAllObjects
    Wend
    Z.

  9. #9
    Lively Member
    Join Date
    Sep 2001
    Posts
    74

    looping

    You can't take care of eveything single thing in the game loop. I'm not talking about stupid arcade games like space invaders. I mean adventure/roleplaying games of greater complexity. Personally for certain events I think timers work far better then hard codeing it into loops.
    All will fall before the might of the Black Sashi...

  10. #10
    Zaei
    Guest
    Trust me. You can take care of EVERYTHING with a single loop. I can give you examples if youd like.

    Z.

    [edit]
    Or just take a look at Times of War, in the Communication Area of this Forum. Everything in there is taken care of with one loop (im the programmer).

  11. #11
    NOMADMAN
    Guest
    Yes its just not Blitting, no sprites. What settings need to be on for the form and the picbuffer? Thanks a bunch guys!

    NOMAD

  12. #12
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    picBuffer must have AutoRedraw set to True (1).
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  13. #13
    maxsrussell
    Guest

    Angry flickers are my problem too

    Is it totally possible to get rid of flickering when animating (toggling between pictures) in a picturebox or image control? I have included a sample of a very simple animation that still flickers. The files are vectors (wmf) and are not large. I even get the mild flickering when I run a loop with only one picture. It is holding up our project. I would greatly appreciate any help. Are the things I've read in this thread pertinent to my situation? I'm pretty new to Visual Basic 6.0.

    Dim TTCount As Integer
    Dim ZZCount As Long
    For TTCount = 1 To 25
    For ZZCount = 1 To 5000000 'Pause loop
    Next
    Set Picture6.Picture = LoadPicture"C:\My Documents\Pictures\Pic1.wmf")
    For ZZCount = 1 To 5000000 'Pause loop
    Next
    Set Picture6.Picture = LoadPicture("C:\My Documents\Pictures\Pic2.wmf")
    Next

    How about a recommendation of a good book? I am also trying to move some pictureboxes, and that's not going too badly. But is Visual Basic the wrong program for commercial instructional software that uses a lot of the kinds of animation that I have described here? Thank you very much.

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