在movieclip的路径中绘制新对象

时间:2013-09-11 10:35:46

标签: actionscript-3

我正在制作一个带炸弹的平台游戏,其中一个将成为一个动力桶。当玩家放置一个火药桶时,我想要从他放置桶和他移动的地方产生粉末痕迹。我只是动作中的业余爱好者,所以有人建议我如何做到这一点吗?

1 个答案:

答案 0 :(得分:0)

我希望您使用平铺系统进行平台游戏。那么你应该只检查这种粉末占用哪些瓷砖。出于这个原因,我们将使用类TrailPowder,它使用适当的处理方法存储所有粉末精灵。

<强> Tile.as

public class Tile {
    public var x:int;
    public var y:int;

    public function Tile(x:int, y:int) {
        this.x = x;
        this.y = y;
    }
}

<强> Powder.as

import flash.display.Sprite;

public class Powder extends Sprite {
    public var tile:Tile;

    public function Powder(tile:Tile) {
        this.tile = tile;
        this.x = tile.x * TILE_WIDTH;
        this.y = tile.y * TILE_HEIGHT;
    }
}

<强> TrailPowder.as

import flash.display.Sprite;

public class TrailPowder {
    private var parent:Sprite;
    private var powders:Vector.<Sprite> = new Vector.<Sprite>();

    public function TrailPowder(parent:Sprite) {
        this.parent = parent;
    }

    public function addPowderAt(tile:Tile):void {
        if (!isOccupied(tile)){
            var powder:Powder = new Powder(tile)
            this.parent.addChild(powder);
            powders.push(powder);
        }
    }

    public function isOccupied(tile:Tile):Boolean {
        var powder:Powder;
        for each(powder in powders)
            if (powder.tile == tile)
                return true;

        return false;
    }

    public function clear():void {
        while (powders.length)
            parent.removeChild(powders.splice(0, 1)[0]);
    }
}