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?

| improve this question | | | | |
\$\endgroup\$
  • \$\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
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.

| improve this answer | | | | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.