Hello! I've been tinkering with the flash version of Box2D for a while now (combining it with Flixel), but I've hit a dead end regarding the setup of debug drawing. I think I've followed the examples I found correctly, but of course something is wrong; I just can't figure out where.
Here is the class file I've been using to set it up (had to keep it separate so I could extend from the Sprite class):
And here is the part where I run the thing:
I know I have bodies in the world, so if anyone can spot where I went wrong I'll be awfully grateful.
Here is the class file I've been using to set it up (had to keep it separate so I could extend from the Sprite class):
Code:
package
{
import Box2D.Dynamics.*;
import flash.display.Sprite;
public class DebugDraw extends Sprite
{
public function DebugDraw()
{
}
public function debugDrawSetup(Box2DWorld:b2World, MetersToPixelsRatio:Number, LineThickness:Number, Alpha:Number, FillAlpha:Number):void
{
var debugSprite:Sprite = new Sprite();
addChild(debugSprite);
var debugDraw:b2DebugDraw = new b2DebugDraw();
debugDraw.SetSprite(debugSprite);
debugDraw.SetDrawScale(MetersToPixelsRatio);
debugDraw.SetLineThickness(LineThickness);
debugDraw.SetAlpha(Alpha);
debugDraw.SetFillAlpha(FillAlpha);
debugDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit);
Box2DWorld.SetDebugDraw(debugDraw);
}
}
}
{
import Box2D.Dynamics.*;
import flash.display.Sprite;
public class DebugDraw extends Sprite
{
public function DebugDraw()
{
}
public function debugDrawSetup(Box2DWorld:b2World, MetersToPixelsRatio:Number, LineThickness:Number, Alpha:Number, FillAlpha:Number):void
{
var debugSprite:Sprite = new Sprite();
addChild(debugSprite);
var debugDraw:b2DebugDraw = new b2DebugDraw();
debugDraw.SetSprite(debugSprite);
debugDraw.SetDrawScale(MetersToPixelsRatio);
debugDraw.SetLineThickness(LineThickness);
debugDraw.SetAlpha(Alpha);
debugDraw.SetFillAlpha(FillAlpha);
debugDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit);
Box2DWorld.SetDebugDraw(debugDraw);
}
}
}
And here is the part where I run the thing:
Code:
override public function create():void
{
physicsSetup(10); //Creates a Box2D world
......
var debugDrawing:DebugDraw = new DebugDraw();
debugDrawing.debugDrawSetup(physicsWorld, ratio, 1.0, 1, 0.5);
}
override public function update():void
{
physicsWorld.Step(FlxG.elapsed, 10, 10);
physicsWorld.DrawDebugData();
super.update();
}
public function physicsSetup(GravityY:Number):void
{
physicsGravity = new b2Vec2(0, GravityY);
physicsWorld = new b2World(physicsGravity, true);
}
}
}
{
physicsSetup(10); //Creates a Box2D world
......
var debugDrawing:DebugDraw = new DebugDraw();
debugDrawing.debugDrawSetup(physicsWorld, ratio, 1.0, 1, 0.5);
}
override public function update():void
{
physicsWorld.Step(FlxG.elapsed, 10, 10);
physicsWorld.DrawDebugData();
super.update();
}
public function physicsSetup(GravityY:Number):void
{
physicsGravity = new b2Vec2(0, GravityY);
physicsWorld = new b2World(physicsGravity, true);
}
}
}
I know I have bodies in the world, so if anyone can spot where I went wrong I'll be awfully grateful.