我正在制作一个带有炸弹的平台游戏,其中一个将是一个火药桶。当玩家放置火药桶时,我想从他放置火药桶的位置和移动的位置生成一条粉末轨迹。我只是动作脚本的业余爱好者,所以有人对我如何做到这一点有建议吗?
问问题
69 次
1 回答
0
我希望您在平台游戏中使用瓷砖系统。然后你应该只检查哪些瓷砖被这种粉末占据。出于这个原因,我们将使用 TrailPowder 类,它使用适当的处理方法存储所有粉末精灵。
瓷砖.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;
}
}
粉末状
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]);
}
}
于 2013-09-11T12:20:40.793 回答