Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Smooth animation

Posted on 2004-11-23
9
Medium Priority
?
464 Views
Last Modified: 2010-04-23
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.
0
Comment
Question by:john-formby
  • 4
  • 4
9 Comments
 
LVL 9

Expert Comment

by:Lacutah
ID: 12658596
Under the initialization portion of the form (or control) where you are drawing the images, add the following line:

setstyle(ControlStyles.DubbleBuffer or ControlStyles.UserPaint or ControlStyles.AllPaintingInWmPaint, True)

This should help reduce the flickering.
0
 
LVL 14

Author Comment

by:john-formby
ID: 12658720
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
0
 
LVL 9

Expert Comment

by:Lacutah
ID: 12658949
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.)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Author Comment

by:john-formby
ID: 12659006
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

0
 
LVL 9

Expert Comment

by:Lacutah
ID: 12659620
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.
0
 
LVL 7

Expert Comment

by:natloz
ID: 12659956
bitblt I think is Direct X.
0
 
LVL 14

Author Comment

by:john-formby
ID: 12660188
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
0
 
LVL 9

Accepted Solution

by:
Lacutah earned 2000 total points
ID: 12660709
http://www.eprojects247.com/updated.zip

Added two lines to your Timer1 Event which helped a tiney bit (imgPerson.Visible = False and imgPerson.Visible = True), also created a demo form showing how to draw the graphics dirrectly to the form and how that DOES improve the preformance rather than using image controls.
0
 
LVL 14

Author Comment

by:john-formby
ID: 12662789
You are a genius, that looks a 1000 times better than before :-)  Thank you so much.

John
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question