LibGdx:在同一批渲染Sprite和PolygonSprite?

LibGdx:在同一批渲染Sprite和PolygonSprite?,libgdx,sprite,spritebatch,Libgdx,Sprite,Spritebatch,对于我的应用程序,我需要在同一帧中渲染精灵(或纹理)和多边形(或网格)。 对于精灵,我在Spritebatch上渲染它们,对于PolygoneSprites,我应该在PolygonSpriteBach上渲染它们。但我真的不能这么做: spriteBatch.begin() spritebatch.draw(sprite) ... spriteBatch.end() polygonSpritebatch.begin() polygonSpritebatch.draw(polygonSprite)

对于我的应用程序,我需要在同一帧中渲染精灵(或纹理)和多边形(或网格)。 对于精灵,我在Spritebatch上渲染它们,对于PolygoneSprites,我应该在PolygonSpriteBach上渲染它们。但我真的不能这么做:

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

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

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

etc...
那么,有办法吗? 附加图像以查看我想要的内容


非常感谢

简短回答:

您可以使用
PolygonSpriteBatch
绘制
Sprite
以及
PolygonSprite
如下所示:

polygonSpriteBatch.begin();

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

polygonSpriteBatch.begin();
polygonSprite.draw(polygonSpriteBatch);
详细描述:

绘制
Sprite
PolygonSprite
与问题中的示例代码有点不同。既然
SpriteBatch
都没有方法
draw(Sprite)
或者
polygonstritbatch
都没有方法
draw(polygonstrite)
你就不能做
SpriteBatch.draw(Sprite)

方法如下:

polygonSpriteBatch.begin();

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

polygonSpriteBatch.begin();
polygonSprite.draw(polygonSpriteBatch);
现在,由于采用了
PolygonSpriteBatch
作为参数,因此无法将
SpriteBatch
传递给此方法

但是由于将对象作为参数,因此可以传递
SpriteBatch
PolygonSpriteBatch
作为参数(因为这两个类都实现了
Batch
接口)