libgdx:使用spritebatch绘制纹理时旋转纹理

ved*_*boy 12 textures rotation libgdx

我在绘制时试图旋转纹理.我认为这样做比在paint.net中将图像旋转90度并将它们保存在不同的文件中更有意义.我看了想spritebatch绘图参数的api文档,但我只是不明白.有一堆参数,如srcX,srcY,originX等.另外我想知道如何对纹理区域做同样的事情.下面是api文档页面的链接:http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/SpriteBatch.html

谢谢!

cle*_*m23 61

再次从文档,但复制在这里易于使用,所以我可以解释一点.

x - the x-coordinate in screen space
y - the y-coordinate in screen space
Run Code Online (Sandbox Code Playgroud)

这两个值表示在屏幕空间(游戏空间)中绘制纹理的位置.非常自我解释.

originX - the x-coordinate of the scaling and rotation origin relative to the screen space coordinates
originY - the y-coordinate of the scaling and rotation origin relative to the screen space coordinates
Run Code Online (Sandbox Code Playgroud)

这两个值表示相对于屏幕空间发生旋转(和缩放)的位置.因此,例如,如果你在这里给出值0,0,旋转和缩放将发生在纹理的一个角上(我相信左下角),而如果给出中心(宽度/ 2,高度/ 2) ),旋转和缩放将发生在纹理的中心周围(这可能是你想要的任何"正常"旋转)

width - the width in pixels
height - the height in pixels
Run Code Online (Sandbox Code Playgroud)

在屏幕上绘制纹理的尺寸.

scaleX - the scale of the rectangle around originX/originY in x
scaleY - the scale of the rectangle around originX/originY in y
Run Code Online (Sandbox Code Playgroud)

表示矩形比例的值,其中0到1之间的值将缩小矩形,大于1的值将扩展矩形.请注意,这与您之前提供的原点有关,这意味着如果这不是中心,则图像可能看起来变形.

rotation - the angle of counter clockwise rotation of the rectangle around originX/originY
Run Code Online (Sandbox Code Playgroud)

旋转图像的角度.同样,这是在前面给出的原点附近,因此如果原点不是图像的中心,则旋转可能不会显示为"正确"

srcX - the x-coordinate in texel space
srcY - the y-coordinate in texel space
Run Code Online (Sandbox Code Playgroud)

这两个值是您希望使用的图像文件(.png,.jpg,等等)的实际区域的起始位置(以像素为单位).基本上是你的形象的开始.

srcWidth - the source with in texels
srcHeight - the source height in texels
Run Code Online (Sandbox Code Playgroud)

同样,这两个值是您正在使用的图像文件的实际区域的宽度和高度,以像素为单位.

flipX - whether to flip the sprite horizontally
flipY - whether to flip the sprite vertically
Run Code Online (Sandbox Code Playgroud)

最后,这两个布尔值用于水平或垂直翻转图像.

现在您可能会注意到,绘制TextureRegions的类似方法没有srcX,srcY,srcWidth或srcHeight.这是因为当您从纹理创建纹理区域时,这些值是您为纹理区域赋予.

基本上这意味着命令

//with TextureRegions
SpriteBatch.draw(textureRegion, x, y, originX, originY, width, height, scaleX, scaleY, rotation);
Run Code Online (Sandbox Code Playgroud)

相当于

//with Textures from TextureRegions
SpriteBatch.draw(textureRegion.getTexture(), x, y, originX, originY, width, height, scaleX, scaleY, rotation, textureRegion.getRegionX(), textureRegion.getRegionY(), textureRegion.getRegionWidth(), textureRegion.getRegionHeight(), false, false);
Run Code Online (Sandbox Code Playgroud)