In my game bullets are constantly created, therefore I want to use Pool
class for this. However, the problem is that I have many types of bullets. All of them extend the same parent class Projectile
. Currently there are 19 types of bullets. It's a bad idea to create a Pool
class for each of them. And more may come later.
I tried to cast BallistaArrow arrow = (BallistaArrow) world.getPool().obtain();
. However I'm getting cast exception:
[..].mygame.Projectile cannot be cast to [...].mygame.engineer.BallistaArrow
.
BallistaArrow is the child class of Projectile.
Is there any way to solve this problem, so that I can have one Pool
class for all Projectile
extending objects?