我使用的是Box2D和最新版本的Starling,我尝试使用Box2D调试器,但到目前为止没有什么工作,这是我尝试过的,我在stage3D层上添加了一个Flash层,这样我就可以使用Flash,我正在网络上运行我的应用程序。
主修班:
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);
}发布于 2015-01-27 22:12:34
看起来您并没有使用b2DebugDraw.AppendFlag()或b2DebugDraw.SetFlags()在调试绘图逻辑中添加任何标志;这些标志告诉调试绘图需要在屏幕上绘制什么样的信息。您很可能希望使用b2DebugDraw.e_shapeBit标志。
它看起来也不像您已经定义了使用b2Debug.SetDrawScale()的绘图比例尺,虽然我不确定如果不能够检查它现在是否是绝对必要的。
查看我的游戏框架中的Debug类可能会帮助您解决这个问题。
发布于 2015-01-27 21:04:42
每次打电话给world.DrawDebugData() step()都要打电话给step()
https://stackoverflow.com/questions/28179931
复制相似问题