as3如何从移除的颈背体中移除图形

时间:2013-03-28 13:23:06

标签: arrays actionscript-3 for-loop reset

我已经将moviecCip的多个实例附加到多个颈背体,并有一个重置按钮将它们恢复到原始位置。当调用重置功能时,主体被重置并附加了mc。问题是原来的mc仍然处于被调用重置位置时被冻结的阶段。

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

private function setUp():void
{
    var brickType:CbType = new CbType();
    var w:int = stage.stageWidth;
var h:int = stage.stageHeight;
var ag:int = stage.stageHeight - 58;// height ofarea above ground
    brickArray = new Array  ;

    //wall
    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:MovieClip = 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;
    brick.userData.sprite.y = brick.position.y;

    this.brickArray.push(brick);
    }
}

private function reset():void
{
    space.clear();
    setUp();
}

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

添加一条语句,将该链接的MovieClip从这些nape body中删除到reset()函数中。我希望这就是你所需要的:

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