john-formby
asked on
Smooth animation
Hi,
What is the best way to make smooth animation in VB.NET? I have a small game with a .JPG background and I have a few transparent GIFs which are animated using the timer control. When the image moves though, it is very jumpy and the background is distorted. It does not have to be perfect, but I would like it to be smoother than it is at the moment.
Thanks,
John.
What is the best way to make smooth animation in VB.NET? I have a small game with a .JPG background and I have a few transparent GIFs which are animated using the timer control. When the image moves though, it is very jumpy and the background is distorted. It does not have to be perfect, but I would like it to be smoother than it is at the moment.
Thanks,
John.
ASKER
Hi,
Thanks for your very quick reply, I am making a small character move across the screen and it has 6 images to animate it. The images are contained within an imagelist and the code that calls the images is:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
hsbSpeed_Change()
steps += 1
steps = steps Mod 5
If imgPerson.Left = 735 Then
direction = "left"
ElseIf imgPerson.Left = 0 Then
direction = "right"
End If
If direction = "left" Then
imgPerson.Left = imgPerson.Left - 15
imgPerson.Image = ImageList1.Images(steps + 6)
ElseIf direction = "right" Then
imgPerson.Left = imgPerson.Left + 15
imgPerson.Image = ImageList1.Images(steps)
End If
CheckJump()
End Sub
I am unsure where to add the piece of code you have just posted.
Please could you advise?
John
Thanks for your very quick reply, I am making a small character move across the screen and it has 6 images to animate it. The images are contained within an imagelist and the code that calls the images is:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
hsbSpeed_Change()
steps += 1
steps = steps Mod 5
If imgPerson.Left = 735 Then
direction = "left"
ElseIf imgPerson.Left = 0 Then
direction = "right"
End If
If direction = "left" Then
imgPerson.Left = imgPerson.Left - 15
imgPerson.Image = ImageList1.Images(steps + 6)
ElseIf direction = "right" Then
imgPerson.Left = imgPerson.Left + 15
imgPerson.Image = ImageList1.Images(steps)
End If
CheckJump()
End Sub
I am unsure where to add the piece of code you have just posted.
Please could you advise?
John
Actually, the code I advised is geared towards you using the form.onPaint event to create the graphics, not a graphics / image control, so it may not work as well.
Plase the snippit in the Public Sub New() event of the form (inside the windows form designer generated code.)
Plase the snippit in the Public Sub New() event of the form (inside the windows form designer generated code.)
ASKER
Not made any noticable difference i'm afraid, but thanks for trying :-) Somebody mentioned something called bitblt. Would this be any use in my situation? I don't really know anything about it and how difficult it is to implement into the code.
John
John
It sounds like bitblt is an API function - something to avoid.
Why not simply handle the painting of the image(s) through the form's OnPaint call and it's associated graphics object? Whenever timer1 fires, simply invalidate the form after changing a form-wide-variable called (arbitrairly) position. Again, this is what my origional answer was prdicated on...
I imagine that the flickering you're seeing now is being caused by a dissacocioated control being relocated and redrawn on your form, then the form playing "catchup" and redrawing the region where the control used to be. Using the OnPaint of the form to draw the images instead, you can redraw the entire form at once, and using double-buffering remove the flicker.
Why not simply handle the painting of the image(s) through the form's OnPaint call and it's associated graphics object? Whenever timer1 fires, simply invalidate the form after changing a form-wide-variable called (arbitrairly) position. Again, this is what my origional answer was prdicated on...
I imagine that the flickering you're seeing now is being caused by a dissacocioated control being relocated and redrawn on your form, then the form playing "catchup" and redrawing the region where the control used to be. Using the OnPaint of the form to draw the images instead, you can redraw the entire form at once, and using double-buffering remove the flicker.
bitblt I think is Direct X.
ASKER
I tried the code you posted but it didn't make any difference :-( I am probably not implementing it correctly :-)
I have posted my entire program for you to look at in a .zip file. It is at:
http://www.3doubleu.co.uk/game.zip
If you could have a look at it I would really appreciate it
John
I have posted my entire program for you to look at in a .zip file. It is at:
http://www.3doubleu.co.uk/game.zip
If you could have a look at it I would really appreciate it
John
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are a genius, that looks a 1000 times better than before :-) Thank you so much.
John
John
setstyle(ControlStyles.Dub
This should help reduce the flickering.