In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Desuade Motion Package 1.5 Example (2)

desuade.com/dmp
Get Adobe Flash player
by sugyan 25 Jun 2010
/**
 * Copyright sugyan ( http://wonderfl.net/user/sugyan )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/cyLF
 */

// forked from sugyan's Desuade Motion Package 1.5 Example
/*

Desuade Motion Package (DMP) 1.5 Physics Example
http://desuade.com/dmp

This .fla goes over how physics works with the package.

////Overview////

This Motion Package offers a very simple, yet powerful approach to physics motion. Compared to full-blown physics engines, the DMP offers a very basic "physics manager" to calculate physics equations for individual objects.

The advantage of this design is that any object's property can be used, not just x and y values on a specific special subclass. Similar to tweening an object's value, except there is no end value or duration, and it uses physics equations rather than easeing.

This means you can apply "physics type velocity" to a Sprite's alpha value, or change the acceleration of the volume of a sound object.

You can use a BasicPhysics object to change a property's value at a specific rate, rather than over a given duration.

Like a Tween object, a BasicPhysics object changes the value of a given property, but unlike a Tween, there is no final value or duration. This means the velocity will continue to be applied until the BasicPhysics object stops.

BasicPhysics has 3 import properties:velocity, acceleration, and friction. These 3 values influence the value of the property on each update. The acceleration and friction affect the velocity, which gets added to the value each frame.

The angle and flip properties are useful mostly for display properties:x, y, z.

////Events////

BasicPhysics has 3 events:

STARTED:when start() is called.
UPDATED:when the velocity is applied
ENDED:when stop() is called.

////Usage////

var po:BasicPhysics = new BasicPhysics(target:Object, {property:String, velocity:Number = 0, acceleration:Number = 0, friction:Number = 0, angle:* = null, flip:Boolean = false, update:false});

See the documentation for more information on each property.

ex:
var mybp:BasicPhysics = new BasicPhysics(myclip, {property:'x', velocity:2});
mybp.start();

Very similar to a Tween object, you start() and stop() a BasicPhysics object.

v1.5:
    -BasicPhysics.startAtTime() is the same as starting a ClassSequence part-way through
    -duration property lets you run it almost like a tween and let's you use physics in sequences

For more information, consult the docs on properties and syntax guidelines: http://api.desuade.com/

*/

package {

    import flash.display.*;
    import com.desuade.motion.physics.*;
    import com.desuade.motion.sequences.*;

    public class motion_physics extends MovieClip {
    
        public function motion_physics() {
            super();
            
            //create movieclip to tween
            var target1:Sprite = new Sprite();
            target1.graphics.beginFill(0xAADDF0);
            target1.graphics.drawRect(0, 0, 100, 100);
            target1.name = "target1";
            addChild(target1);
            target1.x = 150;
            target1.y = 250;

            ////
            //Sequencing physics in v1.5
            //
            var pdncs:ClassSequence = new ClassSequence(BasicPhysics,
                {duration: 1, property:'y', velocity:2, acceleration:-.1, flip:true},
                {duration: 3, property:'x', velocity:2, friction:.3},
                new SequenceGroup(
                {duration: 1, property:'y', velocity:1, acceleration:.1, flip:true},
                {duration: 2, property:'alpha', velocity:-0.01},
                {duration: 1, property:'rotation', velocity:10, friction:1}
                )
            );
            pdncs.overrides = {target:target1};
            pdncs.start();
        }
    }
}