# vb.net animate line



## boogerlad (Apr 22, 2010)

Hi, is there a way to make a line draw with the surface.drawline command animate? I want to draw a line, and then translate it a certain number of times. Sure,you can use variables to move around the xy values, but I want to do it in a way without clearing the surface, thus causing flickering. Is there a way?


----------



## FordGT90Concept (Apr 22, 2010)

Maybe draw over it again with the background color?  To prevent flickering, you'd need more performance than GDI which basically means using DirectDraw.


----------



## Kreij (Apr 22, 2010)

Can you post some code so we can see what you are doing?


----------



## boogerlad (Apr 22, 2010)

I seem to have fixed this with a manual backbuffer. I'll post the code soon.


----------



## W1zzard (Apr 22, 2010)

.net has some doublebuffered feature for controls, in non managed use a memory dc - good class for it at codeproject


----------



## boogerlad (Apr 23, 2010)

Dim midx As Integer = pnlSurface.Width / 2
        Dim midy As Integer = pnlSurface.Height / 2
        Dim placeY As Integer = pnlSurface.Width / 16
        Dim fscrollY As Integer = pnlSurface.Height - 128
        Dim myBuffer As BufferedGraphics
        Dim currentContext As BufferedGraphicsContext
        currentContext = BufferedGraphicsManager.Current
        Dim rect As Rectangle = New Rectangle(0, 0, pnlSurface.Width, pnlSurface.Height)
        myBuffer = currentContext.Allocate(pnlSurface.CreateGraphics, rect)
        Dim Mario() As System.Drawing.Image = {My.Resources.walk_1, My.Resources.walk_2, My.Resources.walk_3, My.Resources.jump}
        Dim Goomba() As System.Drawing.Image = {My.Resources.goomba_1, My.Resources.goomba_2, My.Resources.goomba_squished}
        Dim floor = My.Resources.floor
        Dim scroll, changeM, changeG, fscroll As Integer
        Dim draw As New Pen(Color.Black, 4)
        myBuffer.Graphics.Clear(Color.Blue)
        tmr = tmr + 1
        If tmr > 1 Then tmrMove.Enabled = False
        For scroll = 0 To pnlSurface.Width Step 1
            changeM = changeM + 1
            If changeM > 2 Then changeM = 0
            changeG = changeG + 1
            If changeG > 1 Then changeG = 0
            fscroll = fscroll - 1
            If fscroll < -63 Then fscroll = 0
            myBuffer.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
            System.Threading.Thread.Sleep(10)
            myBuffer.Graphics.Clear(Color.Blue)
            myBuffer.Graphics.DrawEllipse(draw, scroll, placeY, 90, 30)
            myBuffer.Graphics.FillEllipse(Brushes.White, scroll, placeY, 90, 30)
            myBuffer.Graphics.DrawEllipse(draw, scroll + 30, placeY + 70, 90, 30)
            myBuffer.Graphics.FillEllipse(Brushes.White, scroll + 30, placeY + 70, 90, 30)
            myBuffer.Graphics.DrawImage(floor, fscroll, fscrollY)
            myBuffer.Graphics.DrawImage(Mario(changeM), midx - 100, fscrollY - 150)
            myBuffer.Graphics.DrawImage(Goomba(changeG), midx + 100, fscrollY - 80)
            myBuffer.Render(pnlSurface.CreateGraphics)
        Next scroll

is the code for my gr.10 comp science code. It works now! I simply followed the msdn article http://msdn.microsoft.com/en-us/library/ka0yazs1.aspx

It's a little too fast now though. How do I limit the drawing speed of mario and the goomba but not the clouds?


----------

