Box2D 调试器不适用于 Starling
Box2D Debugger Not Working With Starling
我将 Box2D 与最新版本的 Starling 一起使用,我正在尝试使用 Box2D 调试器,但到目前为止没有任何效果,这是我尝试过的,我在 stage3D 的顶部添加了一个 Flash 层层,这样我就可以使用 Flash Sprite,我是 运行 我的网络应用程序。
主要 Class :
public function BallFriction()
{
this.addEventListener(Event.ADDED_TO_STAGE, onReady, false, 0, true);
}
private function onReady(event : Event) : void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onReady);
var stats:Stats = new Stats();
stats.y = 500;
stats.x = 50;
this.addChild(stats);
stage.color = 0x333333;
stage.stage3Ds[0].addEventListener(Event.CONTEXT3D_CREATE, onContextCreated);
oStarling = new Starling(Game, stage);
// akaStarling = new Starling(BoxWorld, stage);
oStarling.antiAliasing = 1;
oStarling.start();
}
private function onContextCreated(e:Event):void{
//debug mode
debugSprite=new Sprite();
addChild(debugSprite);
(BallFriction.oStarling.stage.getChildAt(0) as Game).debugDraw(BallFriction.debugSprite);
}
游戏世界:
public function Game()
{
super();
// Create a b2World with gravity 9.8 towards y axis.
world = new b2World(new b2Vec2(0, 9.8), true);
floor(400,590,800,20);
theBall = ball(100,400,ballWidth/2,Texture.fromBitmap(new Ball()));
// I also set the velocity of the ball
theBall.SetLinearVelocity(new b2Vec2(8, -8));
// Listen enterframe event and update world for each enter frame
this.addEventListener(EnterFrameEvent.ENTER_FRAME, updateWorld);
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage():void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
//(BallFriction.oStarling.stage.getChildAt(0) as Game).debugDraw(BallFriction.debugSprite);
}
private function updateWorld(e:EnterFrameEvent):void
{
world.Step(timestep, 10, 10);
world.DrawDebugData()
world.ClearForces();
}
public function debugDraw(debugSprite:flash.display.Sprite):void{
var debugDraw:b2DebugDraw = new b2DebugDraw();
debugDraw.SetSprite(Starling.current.nativeOverlay);
debugDraw.SetDrawScale(30);
debugDraw.SetLineThickness( 1.0);
debugDraw.SetAlpha(1);
debugDraw.SetFillAlpha(0.4);
debugDraw.SetFlags(b2DebugDraw.e_shapeBit);
world.SetDebugDraw(debugDraw);
}
每次调用step()
都要调用world.DrawDebugData()
您似乎没有使用 b2DebugDraw.AppendFlag()
或 b2DebugDraw.SetFlags()
向调试绘图逻辑添加任何标志;这些标志告诉调试绘制它需要在屏幕上绘制什么样的信息。您很可能会想要使用 b2DebugDraw.e_shapeBit
标志。
您似乎也没有使用 b2Debug.SetDrawScale()
定义绘图比例,但我不确定是否绝对有必要,现在无法检查它。
查看我的游戏框架中的 Debug
class 可能会对您有所帮助 - 它可以解决这个问题。
我将 Box2D 与最新版本的 Starling 一起使用,我正在尝试使用 Box2D 调试器,但到目前为止没有任何效果,这是我尝试过的,我在 stage3D 的顶部添加了一个 Flash 层层,这样我就可以使用 Flash Sprite,我是 运行 我的网络应用程序。
主要 Class :
public function BallFriction()
{
this.addEventListener(Event.ADDED_TO_STAGE, onReady, false, 0, true);
}
private function onReady(event : Event) : void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onReady);
var stats:Stats = new Stats();
stats.y = 500;
stats.x = 50;
this.addChild(stats);
stage.color = 0x333333;
stage.stage3Ds[0].addEventListener(Event.CONTEXT3D_CREATE, onContextCreated);
oStarling = new Starling(Game, stage);
// akaStarling = new Starling(BoxWorld, stage);
oStarling.antiAliasing = 1;
oStarling.start();
}
private function onContextCreated(e:Event):void{
//debug mode
debugSprite=new Sprite();
addChild(debugSprite);
(BallFriction.oStarling.stage.getChildAt(0) as Game).debugDraw(BallFriction.debugSprite);
}
游戏世界:
public function Game()
{
super();
// Create a b2World with gravity 9.8 towards y axis.
world = new b2World(new b2Vec2(0, 9.8), true);
floor(400,590,800,20);
theBall = ball(100,400,ballWidth/2,Texture.fromBitmap(new Ball()));
// I also set the velocity of the ball
theBall.SetLinearVelocity(new b2Vec2(8, -8));
// Listen enterframe event and update world for each enter frame
this.addEventListener(EnterFrameEvent.ENTER_FRAME, updateWorld);
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage():void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
//(BallFriction.oStarling.stage.getChildAt(0) as Game).debugDraw(BallFriction.debugSprite);
}
private function updateWorld(e:EnterFrameEvent):void
{
world.Step(timestep, 10, 10);
world.DrawDebugData()
world.ClearForces();
}
public function debugDraw(debugSprite:flash.display.Sprite):void{
var debugDraw:b2DebugDraw = new b2DebugDraw();
debugDraw.SetSprite(Starling.current.nativeOverlay);
debugDraw.SetDrawScale(30);
debugDraw.SetLineThickness( 1.0);
debugDraw.SetAlpha(1);
debugDraw.SetFillAlpha(0.4);
debugDraw.SetFlags(b2DebugDraw.e_shapeBit);
world.SetDebugDraw(debugDraw);
}
每次调用step()
world.DrawDebugData()
您似乎没有使用 b2DebugDraw.AppendFlag()
或 b2DebugDraw.SetFlags()
向调试绘图逻辑添加任何标志;这些标志告诉调试绘制它需要在屏幕上绘制什么样的信息。您很可能会想要使用 b2DebugDraw.e_shapeBit
标志。
您似乎也没有使用 b2Debug.SetDrawScale()
定义绘图比例,但我不确定是否绝对有必要,现在无法检查它。
查看我的游戏框架中的 Debug
class 可能会对您有所帮助 - 它可以解决这个问题。