|
-
Dec 7th, 2001, 12:43 PM
#1
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
-
Dec 7th, 2001, 01:24 PM
#2
Good Ol' Platypus
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:
Function GameLoop()
Dim LastCount As Long
Dim ThisCount As Long
LastCount = GetTickCount
Do
ThisCount = GetTickCount
If ThisCount - LastCount >= (1000 / Game_Updates_Per_Second) Then
[attainedFPS] = 1000 / (ThisCount - LastCount)
'Do your BitBlt calls here.
End If
DoEvents
Loop
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)
-
Dec 7th, 2001, 06:42 PM
#3
Lively Member
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...
-
Dec 8th, 2001, 01:36 AM
#4
Lively Member
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...
-
Dec 8th, 2001, 11:34 AM
#5
Good Ol' Platypus
Well timers create a pseudo-multithreaded program, but all they really do is nested GetTickCount loops:
VB Code:
Function GameLoop()
Dim LastCount As Long
Dim ThisCount As Long
LastCount = GetTickCount
Do
ThisCount = GetTickCount
If ThisCount - LastCount >= Interval Then
'Timer Function
End If
ThisCount = GetTickCount
If ThisCount - LastCount >= Interval2 Then
'Timer Function
End If
DoEvents
Loop
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)
-
Dec 8th, 2001, 01:55 PM
#6
Thanks All!
But Sastaxi, it doesn't seem to be working. This is more-or-less what I did.
VB Code:
picBuffer.Cls
'My BitBlting
'Imagine much code here
'displays everything
'All I did was change the destination hDC to picbuffer.hDC from
'frmMain.hDC. But the rest of the code is the same.
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
-
Dec 8th, 2001, 06:00 PM
#7
Good Ol' Platypus
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)
-
Dec 8th, 2001, 09:51 PM
#8
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.
-
Dec 8th, 2001, 11:39 PM
#9
Lively Member
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...
-
Dec 8th, 2001, 11:50 PM
#10
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).
-
Dec 9th, 2001, 01:16 PM
#11
Yes its just not Blitting, no sprites. What settings need to be on for the form and the picbuffer? Thanks a bunch guys!
NOMAD
-
Dec 9th, 2001, 03:02 PM
#12
Good Ol' Platypus
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)
-
Dec 9th, 2001, 08:52 PM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|