So I've got a free hour today, just enough to make this little thing as an answer to a question from Tweener list. For this example, I will (ab)use Petrie, little pteranodon who was affraid to fly. So, here goes a little helper class for tweening your DisplayObject along parabolic projectile:
package
{
import flash.display.DisplayObject
import flash.geom.Point
public class projectile
{
public function projectile (obj:DisplayObject = null)
{
_obj = obj;
}
public var g:Number = 1;
public var v0:Point = new Point ();
public var r0:Point = new Point ();
private var _obj:DisplayObject;
private var _t:Number = 0;
public function get t():Number { return _t; }
public function set t(val:Number):void
{
_t = val;
if (_obj != null)
{
_obj.x = r.x; _obj.y = r.y;
}
}
// physics
public function get r():Point
{
return new Point (r0.x + v0.x * t,
r0.y + v0.y * t + 0.5 * g * t * t);
}
}
}
How does it work? This article will give you verbose answer, I will simply give you the code this time:
Clickety click.