mh

by hemingway
wip
♥0 | Line 54 | Modified 2013-01-27 13:14:36 | MIT License
play

ActionScript3 source code

/**
 * Copyright hemingway ( http://wonderfl.net/user/hemingway )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zexH
 */

package
{
    import flash.display.*;   
    import starling.core.*;
    
    [SWF(frameRate=60, width=465, height=465)]
    public class Main extends flash.display.Sprite
    {
        public function Main()
        {
            var starlingInstance:Starling = new Starling(StarlingBuffer, stage);
                starlingInstance.start();
        }
    }
}

import nape.util.*;
import nape.phys.*;
import nape.geom.*;
import nape.space.*;
import nape.shape.*;

import starling.display.*;
import starling.events.*;

class StarlingBuffer extends starling.display.Sprite
{
    private var instanceDebug :Debug;
    private var instanceSpace :Space;
    
    public function StarlingBuffer()
    {
        addEventListener(Event.ADDED_TO_STAGE, addedToStage);
    }

    protected function addedToStage($e:Event) :void
    {
        removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
        
        _init();
        
        addEventListener(Event.ENTER_FRAME, _loop);
    }

    protected function _init() :void
    {
        instanceDebug = new BitmapDebug(465, 465, 0xFFFFFF, true);
        instanceSpace = new Space(Vec2.weak(0, 3000));
        
        var $b :Body = new Body(BodyType.STATIC);
            $b.shapes.add(new Polygon(Polygon.rect(0, 0, 465, -1)));
            $b.shapes.add(new Polygon(Polygon.rect(0, 465, 465, -1)));
            $b.shapes.add(new Polygon(Polygon.rect(0, 0, -1, 465)));
            $b.shapes.add(new Polygon(Polygon.rect(465, 0, -1, 465)));
            $b.space = instanceSpace;
    }
    
    protected function _loop($e:Event) :void
    {
        instanceSpace.step(1/60);
        
        instanceDebug.clear();
        instanceDebug.draw(instanceSpace);
        instanceDebug.flush(); 
    }

}