Sign in to follow this  
kzar

how to handle varying sprite sizes for the player

Recommended Posts

Hey i am making the player character now. I lifted some mario sprites off a webpage to use while i write the game. I am putting all of a characters sprites in the one image, and heres the problem. The death sprite is about 30 wide but most walking ones are around 20. Of course i need all 30 for the death but if the game thinks the player is 30 wide he will float about slightly above the floor. Of course i could put the smaller sprite at the bottom of the box but thats not a proper solution. Whats the right way of doing this?

Share this post


Link to post
Share on other sites
Something to think about: consider storing geometry / collision info for each frame of animation. each time the frame changes, update the collision geometry. That is a lot more work, but it would fix the problem.

Share this post


Link to post
Share on other sites
Im getting really confused now, have been trying to write how im going to do this down on a piece of paper.

I have been reading a tutorial, and they handle characters animations by having a file for each character which lists the possible states and their text files. In each character's state text file it explains about that animation.

It sounds fine but i dont understand how it can be 100% flexible like that! for instance if i want to move left i would press the left arrow, it would change my state to moving_left and deal with animations but if its 100% flexible how do i know there is a moving_left state? Also i dont see how i could load the file and index an array of animations by the names they gave the different states. You cant define things by loading them from a textfile can you?

Im going to have a structure for characters, a structure for animations and a function for animation but im confused at how to link them. When your standing still you dont need animation but when you move you do.

I hope this makes some sence :o

Share this post


Link to post
Share on other sites
For each "state" (run, idle, jump, fire...) you have an animation sequence. That means you should probably code an AnimationSequence class to handle that. It needs to be able to loop or stop after X number of loops and also needs a configurable number of frames. If you are idle, you only play one frame for eternity (standing still). If you are running, you loop the running sequence as the player moves around. If you jump, you play the rising animation ONCE, then at the peak of the jump (perhaps) the state could change to JUMPING_FALL and you switch to *that* animation and loop once.

The way i do it is to have a file in XML (or whatever) for each animation that describes the filenames of the images and the running times for each frame. You load all the images and configurations at the start of the game, then play the appropriate one when needed. Something like this:

enum state {
RUN,
IDLE,
JUMP,
...
}

class AnimationSequence {
...
void Play ( int num_loops );
...
}

//store them in this:
std::map< state, AnimationSequence* > animations;

Share this post


Link to post
Share on other sites
Would you have an array of animations that you cycle through or somthing? (im not sure how it would know what items are animations and what are stills. )

thanks for the help, think i might have bitten off more than i can chew here!

Share this post


Link to post
Share on other sites
Well animations are just a sequence of still images, right? If you are talking about sprite sheets, it does get kind of tricky at that point, differentiating the two. That's why i've personally chosen to not use them for in-game use. Every image is it's own surface/texture for my current project.

The player state and animation syncing is difficult and often sloppy. You might check out the Game Programming Gems and AI Wisdom books. There is some info on that very topic in those.

Share this post


Link to post
Share on other sites
I think i get the idea now. Im having a go at pacman to see if i can get it working! (withought the ghosts!)

Are there any good examples around? (not of pacman, of the animation problem)

Share this post


Link to post
Share on other sites
I think i get the idea now. Im having a go at pacman to see if i can get it working! (withought the ghosts!)

Are there any good examples around? (not of pacman, of the animation problem)

Share this post


Link to post
Share on other sites
Is this the right idea? Theres an array of this structure for the characters.

Quote:

struct CCharacter
{
int x, y;
int h, w;
int x_vol, y_vol;
int sprite_x;
int sprite_y;
int lastanimated;
int animationdelay
int moving;
enum Estate {STILLRIGHT, STILLLEFT, WALKRIGHT, WALKLEFT} state;
}


and then in my game loop i scan all of the characters to see if moving is 1. if it is i get the lastanimated time, take it from the current time and if its >= animationdelay i shift the sprite_x along 1 width worth (unless it needs looping back). Doing it that way i need to store quite a bit for each character and have a seperate animation function for characters and normal animations but i cant see how else to do it?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this