home page icon Flash Bestiary / Physics / Super Balls

Super Balls

This movie demonstrates basic collision detection and bouncing. You may grab the balls with your mouse and throw them around.

Each superball is a movie clip which keeps track of its own velocity in the variables vx and vy. vx and vy are added to _x and _y, respectively, to move the balls around the Stage.

vy is affected by gravity, which causes the balls to drop towards the floor. And both vx and vy are affected by air resistance, which causes the balls to slow down over time.

Whenever the balls collide with a floor, ceiling or wall, their velocity in either the x or y direction is reversed, and they also lose some speed due to the collision.

When two balls collide with each other, they trade energy (the slow ball goes fast and the fast ball goes slow). They travel in the opposite direction of the collision, and also some energy is lost, due to the collision.

UPDATE: The source code below now contains an Actionscript 3 version, in addition to the original Flash MX code.


sourcecode iconDownload the flash project
book iconJim's Favorite Actionscript Books
wiki iconAsk Jim about Actionscript
Next: Clumping

Having trouble opening the project? You may need to Upgrade to Flash CS3

Copyright © 2003,2004 by Jim Bumgardner. All Rights Reserved.        Leave Jim some feedback