2

For my application, I need to render sprites (or textures) and PolygonSprites (or Mesh) in the same frame. For the sprites, I render them on a Spritebatch, and for the PolygoneSprites, I should render them on a PolygonSpritebatch. But I really can't do that :

spriteBatch.begin()
spritebatch.draw(sprite)
...
spriteBatch.end()

polygonSpritebatch.begin()
polygonSpritebatch.draw(polygonSprite)
...
polygonSpritebatch.end()

spriteBatch.begin()
spritebatch.draw(sprite)
...
spriteBatch.end()

etc...

So, is there a way ? Image is attached to see what i want.

Sprite & PolygonSprite

Thank's a lot !

Dudule
  • 51
  • 2

1 Answers1

2

Short Answer:

You can use a PolygonSpriteBatch to draw a Sprite as well as a PolygonSprite like this:

polygonSpriteBatch.begin();

sprite.draw(polygonSpriteBatch);
polygonSprite.draw(polygonSpriteBatch);

Longer Description:

Drawing a Sprite or a PolygonSprite is done a bit different from the example code in your question. Since neither SpriteBatch has a method draw(Sprite) nor PolygonSpriteBatch has a method draw(PolygonSprite) you can't do spriteBatch.draw(sprite).

The way to do this would be like this:

spriteBatch.begin();
sprite.draw(spriteBatch);

polygonSpriteBatch.begin();
polygonSprite.draw(polygonSpriteBatch);

Now since PolygonSprite.draw takes a PolygonSpriteBatch as a parameter, you won't be able to pass a SpriteBatch to this method.

But since Sprite.draw takes a Batch object as argument, you can pass either a SpriteBatch or a PolygonSpriteBatch as the parameter (since both of these classes implement the Batch interface).

Tobias
  • 2,547
  • 3
  • 14
  • 29