VBVB66

I have a program with a blue ball that bounces around the screen. (I later want to make it into a screensaver) When the ball moves it flashes, it does not move smoothly. Does anyone know how to make the movement more smooth
This is the code I use for the movement:
Code Block
If Direction = "UPLEFT" Then

Ball.Top -= Speed
Ball.Left -= Speed
End If
If Direction = "DOWNRIGHT" Then
Ball.Top += Speed
Ball.Left += Speed
End If
If Direction = "UPRIGHT" Then
Ball.Top -= Speed
Ball.Left += Speed
End If
If Direction = "DOWNLEFT" Then
Ball.Top += Speed
Ball.Left -= Speed
End If


Speed is set to 5 but can be changed
Direction is set by the "Bounce" part of my code. There are only diagonals.
Ball is the name of the blue ball that bounces around.

How can I make the movement more smooth



Re: Visual Basic Express Edition Movement Problem

Dave299

That's not really a lot to go on. What are you using for the ball. What is the timer interval.

Have a look at the following which just moves a ball from top left to bottom right, smoothly. It may give you some ideas

Public Class Form1

Dim rect As New Rectangle(0, 0, 30, 30)

Dim WithEvents Tmr As New Timer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

DoubleBuffered = True

Tmr.Interval = 10

Tmr.Start()

End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

e.Graphics.FillEllipse(Brushes.Blue, rect)

End Sub

Private Sub Tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tmr.Tick

Invalidate(rect)

rect.X += 1

rect.Y += 1

Invalidate(rect)

End Sub

End Class





Re: Visual Basic Express Edition Movement Problem

Tall Dude

Just for fun, try this VB program:

http://www.driveway.com/qdqdv71152






Re: Visual Basic Express Edition Movement Problem

VBVB66

The timer interval is set to 1. For the ball I am using the object BallShape from "Visual Basic PowerPacks 2.0". What does the "DoubleBuffered = True" do





Re: Visual Basic Express Edition Movement Problem

VBVB66

I tried doublebuffer and it reduces the flicker a little, but it still flashes/flickers.





Re: Visual Basic Express Edition Movement Problem

VBVB66

Anyone Please!





Re: Visual Basic Express Edition Movement Problem

ReneeC

I can tell you what I do.

I use pictureboxes but as they are intended to be used. I keep a background image. When I want to draw, I clone the background image and draw onto the new image. When I've done that I set the picturebox image to the newly drawn image. I've never seen this technique flicker. But I did before i began using this technique especially when I used a panel as a drawing surface.






Re: Visual Basic Express Edition Movement Problem

VBVB66

But I want to use OvalShape because I want the ball to change color when it hits the wall.





Re: Visual Basic Express Edition Movement Problem

ReneeC

You could change the ball color when it hits the wall computationally. Since that object isn't compatable with what I recommended, I cannot help you with this.




Re: Visual Basic Express Edition Movement Problem

VBVB66

I hope someone can. Is there any way to get the ball to redraw itself faster





Re: Visual Basic Express Edition Movement Problem

Jayson Furr

Try adding a class like this to the project:

Code Block

Public Class DBPictureBox

Inherits System.Windows.Forms.PictureBox

Public Sub New()

MyBase.New()

Me.SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, True)

Me.SetStyle(System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer, True)

End Sub

End Class

Then change you picturebox from "System.Windows.Forms.PictureBox" to a "DBPictureBox" in the hidden "FormName.Designer.vb" file.

See if that works for you.






Re: Visual Basic Express Edition Movement Problem

VBVB66

What is this I did not mark those replies as answers.(No offense) They all helped but my problem is still not solved. As for the last post, I didn't even read that one and it's marked as answer! Unless I have an evil twin, I see no reason for posts that I have not read to be marked as an answer.