I'm creating an android game that uses an Entity object class that is then extended in many different types (i.e. enemies, bullets, etc). Is there a way to create a pool of type Entity and then transform the obtained Entity objects into whatever I need at runtime (say a bullet type)? Passing the entity as an argument to a constructor will just defeat the purpose of the pool correct? An example is below:
public class EntityPool extends Pool<Entity> {
public EntityPool (int initialCapacity, int max) {
super(initialCapacity, max);
}
protected PooledEntity newObject () {
return new PooledEntity();
}
public Entity obtain (int objectType) {
Entity ent = super.obtain();
if (objectType==SOME_OBJECT_TYPE)
//Do something to make ent into that object type
return ent;
}
public class PooledEntity extends Entity {
PooledEntity () {
super(null, 0, 0);
}
public void free () {
EntityPool.this.free(this);
}
}
}