AS3显示列表和box2d

时间:2015-08-03 12:48:15

标签: actionscript-3 box2d displaylist

我有一个名为" brick"在一个名为createBrick的子类中,从sprite类扩展,我也在为运行时共享导出的库中创建了一个名为" Brick"的影片剪辑。由于某些奇怪的原因,当我运行代码时,即使在我调试代码时确实创建了砖,它也没有出现在舞台上。

这是函数

     public  class createBrick extends Sprite {

        public function createBrick(_main:Main) {
                    main = _main; 
                    var go:Brick = new Brick();
                    addChild(go);
                    trace(go.x);
                    brick(475, 235, 30, 30);
        }

    private function brick(pX: int, pY: int, w: Number, h: Number): void {

                var bric:Brick = new Brick();
                addChild(bric);
                bric.x = pX;
                bric.y = pY;
                bric.width = w;
                bric.height = h;

                var polygonShape: b2PolygonShape = new b2PolygonShape();
                var polygonFixture: b2FixtureDef = new b2FixtureDef();
                polygonShape.SetAsBox(w / 2 / worldScale, h / 2 / worldScale);
                polygonFixture.shape = polygonShape;
                polygonFixture.density = .2;
                polygonFixture.restitution = 0.9;
                polygonFixture.friction = 0.9;
                var brickbodyDef: b2BodyDef = new b2BodyDef();
                brickbodyDef.type=b2Body.b2_dynamicBody;
                brickbodyDef.userData = bric;
                brickbodyDef.position.Set(bric.x / worldScale, bric.y / worldScale);
                var theBrick: b2Body = world.CreateBody(brickbodyDef);
                theBrick.CreateFixture(polygonFixture);
                }
        }

如果我在主文档类中包含所有代码并且我确实在舞台上看到了一块砖,那么相同的功能可以正常工作。任何线索我没有正确引用它吗?

1 个答案:

答案 0 :(得分:0)

我想通了,只需要从主文档类中传递舞台引用以显示精灵。