java - libgdx绘制方法说明

标签 java libgdx

我正在学习libgdx,我已经通过了一些教程,但我总是遇到理解batch.draw()方法的问题

public void draw(Texture texture,
                 float x,
                 float y,
                 float originX,
                 float originY,
                 float width,
                 float height,
                 float scaleX,
                 float scaleY,
                 float rotation,
                 int srcX,
                 int srcY,
                 int srcWidth,
                 int srcHeight,
                 boolean flipX,
                 boolean flipY)

我读了它的documentation仍然对以下陈述感到困惑:-

The rectangle is offset by originX, originY relative to the origin.

这是什么意思?这里谈论的是哪个起源?

我还画了一个简单的草图,以直观地了解 draw() 方法。我走在正确的道路上吗? 谢谢。

Visual representation of how i understand the draw method

最佳答案

The rectangle is offset by originX, originY relative to the origin.

围绕originX、originY执行缩放和旋转。

batch.begin();
batch.draw(texture,300,200,50,50,100,100,1,1,0,100,100,50,50,false,false);
batch.end();

输出是

enter image description here

现在旋转 90 度:

batch.draw(texture,300,200,50,50,100,100,1,1,90,100,100,50,50,false,false);

所以矩形围绕中心偏移 90 度

enter image description here

originX和originY位于矩形的中心,因此x,y中没有出现偏移

让我们将originX和originY放在矩形的左下角并旋转90度

batch.draw(texture,300,200,0,0,100,100,1,1,90,100,100,50,50,false,false);

enter image description here

关于java - libgdx绘制方法说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45015398/

相关文章:

具有持续通信功能的 Java 套接字

java - 使用 apache poi 将 HSSF(excel) 嵌入到 HSLF(ppt) 中

Java:所有派生类必须实现的抽象或通用列表

android - 如何实现室内地图

java - 将 firebase 添加到使用 gradle 构建的 libgdx 项目

java - Spring Boot Security - 默认映射的匿名用户访问/

java - Spring + Hibernate 应用程序中的问题 : org. hibernate.HibernateException: No Session found for current thread

java - 如何在android中添加 'java.awt.geom'类?

java - Libgdx : . for 循环内的 Flip()

java - LibGDX 圆形渲染