Actionscript 3精灵用alpha清除

时间:2014-12-06 22:28:44

标签: flash actionscript adobe

我想用0.1透明度清除精灵,但是sprite.graphics.clear()没有那个选项。它需要每帧不断清理。我怎样才能做到这一点?我尝试在整个舞台上使用填充矩形,透明度为0.1,但我的游戏每帧都在放慢速度。

1 个答案:

答案 0 :(得分:0)

可能你应该将所有精灵放入Vector中,然后在需要时手动删除它们。

    private var vec:Vector.<Sprite> = new Vector.<Sprite>();

    private function update():void
    {
        // reduce the alpha of all other sprites
        // check all other sprites from the newest to the oldest (so we can make a splice without getting an index error in case of there is other sprites to remove)
        for(var i:int = this.vec.length -1; i >=  0; i--)
        {
            this.vec[i].alpha -= 0.1;

            if(this.vec[i].alpha == 0)
            {
                if(this.contains(this.vec[i]))
                {
                    this.removeChild(this.vec[i]);
                }

                // we clear the sprite so it doesn't use any memory
                this.vec[i].graphics.clear();

                // remove the sprite from the vector
                this.vec.splice(i,1);
            }
        }

        // create and draw the new sprite you want to add
        var addingSprite:Sprite = new Sprite();
        addingSprite.graphics.beginFill(0x005500);
        addingSprite.graphics.drawCircle(0, 0, 10);

        this.addChild(addingSprite);                    // add the sprite to the stage

        this.vec.push(addingSprite);                    // add the sprite to the vector so you can reduce his alpha easily
    }