LibGdx:在同一批渲染Sprite和PolygonSprite?
对于我的应用程序,我需要在同一帧中渲染精灵(或纹理)和多边形(或网格)。 对于精灵,我在Spritebatch上渲染它们,对于PolygoneSprites,我应该在PolygonSpriteBach上渲染它们。但我真的不能这么做: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.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
接口)