Create animated 3D movement with ActionScript
Download source project t1031.zip (2 kb)
Angle = 0;
function moveball()
{
Angle++; // increase angle by 1 degree at each frame
rad = Angle / 20; // divide angle by speed
// calculate x and y offset of the ball
// sin and cos are between -1 and 1
X = Math.sin(rad) * 100; // X: -100 to +100 pixels horizontally
Y = Math.cos(rad) * 30; // Y: -30 to +30 pixels vertically
// place the ball at x and y
// (120,120) is the center
theBall._x = 120 + X;
theBall._y = 120 + Y;
// scale the ball based on y coordinate (vertical axis)
// negative y will increase the scale
// 100 is the normal size
theBall._xscale = 100 + Y;
theBall._yscale = 100 + Y;
// fade the ball based on y too
theBall._alpha = 75 + Y / 2;
}
setInterval(moveball,25);