2

I am learning libgdx, I have passed around some of tutorials but I always face problems understanding the batch.draw() method

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)

I read its documentation and still got confused of the following statement:-

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

WHAT DOES THIS MEAN?. Which origin are talking about here?

Also i did a simple sketch of what I visual understand the draw() method. Am I on the right path? Thanks.

Visual representation of how i understand the draw method

Emmanuel Mtali
  • 4,383
  • 3
  • 27
  • 53
  • the doc also continues with "originX - the x-coordinate of the scaling and rotation origin relative to the screen space coordinates". So, x;y is the lower left hand corner for the image, but the origin is where rotation and scaling applies. So width/2; height/2 would give you originX;originY "centered" in your image and when you rotate or scale an image, it is done "around" originX;originY. (originX and Y are offsets from x and y) – Peter R Jul 10 '17 at 15:28

1 Answers1

2

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

Scaling and Rotation performed around originX, originY.

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

And Output is

enter image description here

Now rotate by 90 degree :

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

so rectangle offseted around centre by 90 degree

enter image description here

originX and originY is in the center of Rectangle so no offset appears in x,y

Let's put originX and originY at left bottom of rectangle and rotate by 90 degree

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

enter image description here

Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65