Advertisement

Sprites and states

Started by August 31, 2013 07:43 PM
1 comment, last by Kryzon 11 years, 6 months ago

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?

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:

arshes13.png

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


enum DIRECTION : int {
  DOWN = 0,
  LEFT,
  RIGHT,
  UP
};
 
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.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
Advertisement

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).

This topic is closed to new replies.

Advertisement