Drawing textured polygons with libgdx(使用 libgdx 绘制带纹理的多边形)
问题描述
我使用 libgdx 的渲染周期有问题,基本上我需要用方形纹理填充一个区域,而这个区域的最后一部分可能比纹理更小或形状不同,所以这意味着我需要渲染一个任意形状的四边形并在其上贴上纹理,切割我不需要的部分.
I'm having a problem with my rendering cycle using libgdx, basically I need to fill an area with a square texture, and the last part of this area may be smaller or with a different shape than the texture, so it means that i need to render a quad of arbitrary form and slap the texture on it, cutting the parts I don't need.
我对如何做到这一点有点迷茫,到目前为止,我已经看到 PolygonRegion 和 PolygonSpriteBatch 可能会为我做这件事,但我对实例化一个我只会使用的新重物有点警惕在一个物体上.
I'm a bit lost on how to do this, so far I've seen that the PolygonRegion and PolygonSpriteBatch might do it for me, but I'm a bit wary of instancing a new heavy object I'll use only on one object.
还有其他选择吗?也许是 Mesh 类,但我想确定.
Is there any alternative? Perhaps the Mesh class but i'd like to be certain.
推荐答案
我建议使用 Mesh
来准确定义您想要的区域.定义顶点并将它们映射到纹理坐标有点繁琐,但很高兴知道一些更高级别的 API(如 *Batch 位)下面发生了什么.此外,*Batch API 旨在共享跨多个对象上传单个纹理的权重,这听起来可能不适用于这种情况.(另一方面,即使 Batch 对象有点重量级",在实践中它们实际上也可能不是问题.)
I suggest using a Mesh
to define exactly what region you want. Defining the vertex points and mapping those to the texture coordinates is a bit fiddly, but its good to know what's going on underneath some of the higher level APIs (like the *Batch bits). Additionally, the *Batch APIs are designed to share the weight of uploading a single texture across multiple objects, which sounds like it might not apply in this case. (On the other hand, even if the Batch objects are a bit "heavyweight", they may not actually be a problem in practice.)
要考虑的另一种方法是将对象渲染为方形网格,但为区域外的所有像素定义透明像素的纹理.(我假设非方形是您可以离线知道的,并且不是动态的.)
Another approach to consider is to render the object as a square mesh, but to define your texture with transparent pixels for all the pixels outside the region. (I'm assuming the non-square shape is something you can know offline, and isn't dynamic.)
这篇关于使用 libgdx 绘制带纹理的多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 libgdx 绘制带纹理的多边形
基础教程推荐
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01