Want to make for Flash games animation balloons flying across the screen upon successful completion of the level.
But it is impossible to do it gradually and that would be another processor tiralo much.
Balls I have a movie clips that I randomly change the size to large and a smaller side that would create the impression of "different" balls. The movement of balls make use of the TweenMax library.
But the result depresses me with its quality.
here is the piece of code which I use:
public static function randomScale(shape: DisplayObject, ll Number, ul Number): void
{
var sc: Number = 1 + Math.random() * ((Math.random() < 0.5) ? 1 : -1);
sc = ((sc < ll) || (sc > ul)) ? 1 : sc;
if (sc != 1)
{
shape.scaleX = sc;
shape.scaleY = sc;
}
}
/**
* To launch the object in flight from the bottom of the container to the top, can be used for registration pass the level.
*
* @param parent - the parent container inside of which will be flying objects.
* @param duration - the duration of the animation.
* @param delayMax is the maximum delay before the animation.
* @param deltaX - the maximum deviation of the X-coordinate to the left or the right, to give a natural behavior.
* @param scale - to apply the change of scale of objects in the range from 0.7 to 1.5.
* @param callback function invoked at the end of the animation.
*/
public static function fly(parent: DisplayObjectContainer, shapes: Vector.,
duration: Number, delayMax: Number,
deltaX: uint,
scale: Boolean = false,
callback: Function = null): void
{
// get the dimensions of the parent container
var w: uint = parent.width;
var h: uint = parent.height;
var cnt: uint = shapes.length;
// run the objects one by one
for each (var shape: MovieClip in shapes)
{
// random position of the object
shape.x = Math.the round(Math.random() * w);
shape.y = h + 5; // the original objects are at the bottom
shape.visible = false;
// change scale of the object in nibalism range
if (scale)
{
randomScale(shape, 0.7, 1.5);
}
parent.addChild(shape);
// start the animation of the flight
TweenMax.to(shape, duration, // duration of animation
{delay: delayMax * Math.random(), // random delay 0...delayMax seconds, that would look naturally
x: shape.x + (Math.the round(Math.random() * deltaX * 2) - deltaX), // destination differs ± deltaX from the source
y: -150, // the objects leave the boundary of the screen
ease: Linear.easeIn, // objects are flying with a linear velocity
visible: false, // in the end they become invisible
onInit: showShape,
onInitParams: [shape],
onComplete: removeShape, // method for Stripping the finished animation
onCompleteParams: [shape]
});
}
function showShape(child: MovieClip): void
{
child.visible = true;
}
/** Cleanup at the end of the animation */
function removeShape(child: MovieClip): void
{
// delete objects from the container after the animation ends
parent.removeChild(child);
}
}
}