1 decade ago by quidmonkey
In collideWith() or check() it would be helpful to know the Object type or name of the other parameter. I'd rather not have to loop through a switch() of instanceof's for all Entity types I have defined. Any ideas?
This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact
name: "glider", ...
if (other.name == "glider"){
//There is a match so do whatever needs to be done here
}
if( other.name == "glider" ) { ... }
if( other instanceof EntityGlider ) { ... }
alert('instance ' + EntityGlider.instance);
039;s an #instanceof which is probably suitable for most cases as you are indicating. I came across this issue when I was trying to get the string value of javascript object names and that was the only workaround I could find.
FooClass = ig.Class.extend({});
BarClass = FooClass;
foo = new FooClass();
foo instanceof FooClass; // true
foo instanceof BarClass; // true
// fictional:
foo.getClassName(); // Which one is it? 'FooClass' or 'BarClass'?
spawnEntity() method in your game class (untested):
spawnEntity: function( type, x, y, settings ) {
var ent = this.parent( type, x, y, settings );
ent.className = typeof(type) === 'string'
? type
: 'unknown';
return ent;
},
.className property. However, you have to restrict yourself to always call spawEntity() with the class name as string, instead of with the class itself. E.g.:var g1 = ig.game.spawnEntity( 'EntityGlider', x, y ); g1.className; // EntityGlider var g2 = ig.game.spawnEntity( EntityGlider, x, y ); g2.className; // unknown