I have a Texture sheet that was created with a texture packer app, it removes all of the unnecessary transparent pixels to save space in the final texture sheet. The problem is my animation is a guy with a sword, so when he attacks he swings the sword over his head, meaning it changes the width and height of the sprite. Example...
characterAttack1 = new TextureRegion(texture, 863, 979, 152, 149);
//more animation frames...
characterAttack8 = new TextureRegion(texture, 1, 2, 340, 256);
As you can see the first frame is 152x149, but by the 8th frame it is now 340x256. So when the animation runs if I use the normal getWidth() getHeight() methods within my Character class the character will shrink as he attacks, since the height and width of the attack is larger as the sword swings. On the other hand if I use the method...
((TextureRegion)AssetLoader.characterAttack.getKeyFrame(runTime)).getRegionWidth();
and
((TextureRegion)AssetLoader.characterAttack.getKeyFrame(runTime)).getRegionHeight();
The character will bounce around the screen when the attack animation is run. I know I can't be the only person that has encountered something like this, but I can't seem to find any information on this. Is my only course of action to repack the texture file and make each one the same width and height even though there will be a ton of transparent pixels in the final packed texture?
If you need to see the AssetLoader and the batcher.draw methods or anything else I am more than happy to provide code samples, I am just trying to keep the post from being too large. Thank you.
Unless you are tying to make your game run on something with extremely low RAM, there is really no need to pack the textures so tightly. Sprite sheets are really quite small when you think about the grand scale of things. I imagine your game would require around 100MB of RAM when running, given that most computers now have upwards of 4GB of RAM, what's a few more MB?
A sprite-sheet for your character should be the maximum size of any one of the frames. e.g. If the largest frame is 340x256, every frame needs to be that size.
Now the character will be in the same position every frame because the render position will not change.
If the centre of the character is always in the middle of the sprite, you could render from the centre of the image, which would fix your problem.