Smooth animations 30-100 objects in ActionScript 3


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/code-flow.club/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
5 views
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);
}
}
}
by | 5 views

5 Answers

0 like 0 dislike
Well, do so in a loop creating movie clips with a random size and a random x coordinate, then to each add ENTER_FRAME, respectively, and a function that will randomly in each frame to change a bit of the x coordinate (that he would like the wind trembling in the light) and decrease the y-coordinate, so up he flew. Well, make a frame rate of 41 per second. It should look all smooth and nice. You can still the ball inside to stanimirovata for realism. That he slightly changed the form.
by
0 like 0 dislike
TweenMax seems to be support animation on EnterFrame
by
0 like 0 dislike
There are two tips which will help you with whatever animation you do
do not use something that is not obvious — if you displace the object 10 pixel per second at 100 FPS every time you mix in 0.01 — in this sense is not present, and percent eating.
\r
Let's look deeper.
100 objects are mixed at 10 pixels. 100 FPS
You are trying to do, brakes, goodbye 100 FPS. Cycle...
\r
Now let's not mix them into invisible distances. Also, we give each a starting "offset"
In the end, for every tick only move 10 objects. In the trail of the tik — other 10.
For the "visible" tick — all.
\r
Approval — if you break the animation into parts, and to animate all objects — it will raise FPS
Raising the FPS will smooth out possible fluctuations of the shear objects.
And — the faster, the more faster...
\r
I'm a technology tested at one time on the shadow-mapping( using the texture ) — it is necessary to update the cube. Here is the full update the 6 faces is inhibited. But if the TEC only two faces — fine. And raising FPS gave notice that some faces exist a little in that time
by
0 like 0 dislike
While all the experiments with the smooth reduced to the following: if you do the "flying" balls across the screen for more than 5 seconds, for example 10, it turns smoothly, but very slowly :(, the player these balls quickly begin to curse.
by
0 like 0 dislike
For normal vector of the engine of flash to animate 100 objects with a decent fps - almost an impossible task. Go for GPU rendering, some kind of Starling will help, there is also mobility and TweenMax, so this part of the code even remake is not necessary.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
110,608 questions
257,186 answers
0 comments
24,986 users