[Solved] Control recycled entities


(JasperYong) #1

Greetings! I’m currently poking around with recycle entity, but I’m not too sure how to control it without declaring it as a variable. Now Enemy the moves without the bulletGenerator tagging along.

Can anyone give me some example how I can work with this? Thanks :smiley:

public function Enemy()
	public function init(_x:Number, _y:Number):void
	{	
		this.x = _x;
		this.y = _y;
		
		BulletGenerator(FP.world.create(BulletGenerator)).turret_spawn(_x, _y); //declare?
	}
	override public function update():void 
	{
		super.update();
	}

(JasperYong) #2

so after some random testing, i manage to hit the jackpot :stuck_out_tongue:

//declare
public var generator:Entity;

//spawn generator
generator = BulletGenerator(FP.world.create(BulletGenerator)).turret_spawn(_x, _y, 140, 2, 5, 60);

//under update
enemy.x ++;
generator .x = x;