如何在libgdx中使用简单的纹理绘制自定义形状? [英] how to draw custom shapes using a simple texture in libgdx?

查看:157
本文介绍了如何在libgdx中使用简单的纹理绘制自定义形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的游戏中绘制自定义静态形状,就像愤怒的小鸟一样:

I want to draw custom static shapes in my game just like the angry birds done:

但问题是纹理是方形的。

but the problem is that the texture is in square shape.

我们如何告诉SpriteBatch绘制形状一些顶点?有没有人有想法?

how we can tell to the "SpriteBatch" to draw shapes with some vertices? does anybody has some ideas?

推荐答案

根据 docs


SpriteBatch用于绘制引用纹理的2D矩形(区域)

A SpriteBatch is used to draw 2D rectangles that reference a texture (region)

所以基本上,此方法不允许您指定任何其他几何形状而不是矩形。但是,有一个绘制方法,允许您指定矩形的四个坐标并将其转换为其他坐标。您必须将几何体分解为适合此基元的较小块。看起来这种方法不适合几何变化。

So essentially, this method does not allow you to specify any other geometry than a rectangle. However, there is a draw method that allows you to specify the four coordinates of the "rectangle" and turn it into something else. You'd've to decompose the geometry into smaller pieces that fits this primitives. Looks like this method doesn't lend itself to geometry changes.

更好的你创建一个网格并绘制它。网格不支持三角测量,因此请使用 ObjLoader.loadObj * 方法在 Alias Wavefront OBJ中加载网格格式。指定几何图形不应该是麻烦;该文章链接到一些示例文件。

Better you create a mesh and just draw it. The mesh does not support triangulation, so use the ObjLoader.loadObj* methods to load a mesh in Alias Wavefront OBJ format. Specifying the geometry shouldn't be a hassle; the article links to some example files.

这篇关于如何在libgdx中使用简单的纹理绘制自定义形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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