首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Box2D调试器不与Starling一起工作

Box2D调试器不与Starling一起工作
EN

Stack Overflow用户
提问于 2015-01-27 21:02:47
回答 2查看 173关注 0票数 0

我使用的是Box2D和最新版本的Starling,我尝试使用Box2D调试器,但到目前为止没有什么工作,这是我尝试过的,我在stage3D层上添加了一个Flash层,这样我就可以使用Flash,我正在网络上运行我的应用程序。

主修班:

代码语言:javascript
复制
    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);
    }

游戏世界:

代码语言:javascript
复制
  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);
    }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-01-27 22:12:34

看起来您并没有使用b2DebugDraw.AppendFlag()b2DebugDraw.SetFlags()在调试绘图逻辑中添加任何标志;这些标志告诉调试绘图需要在屏幕上绘制什么样的信息。您很可能希望使用b2DebugDraw.e_shapeBit标志。

它看起来也不像您已经定义了使用b2Debug.SetDrawScale()的绘图比例尺,虽然我不确定如果不能够检查它现在是否是绝对必要的。

查看我的游戏框架中的Debug类可能会帮助您解决这个问题。

票数 3
EN

Stack Overflow用户

发布于 2015-01-27 21:04:42

每次打电话给world.DrawDebugData() step()都要打电话给step()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28179931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档