Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Basically, the way it works is that it update the frame to show every let's say 24 ticks and every time the frame update, it recalculates the height and width of the new sprite to render so that my gravity logics and stuff works well. But the problem i am having now is a bit hard to explain in words only, therefore i will use this picture to assist me

The picture

So what i need basically is that if let's say i froze the sprite at the first frame, then unfreeze it and freeze it at the second frame, have the second frame's sprite (let's say it's a prone move) simply stand on the foothold without starting the gravity and when switching back, have the first sprite go back on the foothold like normal without being under the foothold.

I had 2 ideas on doing this but I'm not sure it's the most efficient ways to do it so i wanna hear your inputs.

share|improve this question
so the 2 sprites have different hight/widths but are in the same animation-frame? – iQue Sep 8 '12 at 16:32
Yes but i found a fix – oxysoft Sep 8 '12 at 18:41
up vote 0 down vote accepted

Fixed my problem, not sure if it will still function effectively in the future but it seems like a pretty good way to me

(i added a currentFoothold defenition the entity with for the object Foothold and when the entity isOnGround, set that foothold object to the foothold he currently is standing on, naturally. When recalculating height, if the entity isOnGround && foothold != null set the entity's Y coordinate to the foothold's Y coordinate in the map)

share|improve this answer
is there any reason ur not using an ordinary .png-file so all ur frames can be the same size? – iQue Sep 8 '12 at 20:44
For some frames, the character has for example his arm extended into the airs so the height of the png has to be bigger – oxysoft Sep 15 '12 at 0:00

Make your current getWidth() and getHeight() methods like this.

public int getWidth(){
    return currentImage.getWidth(null);

public int getHeight(){
    return currentImage.getHeight(null);

This makes you depends on the Java API to know these parameters. Instead of measuring them all the time, it simply calls the methods of the current image object. Make sure you call them only on the Current Image.

For reference see

It's free to use and is my own class.

share|improve this answer

Your Answer


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.