1 decade ago
by riceje7
how would i go about properly subclassing an entity that i have written? i know its possible from the docs (
.getEntitiesByType(). however what i'm doing now isn't working as .getEntitiesByType() returns an empty array.
here is how i'm currently doing it:
#
Enemy Entity
<1>
Subclassed Enemy
#
ig.module('game.entities.robopenguin').requires('impact.entity', 'game.entities.enemy').defines(function() {
EntityRobopenguin = EntityEnemy.extend({...});
});
like i said when i call .getEntitiesByType it returns an empty array, any ideas?
1 decade ago
by riceje7
sorry messed up my post here is the code for
EntityEnemy:
ig.module('game.entities.enemy').requires('impact.entity').defines(function() {
EntityEnemy = ig.Entity.extend({
init: function(x, y, settings){
this.parent(x, y, settings);
},
update: function(){
this.parent();
}
});
});
1 decade ago
by riceje7
sorry for the multiple postings, but i forgot to mention that the entities still show up in the game they just aren&039;t being identified by my call to #.getEntitiesByType(EntityEnemy)
They would show up as EntityRobopenguin and not EntityEnemy. Can you confirm if thats how your calling it? Can you also post the code you're using to refer to this as it may help expose the problem.
1 decade ago
by riceje7
according to the docs (referenced in my first post) they should show up as both EntityEnemy and EntityRobopenguin. Maybe Dominic can confirm this.
Anyways right now i'm just outputting it to the console through this code called in my main.js file:
console.log(this.getEntitiesByType(EntityEnemy));
First, I'd suggest to surround that argument with quotes. Your call is valid but a lighter argument (string vs. class object) makes for a happier client.
Also, you&039;re right; prototype chain inheritance implies that #this.getEntitiesByType('EntityEnemy');
will return all EntityEnemy objects and their descendant class instances as well.
If you can see them in-game, then getEntitiesByType must return something. Only thing I can see: your code. Post some if you can. Will help us help.
1 decade ago
by riceje7
@alexandre - strange thing happened... i put the argument in quotes as you suggested (and which i had started with) and now .getEntitiesByType is returning the proper array. not sure what else changed other than the quotes (i've been fiddling around trying to get it to work). thanks
1 decade ago
by city41
"First, I'd suggest to surround that argument with quotes. Your call is valid but a lighter argument (string vs. class object) makes for a happier client."
Actually passing the type (ie EntityEnemy) is cheaper and faster than passing "EntityEnemy". If you pass a string then getEntityByType must first look up the type in ig.global. In almost all situations it won't matter, but if you are calling getEntityByType a lot (especially in loops), then passing the type will be faster.
Page 1 of 1
« first
« previous
next ›
last »