Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by John

So I'm making a game where I spawn the same enemy over and over again, but I'm having trouble with the .kill function killing all of them when one gets hit. Any ideas what I'm doing wrong?

spawn code:


if(canSpawn == true){

			var sy = Math.floor(Math.random() * ig.system.height - 55) + 55;

			var sx = ig.system.width + 50;

			ig.game.spawnEntity(EntityChicken,sx,sy);

			canSpawn = false;

			setTimeout(function(){ canSpawn = true; }, 1000);

		}


kill code:


if(killMe == true){

            this.kill();

        } 

1 decade ago by stuckie

Amusingly, I had this exact same issue in Grim's Christmas List... it was due to having a timer created outside the Entity's init function so it ended up global to all the entities of that type - so when it triggered for one entity, it triggered for them all.

Maybe it's the same kind of problem?
I fixed it by creating the timer in the init function instead, so that it was unique for each instance.

1 decade ago by John

Thanks stuckie, the problem is now resolved.
Page 1 of 1
« first « previous next › last »