… I’m trying to add an entity to my world and at the same time add a few clones of it just like this :
i created a class with a function to generate a copy of it, but i don’t know how to use it once added to the world :
public class LineTrap extends Entity
{
[Embed(source = "../../assets/images/trap/ball.png")]
protected static const LINETRAP_ART:Class;
protected var _lineTrap:Image;
protected var enemyNumber:Number;
private const spaceBetween:Number = 10;
public function LineTrap(x:Number=0, y:Number=0, repeated:Number=5)
{
this.x = x;
this.y = y;
_lineTrap = new Image(LINETRAP_ART);
enemyNumber = repeated;
layer = 1;
type = "lineTrap";
}
override public function added():void
{
graphic = _lineTrap;
}
override public function update():void
{
x -= Globals.lineTrapSpeed * FP.elapsed;
if (x < - _lineTrap.width) {
world.recycle(this);
}
}
public function addLineTrap():void {
for (int i = 0; i < enemyNumber; i++ ) {
aCopyOf(this);
}
}
public function aCopyOf(original:Entity) {
this.x = original.x + spaceBetween;
this.y = y;
spaceBetween += _lineTrap.width;
}
}
}