使用PolygonSpriteBatch在Libgdx中渲染具有重复纹理的多边形 [英] Render polygon with repeate Texture in Libgdx using PolygonSpriteBatch
本文介绍了使用PolygonSpriteBatch在Libgdx中渲染具有重复纹理的多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想绘制一个具有重复纹理的多边形(例如砖).这是我的代码:
I would like to draw a polygon with repeat texture (e.g brick). Here is my code:
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);
然后我进行绘制(渲染):
and next i draw (render):
public void render(SpriteBatch spriteBatch, PolygonSpriteBatch polygonBatch) {
Gdx.gl.glEnable(GL10.GL_TEXTURE_2D);
polygonBatch.draw(po, 0,0, 512f, 256f);
}
不幸的是,我总是得到用白色填充的多边形.为什么?
Unfortunately, I always gets polygons filled by white colour. Why?
推荐答案
您可能会以此顺序调用代码
You might be calling code in this order
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等可能会导致此类问题,您应该单独使用它们:
Using spriteBatch,polygonBatch, shapeRenders etc together might lead to this type of problem you should use them seperately :
spriteBatch.begin();
spriteBatch.draw(textureRegion, 0, 0, 480, 480);
spriteBatch.end();
polygonBatch.begin();
polygonBatch.draw(polygonRegion, 0,0, 400f, 400f);
polygonBatch.end();
在使用任何其他批次的开始之前,您应该结束上一个批次.
Before using begin of any other batch you should end the previous batch.
这篇关于使用PolygonSpriteBatch在Libgdx中渲染具有重复纹理的多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文