[SOLVED] A simple question, how to clear a vector?


(Bora Kasap) #1

I ask this because i think getType function adding same Entities multiple times into the vector in override update function. Or somebody tell me please why my game getting slower and slower in a few seconds . . . :/?

		world.getType("enemy", elist);
		world.getType("pbullet", pblist);
		for each (var e:Enemy in elist)
		{
		for each (var pb:Bullet in pblist)
		{
			if (pb.collideWith(e,pb.x,pb.y) && !pb.removed())
			{
			pb.hit.play();
			var hitanim:Entity = world.add(new HitAnim());
			hitanim.x = pb.x;
			hitanim.y = pb.y;
			world.remove(pb);
			}
		}
		}

(azrafe7) #2

Yes… getType(), as other get*something* functions of the World class, doesn’t clear the returned array, and purposedly does so (in case you want to build an array of different colliding types).

To fast clear it you simply set to 0 its length property:

var allUnits:Array = [];
FP.world.getType("unit", allUnits);
// use allUnits array here
...
allUnits.length = 0;    // clear allUnits array

(Bora Kasap) #3

Thanks my friend. It worked well.