gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:59:18 26 4
gpt4 key购买 nike

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

谢谢!

最佳答案

再次from the documentation ,但为了便于使用而复制到这里,所以我可以更好地解释一下。

x - the x-coordinate in screen space
y - the y-coordinate in screen space

这两个值表示在屏幕空间(游戏空间)中绘制纹理的位置。非常不言自明。
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

这两个值表示相对于屏幕空间发生旋转(和缩放)的位置。因此,例如,如果您在此处指定值 0, 0,则旋转和缩放将发生在纹理的一个角(我相信是左下角)周围,而如果您将中心 (width/2, height/2 ),旋转和缩放将围绕纹理中心发生(这可能是您想要的任何“正常”旋转)
width - the width in pixels
height - the height in pixels

在屏幕上绘制纹理的尺寸。
scaleX - the scale of the rectangle around originX/originY in x
scaleY - the scale of the rectangle around originX/originY in y

表示矩形比例的值,其中 0 和 1 之间的值将缩小矩形,大于 1 的值将扩展矩形。请注意,这是关于您之前给出的原点,这意味着如果这不是中心,则图像可能看起来失真。
rotation - the angle of counter clockwise rotation of the rectangle around originX/originY

旋转图像的角度。同样,这是围绕先前给出的原点,因此如果原点不是图像的中心,旋转可能不会显得“正确”
srcX - the x-coordinate in texel space
srcY - the y-coordinate in texel space

这两个值是您希望使用的图像文件(.png、.jpg 等)的实际区域的起始位置,以像素为单位。基本上是你的形象的开始。
srcWidth - the source with in texels
srcHeight - the source height in texels

同样,这两个值是您正在使用的图像文件实际区域的宽度和高度,以像素为单位。
flipX - whether to flip the sprite horizontally
flipY - whether to flip the sprite vertically

最后,这两个 bool 值用于水平或垂直翻转图像。

现在您可能会注意到类似的 method for drawing TextureRegions没有 srcX、srcY、srcWidth 或 srcHeight。这是因为那些是 values you give to a texture region when you create it from a texture .

基本上这意味着命令
//with TextureRegions
SpriteBatch.draw(textureRegion, x, y, originX, originY, width, height, scaleX, scaleY, rotation);

相当于
//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);

关于rotation - libgdx:使用 spritebatch 绘制纹理时旋转纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24748350/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com