【问题标题】:Render polygon with repeate Texture in Libgdx using PolygonSpriteBatch使用 PolygonSpriteBatch 在 Libgdx 中渲染具有重复纹理的多边形
【发布时间】:2013-09-26 08:03:34
【问题描述】:

我想绘制一个具有重复纹理的多边形(例如砖块)。这是我的代码:

textureBrick = new Texture(Gdx.files.internal("data/brick.png"));
textureBrick.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);


TextureRegion texreg = new TextureRegion(textureBrick,0,0,1f,1f);
texreg.setTexture(textureBrick);
PolygonRegion po = new PolygonRegion(texreg, floatvertices);

接下来我绘制(渲染):

public void render(SpriteBatch spriteBatch, PolygonSpriteBatch polygonBatch) {
    Gdx.gl.glEnable(GL10.GL_TEXTURE_2D);
    polygonBatch.draw(po, 0,0, 512f, 256f);
}

不幸的是,我总是得到用白色填充的多边形。为什么?

【问题讨论】:

  • 您的代码看起来不错...请提供更多代码以找出问题所在。还提供您从当前夜间 0.9.9 开始使用的 LIBGDX 版本,此代码将无效,因为多边形区域在夜间也采用三角形。我假设您将只使用多边形精灵批处理,并且在 polygonbatch.begin() 和 polygonbatch.end() 之间完成渲染

标签: opengl textures libgdx


【解决方案1】:

您可能会按此顺序调用代码

spriteBatch.begin();
spriteBatch.draw(textureRegion, 0, 0, 480, 480);
polygonBatch.begin();
polygonBatch.draw(polygonRegion, 0,0, 400f, 400f);  
polygonBatch.end();
spriteBatch.end();

同时使用 spriteBatch、polygonBatch、shapeRenders 等可能会导致此类问题,您应该单独使用它们:

spriteBatch.begin();
spriteBatch.draw(textureRegion, 0, 0, 480, 480);
spriteBatch.end();
polygonBatch.begin();
polygonBatch.draw(polygonRegion, 0,0, 400f, 400f);  
polygonBatch.end();

在使用任何其他批次的开始之前,您应该结束前一个批次。

【讨论】:

  • 使用spriteBatch和polygonBatch分别绘制多边形作品后
  • 我可以只使用多边形批处理来完成所有的绘图吗?或者单独使用 spriteBatch 和多边形批处理有什么好处?
猜你喜欢
  • 2015-07-20
  • 1970-01-01
  • 1970-01-01
  • 2015-09-10
  • 1970-01-01
  • 2012-11-25
  • 1970-01-01
  • 1970-01-01
  • 2014-10-28
相关资源
最近更新 更多