1
\$\begingroup\$

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?

\$\endgroup\$
1
  • \$\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, 2016 at 13:26

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .