0

我已将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();
}

任何帮助将不胜感激

4

1 回答 1

0

添加一条语句,将链接的 MovieClip 从这些颈背主体中删除到您的reset()函数中。我希望这是您需要的:

private function reset():void
{
    if (contains(brick.userData.sprite)) removeChild(brick.userData.sprite);
    space.clear();
    setUp();
}
于 2013-03-28T13:28:27.683 回答