用libgdx绘制纹理多边形 [英] Drawing textured polygons with libgdx

查看:169
本文介绍了用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.

推荐答案

我建议使用网格准确定义您想要的区域。定义顶点并将它们映射到纹理坐标有点繁琐,但知道在某些更高级别的API(如*批处理位)下面发生了什么是很好的。此外,* 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绘制纹理多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆