0

我正在尝试重置场景并将所有东西移动到其原始位置重置功能重置阵列将颈背体添加回舞台并附加图形但原始图形仍然在舞台上重置时的任何位置被称为

private var brickGraphic:MovieClip = new Brick();
private var brick:Body;
private var brickArray:Array;

private function setUp():void
{
    brickArray = new Array  ;

    for (var i:int = 0; i < 10; i++)
    {
        var brick:Body = new Body(BodyType.DYNAMIC);
        var brickShape:Polygon = new Polygon(Polygon.box(10,25));
        var brickGraphic = new Brick();
        brickGraphic.width = 10;
        brickGraphic.height = 25;
        addChild(brickGraphic);
        brickGraphic.cacheAsBitmap = true;
        brick.shapes.add(brickShape);
        brick.position.setxy(450, ((ag ) - 30 * (i + 0.5)));
        brick.angularVel = 0;
        brick.shapes.at(0).material.elasticity = .5;
        brick.shapes.at(0).material.density = 150;
        brick.cbTypes.add(brickType);
        brick.space = space;
        brickGraphic.stop();
        brick.userData.sprite = brickGraphic;
        brick.userData.sprite.x = brick.position.x;
        this.brickArray.push(brick);
    }

    private function reset():void
    {
        if (contains(brickGraphic)) removeChild(brickGraphic);
        space.clear();
        setUp();
    }
}

这是我在这个应用程序上遇到的最后一个问题,非常感谢您的帮助

4

1 回答 1

1

那是因为你没有用removeChild.

您需要为添加到舞台removeChild的每个对象调用。brickGraphic

就像是 :

private function setUp():void
{
    brickArray = [];

    for (var i:int = 0; i < 10; i++)
    {
        var brick:Body = new Body(BodyType.DYNAMIC);
        var brickShape:Polygon = new Polygon(Polygon.box(10,25));
        var brickGraphic = new Brick();
        brickGraphic.width = 10;
        brickGraphic.height = 25;
        addChild(brickGraphic);
        brickGraphic.cacheAsBitmap = true;
        brick.shapes.add(brickShape);
        brick.position.setxy(450, ((ag ) - 30 * (i + 0.5)));
        brick.angularVel = 0;
        brick.shapes.at(0).material.elasticity = .5;
        brick.shapes.at(0).material.density = 150;
        brick.cbTypes.add(brickType);
        brick.space = space;
        brickGraphic.stop();
        brick.userData.sprite = brickGraphic;
        brick.userData.sprite.x = brick.position.x;
        this.brickArray.push(brick);
    }


}

private function removeAllBricks():void
{
    for(var i:int=0; i<brickArray.length; i++)
    {
       var dp:DisplayObject = brickArray[i].userData.sprite as DisplayObject;
       if(dp && dp.parent)
           dp.parent.removeChild(dp);
    }
}

private function reset():void
{
    removeAllBricks();
    space.clear();
    setUp();
}
于 2013-03-28T23:39:22.327 回答