AS3显示列表和Box2D的 [英] AS3 Display list and box2d

查看:149
本文介绍了AS3显示列表和Box2D的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为砖一个叫createBrick子类,Sprite类用于扩展的内部功能,我也有在导出运行时共享所谓的砖库中创建的影片剪辑。对于一些奇怪的原因,当我运行code砖没有显示出来的,即使它得到当我调试了code创建并阶段。

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.

下面是函数

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

同样的功能完美地工作,如果我有所有code在主文档类和我看到舞台上的一块砖。任何线索,我这不是引用它是否正确?

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?

推荐答案

我想通了,刚刚通过的主要文件类舞台参考精灵展现出来。

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

这篇关于AS3显示列表和Box2D的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆