Quantunet.com

My Account

Joins Us
Flash 8 Actionscript 2.0 Knowledgebase
Linear Acceleration, Quadratic Easing  

Download

How to create an quadratic tween.


Actionscript

var x_velocity:Number = 25;
var y_velocity:Number = -80;
var a:Number = 10;
var dt:Number = 0.3;
var t:Number = 0;

ball_mc._x = 10;
ball_mc._y = 400;

ball_mc.onEnterFrame = function(){;
ball_mc._x += x_velocity*dt
ball_mc._y += y_velocity*dt + a*t*dt
t += dt;
};


Note: Press the "refresh" button in the browser to play the animation again.

How The Actionscript Works

First declare, define and assigned a values to varible.

var x_velocity:Number = 25;
var y_velocity:Number = -80;
var a:Number = 10;
var dt:Number = 0.3;
var t:Number = 0;


The movie clip "ball_mc" is set to a horizontal position of 10 and vertical position of 400.

ball_mc._x = 10;
ball_mc._y = 400;

A function is created the is called everytime the movie clip "ball_mc" enteres a new frame.

ball_mc.onEnterFrame = function(){

Inside this a new function is created to calcualtes the acceleration which is exponentialy related to the time passed. This is then multipled by the acceleration factor "a", time passed "t" and the time interval "dt" to give the change in position.This value is then returned.

ball_mc._x += x_velocity*dt
ball_mc._y += y_velocity*dt + a*t*dt

An interval amount is added to the total running time.

t += dt;

Each time the mc enters a new frame an amount is added to the position of the mc. This amount is directly propertional to the acceleration "a" the time "t" and the time interval "dt".

To learn more about kinematics see [projectile motion with actionscript]


© 2008 Quantunet LLC All Rights Reserved | Intellectual Property | Terms of Use | Privacy
Home | About Quantunet | FAQ's | Contact Us