How to create a moving a pictureBox right till it hits another PixelBox in

Im trying to make a ball move from the left side of the form to the right until it hits another PixelBox can any one suggest how to do it?

Well, the first step is getting the ball to move, at a steady pace. So to do this we will use the timer control, click and drag a timer onto the form, then set the interval property to 100 or so (depending on how fast you want the ball to move). Then make sure it is enabled, and double click on it to create the tick event. In the tick event:

ball.Left = ball.Left + 1

Depending on how fast you want it to go, change the number one to something higher (the smaller this number the smoother the movement, it's better to put the timer interval down lower, if you want speed). Then we want to check if this new move means it's hit the other picture box, so right after moving it:

If ball.Left + ball.Width > otherpicturebox.Left And ball.Top + ball.Height > otherpicturebox.Top And ball.Left < otherpicturebox.Left + otherpicturebox.Width And ball.Top < otherpicturebox.Top + otherpicturebox.Height Then
Timer1.Enabled = False
MsgBox("I've hit the other picture box")
End If

No comments:

Post a Comment

Please Provide your feedback here