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 Gommeth

Solved previous issue but now I have a new one: I'm trying to do a melee detection by using distanceTo but I can't find out how or where to get the entities of both the enemies, preferably using getEntitiesByType, and the hero, using getEntityByName.

Anyone have any advice on how or where to be able to call these methods? Everywhere I try it seems it just says that MyGame or game is unreferenced, doesn't contain method, etc

1 decade ago by dominic

MyGame is just the (default) name of your game class. When you call ig.main() it creates an instance of that class - you can access that instance from anywhere using ig.game.

E.g. you could do the following in your enemy entity:

update: function() {
	this.parent();
	
	var hero = ig.game.getEntityByName('name');
	if( hero ) {
		var dist = this.distanceTo( hero );
		// ... do something with 'dist' here
	}
}
Page 1 of 1
« first « previous next › last »