我正在学习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()
方法。我走在正确的道路上吗?
谢谢。
最佳答案
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();
输出是
现在旋转 90 度:
batch.draw(texture,300,200,50,50,100,100,1,1,90,100,100,50,50,false,false);
所以矩形围绕中心偏移 90 度
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);
关于java - libgdx绘制方法说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45015398/