AS3 Display list and box2d

一笑奈何 提交于 2019-12-25 04:48:10

问题


I have a function called "brick" inside a subclass called createBrick that extends from the sprite class, also I have a movie clip created in the library exported for runtime sharing called "Brick". For some odd reason when I run the code the brick is not showing up on the stage even though it does get created when I debug the code.

here is the function

     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);
                }
        }

The same function works perfectly if I have all the code with in the main document class and I do see a brick on the stage. Any clues Am I not referencing it properly?


回答1:


I figured it out, just had to pass the stage reference from main document class for the sprite to show up.



来源:https://stackoverflow.com/questions/31787731/as3-display-list-and-box2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!