Sign in to follow this  

Sprites and states

Recommended Posts

I was wondering how people organize the sprites that correspond to certain states such as walking left, walking right, etc.  I have a sprite sheet that has sprites all unorganized in it so I was thinking of taking each animation and putting it into its own file such as walkingLeft.png  


Do you guys put your sprites into their own image file, hard code each sprite animation frame, or do you organize your sprite sheet in a way where each one has to have x amount of frames per state and you just organize the rows by states?

Share this post

Link to post
Share on other sites

Equally sized cells, laid out in a reasonable manner are pretty easy to work with.


RPG Maker XP had a decent convention for this. Spritesheets are 4 cells by 4 cells. Each row is an animation of walking in a specific cardinal direction:




If your directions are sequentially enumerated values then you can use math to pick the cell:

enum DIRECTION : int {
  DOWN = 0,
sprite.src_rect.x = animationStep * (sprite.width / SPRITESHEET_COLUMNS);
sprite.src_rect.y = direction * (sprite.height / SPRITESHEET_ROWS);

This is an easily extended pattern. You can easily add custom animations in new rows, or add rows of static images.


Probably a better bet is to have a base spritesheet for each entity, then add extras as needed.

Share this post

Link to post
Share on other sites

You can save everything in separate files for organization, and later on program a tool that 'merges' these files into a single, final asset that you're going to ship your game with (something like that atlas on the post above).

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