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\$
\$\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– cozmic2016-07-21 13:26:21 +00:00Commented Jul 21, 2016 at 13:26
Add a comment
|
1 Answer
\$\begingroup\$
\$\endgroup\$
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.