# Aligning animation frame assets with different sizes

I have code that changes texture in each frame depending on the player's state - walking, idle.

My problem is that the idle texture (from separate png) has a slightly different size, and due to that it appears not in line with rest of the animations, seemingly being in a slightly different position when returning to idle.

How can I position the frames based on the center of texture instead of the bottom left?

batch.draw(determineTexture(), position.x, position.y,
currentFrame.getRegionWidth()/2f, currentFrame.getRegionHeight()/2f,
currentFrame.getRegionWidth(), currentFrame.getRegionHeight(),1f,1f, rotation,false);

TextureRegion determineTexture(){
if(playerState == State.idle)
currentFrame = idleAnimation.getKeyFrame(stateTime, true);
else if (playerState == State.walkingUP || playerState == State.walkingDOWN || playerState == State.walkingRIGHT || playerState == State.walkingLEFT )
currentFrame = walkAnimation.getKeyFrame(stateTime, true);
return currentFrame;
}


One png has a height of 57 - idle, while 6 columns and one row of walking frames have a height of 87 pixels.

• Why don't you make them the same size? – Vaillancourt Jul 25 '19 at 23:08
• – DMGregory Jul 25 '19 at 23:27
• @AlexandreVaillancourt Tried it just resizing png with this ps2pdf.com/resize-png but now image is blurry and visibly bigger by ~ 25 % from other frames of animation. Its just that walking animation has arms spread wider and its bigger in resolution size thanks to that. – new User Jul 26 '19 at 8:03
• @DMGregory a bit simillar at first glance thanks, but not really useful :(. Shame i really struggle right now because that free asset pack looks cool and i wonder if thats me doing something wrong or i should look for new asset pack because you cant have two different heights. – new User Jul 26 '19 at 8:07
• What force in the universe prevents you from having two different heights? Just offset your draw position accordingly, using a defined hotpoint/pivot you've defined each frame. This is addition and subtraction, not the halting problem. – DMGregory Jul 26 '19 at 8:20

SOLVED ! I have modified the code as follows: instead of just position.x and position.y as arguments in SpriteBatch.draw() i modified those values as follows after some trial and error

position.x - currentFrame.getRegionWidth()/2f
position.y - currentFrame.getRegionHeight()/2f


So batch draw call looks now like this:

 batch.draw(determineTexture(), position.x - currentFrame.getRegionWidth()/2f, position.y - currentFrame.getRegionHeight()/2f,
currentFrame.getRegionWidth()/2f, currentFrame.getRegionHeight()/2f,
currentFrame.getRegionWidth(), currentFrame.getRegionHeight(),1f,1f, rotation,false);


That makes it centered every time i think Maybe i should mark it as beginner question next time but it felt satysfying to solve after some hints from @DMGregory thanks

• This answer would be better if it showed the code change in context and described how/why making this change solves your problem. – DMGregory Jul 26 '19 at 8:46
• @DMGregory I am still figuring out why it works – new User Jul 26 '19 at 9:09