1
\$\begingroup\$

Thing is, I've used darkFunction Editor as a way to get all the spriteCoordinates off a spriteSheet for each individual sprite, and parse the .xml it generates inside my game. It all works fine, except when the sprites are all similarly sized, but when a sprite changes from a small sprite into a big one, such as here:

http://www.wiizelda.net/images/oos/Link.png

When from walking from some direction, to attacking, it starts "jumping", appearing glitchy, because it's not staying in the same correct position, only doing so for the right attacking sprite, due to the drawing being made from the lower left part of the rectangle.

I think someone experienced will immediately recognize the problem I mean, if not, when I return home soon, I will shoot a little youtube video demonstrating the issue!

So the question is: what possible solutions are there? I've thought that some sort of individual frame "offset" system might be the answer, or perhaps splitting, in this case, the sprite in 2: the sword, and the character itself, and draw sword according to character's facing, but that might be overly complex. Another speculation would be that there might be some sort of method in LibGdx, the library I'm using, that allows me to change the drawing center (which I looked for and didn't find), so I could choose from where the drawing starts.

\$\endgroup\$
4
  • 3
    \$\begingroup\$ For small projects, I have always overcome the issue by setting the sprite size to the largest sprite available and aligning all properly (on sheet). Other option is to, yes, store offsets and displace on draw. \$\endgroup\$ May 31, 2013 at 8:15
  • 3
    \$\begingroup\$ There are lots of solutions. You've already identified 3. Is there a problem with any of the solutions you're looking at that you have a specific problem with? \$\endgroup\$
    – Tetrad
    May 31, 2013 at 8:18
  • \$\begingroup\$ Yes, several: as for the suggestion above of aligning the sprite to it's biggest possible size, it's what I used to do, but I found myself losing so much time aligning every pixel of all the animations of all the sprites... very time consuming, which i against what I had tried to do, save time, by selecting sprites in darkFunctionEditor, and parsing the .xml. And another huge drawback of this: my hitboxes ARE the sprite sizes, the way I have this designed. (sort of a placeholder, but still) Offset - huge complications, hitbox issues again, loads changes... \$\endgroup\$
    – parreirat
    May 31, 2013 at 12:55
  • \$\begingroup\$ As for the one pertaining changing the way LibGdx draws, from where, can't find how to do so/if it is possible, and as for the one that is about splitting sprites, that's likely the biggest, most messiest solution of all and would only work in specific cases such as this where I had one big thing I can consider a sole "sprite" sticking out of the character's rectangle, so to say. \$\endgroup\$
    – parreirat
    May 31, 2013 at 12:56

1 Answer 1

2
\$\begingroup\$

To "choose from where the drawing starts" in libgdx, you use the function:

batch.draw(texture, x, y, srcX, srcY, srcWidth, srcHeight)

where (x,y) is the onscreen coordinate you want to start drawing at, and (srcX,srcY) is the texture coordinate you would like to draw from.

\$\endgroup\$
1
  • \$\begingroup\$ Better yet, LibGDX comes with texture packing tools in which you can identify how to handle sprite area. \$\endgroup\$
    – Sidar
    Sep 1, 2013 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .