Picturebox Flickering when location Changed...

12padams

Well-known member
Joined
Feb 19, 2010
Messages
48
Programming Experience
Beginner
Hi i am making an RPG game with visual basic...

The character is a picture box.

The problem is when i move the charactor with the arrow keys it flashes black for a milisecond. I think added animated walking where it slowely moves 32 pixels but not it goes black the whole time... what can i do sto stop it going black everytime it moves?

Old movement code:
VB.NET:
        If e.KeyCode = Keys.Right Then
            player.Image = My.Resources.mainplayerright
            moveto = New Point(playerx + 32, playery)
            If badpoints.Contains(moveto) Then
            Else
                playerx = playerx + 32
                player.Location = New Point(playerx, playery)
            End If
        End If

that code moved player or jumped player to a tile 32 pixels in one direction and caused a quick black flash

VB.NET:
        If e.KeyCode = Keys.Left Then
            player.Image = My.Resources.mainplayerleft
            moveto = New Point(playerx - 32, playery)
            If badpoints.Contains(moveto) Then
            Else
                walkdirection = "left"
                walkmove.Start()
            End If
        End If

    Private Sub walk_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles walkmove.Tick
        If walkdirection = "left" Then
            While walkcount < 32
                playerx = playerx - 1
                player.Location = New Point(playerx, playery)
                walkcount = walkcount + 1
            End While
            walkcount = 0
            walkmove.Stop()
        End If

    End Sub

That code moves the player slowely but causes a big black line to merge then just ends up teleporting the player...

How can i get rid of the black flash during movement?
 
To help reduce flickering, put this code in your main. This doubles the buffer.

VB.NET:
Public Sub New()
        MyBase.New()
        'This call is required by the Windows Form Designer.
        InitializeComponent()
        Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint, True)
        Me.UpdateStyles()
        'Add any initialization after the InitializeComponent() call
    End Sub
 
I think you're having those kind of problems because Windows Forms are not supposed to be dealing with loads of graphics and/or moving graphics.
To have it nice and smooth as we usually see in games you'll have to point to graphic libraries.
 
Back
Top