Skip to content

Instantly share code, notes, and snippets.

@Misiur
Created August 3, 2016 19:31
Show Gist options
  • Save Misiur/b783aa81671f403ab165219ebcc1117b to your computer and use it in GitHub Desktop.
Save Misiur/b783aa81671f403ab165219ebcc1117b to your computer and use it in GitHub Desktop.
package;
import nape.util.BitmapDebug;
import nape.util.Debug;
import nape.phys.Body;
import nape.phys.BodyType;
import nape.shape.Circle;
import nape.shape.Polygon;
import nape.geom.Vec2;
import nape.space.Space;
import openfl.display.Sprite;
import openfl.display.DisplayObject;
import openfl.events.Event;
import openfl.Lib;
class Main extends Sprite {
public var space:Space;
private var _t:Int;
private var debug:Debug;
public function new () {
super ();
_t = Lib.getTimer();
space = new Space(new Vec2(0, 600));
addEventListener(Event.ENTER_FRAME, update, false);
var floorBody:Body = new Body(BodyType.STATIC);
var floorShape:Polygon = new Polygon(Polygon.rect(0, Lib.current.stage.stageHeight - 5, Lib.current.stage.stageWidth, 5));
floorShape.body = floorBody;
floorBody.space = space;
var block:Body = new Body();
var blockShape:Polygon = new Polygon(Polygon.rect(300, 100, 50, 50));
blockShape.body = block;
block.space = space;
var circle:Body = new Body();
var circleShape:Circle = new Circle(50, new Vec2(100, 100));
circle.rotation = 45;
circle.position.x = 300;
circle.position.y = 100;
circleShape.body = circle;
circle.space = space;
debug = new BitmapDebug(Lib.current.stage.stageWidth, Lib.current.stage.stageHeight, 0x33BADA55);
var display:DisplayObject = debug.display;
addChild(display);
}
public function update(e:Event)
{
var t:Int = Lib.getTimer();
var dt:Float = (t - _t) * 0.001;
_t = t;
space.step(dt);
debug.clear();
debug.draw(space);
debug.flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment