问题描述
我想知道如何在旋转一个Libgdx textureRegion。
I wonder know how to Rotate a textureRegion in Libgdx.
如果有一个与像素图一isue,你也可以把它给我。
If there is a isue with Pixmap, you can also give it to me.
我不希望使用精灵,因为它不是为appropiate我想要做的事。
I don't want to use sprites because it's not appropiate for the thing I want do.
谢谢你。
推荐答案
它实际上是pretty简单的为90°的倍数旋转textureRegion。
It is actually pretty simple to rotate a textureRegion with multiples of 90°.
一个textureRegion是一个更大的纹理的一部分,具有UV坐标两对夫妇来定义。
为了旋转你的textureRegion,你探微要旋转这些UV坐标。
A textureRegion is a portion of a bigger Texture, defined with two couples of UV coordinates.In order to rotate your textureRegion, you juste have to rotates these UV coordinates.
例如,这里是你原来textureRegion:
For instance, here is you original textureRegion:
(我们假定你的区域是一个正方形,但它会用矩形工作以及)
顺时针旋转90,你只需要已换坐标:
(we're assuming that your region is a square, but it would work with a rectangle as well)To rotate 90 clockwise, you need just have to swap coordinates:
u1 = u1
v1 = v2
u2 = u2
v2 = v1
哪样的:
您可以用概括变换矩阵(旋转,平移,缩放)这个解决方案,但对于90°旋转多次,你只需要交换坐标。
You can generalize this solution with transformation matrix (rotation, translation, scaling), but for 90° multiple rotation, you just need to swap coordinates.
编辑:包含了所有你需要知道更改textureRegion的UV坐标
This page contains all you need you know to change UV coordinates of a textureRegion
这篇关于Libgx旋转纹理区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!