1

I'm trying to figure out what all these arguments do, as when I draw my bullet image it appears as a solid block instead of a sprite that alternates between solid color and an empty portion (i.e instead of 10101 it's 11111, with 0's being empty parts in the texture).

Before, I was using batch.draw(texture, float x, float y) and it displays the texture correctly. However I was playing around with rotation, and this is the version of draw that seemed most suitable:

batch.draw(texture, x, y, originX, originY, width, height, scaleX, scaleY, rotation, srcX, srcY, srcWidth, srcHeight, flipX, flipY)

I can figure out the obvious ones, those being originX, originY (location to draw the image from its upper left pixel I believe) however then I don't know what the x, y coordinate after texture is for.

scaleX,scaleY, rotation, and flipX, flipY I know what to do with, but what is srcX and srcY, along with the srcWidth and srcHeight for?

edit: I played around and figured out what the srcX,srcY and srcHeight,Width do. I can not figure out what originX,Y does, even though I'm guess it's the centerpoint of the image. Since I don't want to play around with this one anyway, should I leave it as 0,0?

What would be common uses for manipulating the centerpoint of images?

Andy Thomas
  • 84,978
  • 11
  • 107
  • 151
ramboCODER
  • 73
  • 9
  • 2
    Well, have you bothered to read the documentation? – OldProgrammer Aug 13 '14 at 16:49
  • No, that's your job. I don't bother to read the documentation, I come and ask for help at stackoverflow, you either help or not depending on whatever reason, and stackoverflow makes money either way. If I read documentation, stackoverflow doesn't make money. get it? – ramboCODER Aug 16 '14 at 20:46

2 Answers2

2

Answering main question.

srcX, srcY, srcWidth, srcHeight are values determine which part (rectangle) of source texture you want to draw. For example, your source image is 100x100 pixels of size. And you want to draw only 60x60 part in a middle of source image.

batch.draw(texture, x, y, 20, 20, 60, 60);

Answering your edited question.

Origin is a center point for rotation and scale transformations. So if you want to your sprite scales and rotates around it's center point you should set origin values so:

float originX = width * 0.5f;
float originY = height * 0.5f;

In case you don't care about rotation and scaling you may not specify this params (leave it 0).

And keep in mind, that origin is not determines image drawing position (this is most common mistake). It means that two next method calls are draw image at same position (forth and fifth params are originX and originY):

batch.draw(image, x, y, 0, 0, width, height, ...);
batch.draw(image, x, y, 50, 50, width, height, ...);
Metaphore
  • 749
  • 1
  • 7
  • 15
1

According to the documentation, the parameters are as defined:

srcX - the x-coordinate in texel space
srcY - the y-coordinate in texel space
srcWidth - the source with in texels
srcHeight - the source height in texels
hofan41
  • 1,438
  • 1
  • 11
  • 25