Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
3  
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. –  joltmode May 31 '13 at 8:15
3  
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? –  Tetrad May 31 '13 at 8:18
    
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... –  GigaBass May 31 '13 at 12:55
    
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. –  GigaBass May 31 '13 at 12:56

1 Answer 1

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.

share|improve this answer
    
Better yet, LibGDX comes with texture packing tools in which you can identify how to handle sprite area. –  Sidar Sep 1 '13 at 14:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.