I have created a little game using LibGDX and it uses a SpriteBatch when it renders the game objects. Now I want to add a Touchpad to it, and the draw method of Touchpad takes a Batch as a parameter, but my game uses SpriteBatch. What can I do?
-
\$\begingroup\$ The class SpriteBatch implements the interface Batch, so it is an instance of it that can just be passed as the parameter. This is called polymorphism. \$\endgroup\$ – cozmic Jul 21 '16 at 13:26
Because SpriteBatch
implements Batch
this means it can be used wherever a function requires a Batch
. So when you call Touchpad#draw(batch)
you can give it your SpriteBatch
instance and it will work just fine. You should probably read up on polymorphism in Java.