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 OMATASE

I have a menu entity which needs to display more than one animation. I have encapsulated a character preview functionality in its own entity. The menu entity needs to show more than one character preview (which is an animation). I have the menu entity call ig.game.SpawnEntity() to create the previews as needed.

What is the best way to remove these preview entities as my menu entity is getting removed? I looked but didn't see a method that ig.game calls when doing a removeEntity call.

Thanks

1 decade ago by dominic

.spawnEntity returns the entity that was just created. You can use this to keep track of the entities you spawn from your menu to remove them again later.

previewEntities: [],

createrCharacterPreviews: function() {
	var ent = ig.game.spawnEntity( EntityPreview, x, y );
	this.previewEntities.push( ent );
	…
},

kill: function() {
	// kill the menu itself
	this.parent();
	
	// kill all entities that belong to that menu
	for( var i = 0; i < this.previewEntities.length; i++ ) {
		this.previewEntities[i].kill();
	}
}
Page 1 of 1
« first « previous next › last »