spritelayout.h 1.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#ifndef spritelayout_H_INCLUDED
#define spritelayout_H_INCLUDED

/* The layout of the sprite. Each int * pointer field should be ponted to 
 * an array of size rows.  
 * In general, the cells of a sprite are expected to be layed out on a sprite 
 * sheet in rows of equal height, and in columns of equal width. 
 */ 
struct SpriteLayout_ {
  int rows;
  int * per_row;
  int * row_type;
  int * row_dir;
  double * row_duration;
  /* The maximum sizes of the individual frames or layers.  */
  int size_x;
  int size_y;  
  /* If not negative, this means the standinwaltk'th frame of the 
   walking animation is in fact the standing position. This frame should be skipped 
   for walking and added to a separate standing position. 
   The standing actions will be placed after all other actions of the sprite.
   */
  int standinwalk;
  /* The offset from the top to the "feet" of the sprite. Must be the same for 
   * all frames. */
  int offset_x;
  int offset_y;
  
};

#define DEFINE_SPRITELAYOUT(NAME, ROWS, PER_ROW, ROW_POSE, ROW_DIR,            \
                            SIZE_X, SIZE_Y, STANDINWALK, OFFSET_X, OFFSET_Y)                       \
struct SpriteLayout_ NAME = { ROWS  , PER_ROW, ROW_POSE, ROW_DIR,              \
                              SIZE_X, SIZE_Y, STANDINWALK, OFFSET_X, OFFSET_Y } 

int spritelayout_rows(SpriteLayout * layout);

Sprite * spritelayout_loadactionlayer(SpriteLayout * layout, Sprite * sprite, 
  Image * source, int actionindex, int layerindex);
 
SpriteLayout * spritelayout_for(int load_type);

Sprite * spritelayout_load_layer
(SpriteLayout * layout, Sprite * sprite, Image * source, int layeri);


#endif