how to draw custom shapes using a simple texture in libgdx?(如何使用 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?
推荐答案
根据文档:
SpriteBatch 用于绘制引用纹理(区域)的 2D 矩形
A SpriteBatch is used to draw 2D rectangles that reference a texture (region)
因此,从本质上讲,此方法不允许您指定除矩形之外的任何其他几何图形.但是,有一个 draw 方法 允许您指定矩形"的四个坐标并将其转换为其他东西.您必须将几何体分解为适合此基元的较小部分.看起来这种方法不适合几何形状的变化.
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 中的简单纹理绘制自定义形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 libgdx 中的简单纹理绘制自定义形状?


基础教程推荐
- 从 python 访问 JVM 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- Java Swing计时器未清除 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 大摇大摆的枚举 2022-01-01