1 decade ago by Aitor
I have injected to the Entity class so that It calls a method each frame passing itself as a parameter. This is de code (It's not the real code, but it is similar):
And It works fine if I only acces properties like pos or vel of the entity from the function that is called. But some entities have a flying property, and I want to know if that property is true. So i do this in the called function (It's in ig.game):
But "flying" is never printed, even If the flying property is true. Does this happen because I pass
P.D: I've tried calling a method of the subclass instead of accesing a property, and it works. For example, I can do this:
and
ig.Entity.inject({ funcToCall:undefined, update:function() { if (funcToCall) funcToCall(this); this.parent(); } }
And It works fine if I only acces properties like pos or vel of the entity from the function that is called. But some entities have a flying property, and I want to know if that property is true. So i do this in the called function (It's in ig.game):
testFunc:function(entity) { if (entity.flying) { console.log("flying"); } }
But "flying" is never printed, even If the flying property is true. Does this happen because I pass
this
as a parameter in an injected method of Entity, and I can&039;t acces the subclass's properties? But if I do #entity instanceof EntitySubclass
(replacing EntitySubclass with the kind of the entity that has the flying property) it returns true. So why I can't acces the flying propertyP.D: I've tried calling a method of the subclass instead of accesing a property, and it works. For example, I can do this:
testFunc:function(entity) { if (entity.aMethodOfTheSubclass) { aMethodOfTheSubclass(); } }
and
aMethodOfTheSubclass
is called