Hi all,
Does anyone know if I have a parent object definition which has entity pooling enabled, do any child objects which are extended from it inherit the pooling? Or do you need to define explicitly for each object definition in a hierarchy?
Thanks for any help!
10 years ago
by TC
An entity will not inherit object pooling from the entity it extends.
You will need to enable it individually for each entity class that you require using:
ig.EntityPool.enableFor( EntityBullet );
(make sure the above goes outside of the entities extend function)
Fantastic, thank you very much for the help.
10 years ago
by Seeders
Hmm, I seem to be getting entities reborn without the correct default values for their class. I have a bunch of terrain tile types with different movement speed values. When I enable pooling, I start getting terrain with incorrect values for the type. This is with each class individually enabled.
10 years ago
by TC
I have just dived into the source code and it turns out an entity will indeed inherit object pooling if it is enabled on a class it extends.
This works because of how the code is using the class inject system.
However it would make no difference also enabling it for each entity individually, and in my personal opinion creates cleaner code as your are not relying on whether a parent entity has it enabled or not.
@Seeders, if you you go to the docs page
http://impactjs.com/documentation/entity-pooling
Have a look at the reset method on the entity.
Any custom code in your entities init will also need to be added to the reset method so it resets values when the object is pulled from the pool.
10 years ago
by Seeders
I actually just made a single function called doInit(), and in my init and reset methods, i just call doInit(). So I do have the same code in there, but what I was describing was my default values to properties.
EntityForest = EntityTerrain.extend({
name: "forest",
zOrder: 5,
type: 4,
baseFrame: { x: 416, y: 32 },
buildable: true,
numFrames: 7,
structureType: EntityTree,
structureChance: 20,
default_modifiers : {
movement_speed: .8,
pathCost: 1
},
modifiers : {
movement_speed : .8,
pathCost : 1
}
});
So this is a forest tile. It doesn't have an init function because that is all at the EntityTerrain level. However, none of these values are kept when the tile is reset (except for name?). To fix this I have to assign all the values to a hash, which defeats the purpose of having these classes defined at all.
Page 1 of 1
« first
« previous
next ›
last »