Bounce Multiple Objects

Bounce Back With if And else if

Great! Now we can flip the myBall.speed variables between positive and negative numbers exactly like we did when we bounced that single ball.

Our if statement will now flip the value of myBall.speed instead of resetting the Y position. Then we'll add an else if statement that does the same thing when the Y position of myBall is less than the top boundary:

That's all it takes to get a bounce animation:

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player