The pool contains instances of a specific type. Say it has 10 objects in it, those are going to be 10 specific Projectile
instances, you cannot decide which type the object is after you extract it from the pool.
There are two ways to solve this, at least:
- Use multiple pools, one per bullet type. You can put a wrapper around the pools that knows which one to use based on a typed parameter. This is probably not that bad of a solution. An empty pool isn't a big deal. You may have retention problems if some class of projectile is used for a while, and then isn't used (its pool will still be full).
- Make your
Projectile
sub-types a run-time specialization, not a subclass. So you just have aProjectile
class that stores stuff common to all your bullets, and figure out the behavior difference at run-time. See Using Object Pools in Libgdx.