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

ジョイントとか。。

Get Adobe Flash player
by wass 11 Oct 2010
    Embed
/**
 * Copyright wass ( http://wonderfl.net/user/wass )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/qNIm
 */

package {
    import flash.display.*;
    import flash.events.*;
    import flash.ui.*;
    import com.actionsnippet.qbox.*;
    import Box2D.Common.Math.*
    

    public class FlashTest extends MovieClip {
        public var jiki:QuickObject
        
        
        public function FlashTest() {
            // write as3 code here..
            stage.frameRate = 60;
 
            var sim:QuickBox2D = new QuickBox2D(this);
 
            sim.createStageWalls();
 
            jiki = sim.addCircle({x:4, y:8, radius:1});
            var foot:QuickObject=sim.addBox({x:5, y:5, width:3, height:0.3,density:2.1} );
            sim.addBox( { x:2.5, y:6, width:4, height:.3, angle:0.3, density:0, fillColor:0xCC0000 } );
            sim.addBox( { x:13, y:6, width:4, height:.3, angle:6.28-0.3, density:0, fillColor:0xCC0000 , maskBits:0xFFFE} );
            
            var bou:QuickObject = sim.addJoint({  
                a:foot.body,
                b:jiki.body,
                //x1:4,
                //y1:8,
                //x2:5,
                //y2:5,
                //length:2,
                frequencyHz:4,///大きいほど伸びにくい0は最大
                dampingRatio:0.1,//小さいほど引きつく
                collideConnected:true
            });
            sim.start();
            sim.mouseDrag();
            
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
            stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
            stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
        }  
        private var left:Boolean = false;
        private var right:Boolean = false;
        private var up:Boolean = false;
        private var down:Boolean = false;
        private function onEnterFrame(event:Event):void
        {   
            var jikiVec:b2Vec2 = jiki.body.GetLinearVelocity();
            var jikiSca:Number = jiki.body.GetAngularVelocity();
            
            if (up)jikiVec.y -= 0.5;
            if (down)jikiVec.y += 0.5;
            if (right)jikiVec.x += 0.2;
            if (left)jikiVec.x -= 0.2;
             
            jiki.body.SetLinearVelocity(jikiVec);
            jiki.body.SetAngularVelocity(jikiSca);
        }
        private function onKeyDown(event:KeyboardEvent):void {
            if (event.keyCode == Keyboard.LEFT) left = true;
            if (event.keyCode == Keyboard.RIGHT) right = true;
            if (event.keyCode == Keyboard.UP) up = true;
            if (event.keyCode == Keyboard.DOWN) down = true;        
        }
        private function onKeyUp(event:KeyboardEvent):void
        {
            if (event.keyCode == Keyboard.LEFT) left = false;
            if (event.keyCode == Keyboard.RIGHT) right = false;
            if (event.keyCode == Keyboard.UP) up = false;
            if (event.keyCode == Keyboard.DOWN) down = false;    
        }
 
    }
    
}