• Advertisement
Sign in to follow this  

Sprites and states

This topic is 1634 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

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.

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
Sign in to follow this  

  • Advertisement