The sprite module allows you to animate more easily characters and landscapes
by bringing configured animation and automation functions.
The sprite module header is lapin/sprite.h
Description
  This enumeration describes the way an animation in sprite
is browsed.
Symbols
-
BFB_LEFT_TO_RIGHT:
  The animation is browsed from left to right.
-
BFB_RIGHT_TO_LEFT:
  The animation is browsed from left to right.
-
BFB_BACK_AND_FORTH:
  The animation is browsed from left to right, and then
from right to left, and it start again.
INDEX
Description
  This structure represents a single animation from a sprite sheet.
For example, it will be a character running. This type is more internal
than user-side, but you may want to edit it at runtime.
Some field should definitively be constant and may become on a next version.
Concerned fields will be noted here.
Attributes
-
uint64_t hash:
  The animation name, hashed with an inside algorithm.
This field will become const in a next version. Do not edit it.
-
double delay:
  The delay between any frame shift, in seconds.
-
uint32_t nbr_frame:
  How many pictures is there in this animation.
-
t_bunny_position position:
  The position in pixel of the first frame of the animation in the
whole sprite sheet.
-
t_bunny_vector *frame_repetition:
  This vector is nbr_frame long. Each case contain a value greater
or equal to zero that indicates how many time some frame must be repeated
before switching to the next one.
For example, take a three frame long animation, the vector
will have three cases. It may contains, for example: 1, 3 and 1.
This means that at step 0, the first frame will be displayed.
At step 1, 2 and 3, the second frame will be displayed.
At step 4, the last one.
This pointer itself will become constant. Do not edit it. You can
still change the content of the vector.
-
t_bunny_frame_browsing browsing:
  How the frame are browsed.
-
int32_t animation_repeat:
  How many time the full animation must be played before being
considered terminated and switch to next_animation.
Set this field to -1 will indicates infinite repetition.
-
int32_t next_animation:
  The id of the next animation on which the system will
automatically switch until the current one is considered terminated.
It can be set to -1 to indicates there is no next animation.
This field will become const in a next version. Do not edit it.
INDEX
Attributes
-
t_bunny_clipable clipable:
  The clipable which serve as base for the t_bunny_sprite structure.
Some fields are handled by the sprite mechanisms and should not be modified,
but most of them can still be used by your program directly.
Fields you should avoid to edit are:
- clip_x_position
- clip_y_position
- clip_width
- clip_height
-
const size_t _private[3]:
  This field contains inner data you should not modify or it may
make your program crash.
-
t_bunny_vector *animation:
  All animations loaded and stored inside this structure.
This pointer itself will become constant. Do not edit it. You can
still change the content of the vector.
-
t_bunny_map *hashname_id:
  A map used to store the relation between hash and id. The hash
being the name written in configuration and the id the position
in the t_bunny_vector *animation.
The pointer itself and the data will become constant.
Do not edit it.
-
int32_t current_animation:
  The id of the animation currently being played.
-
uint32_t current_frame_repeat:
  The amount of time the current frame was repeated.
-
uint32_t current_repeat:
  The amount of time the current animation was repeated.
-
uint32_t current_frame:
  The frame currently being on display.
-
bool stop_repeat:
  If set to true, the animation will not repeat itself
after its end and the next animation will not be played.
It will simply stop on the last frame.
Setting a new animation will set this field to false.
INDEX
Error values and logs
On error, bunny_errno is set to:
Logs written by this function are tagged with the
"ressource",
"sprite" or
"syntax"
label.
Configuration file format
You can set properties of a t_bunny_sprite thanks to a file at runtime.
This allow you to get rid of a lot of configuration and to create space
for any outside editor.
DABSIC format and complete field description
Mandatory fields
-
The Animations node is mandatory. The Animations node is a hashmap node
(it contains named fields) that contains every animation available for
the sprite:
[Animations
  [Running
   
  ]
  [Jumping
   
  ]
]
-
The InitialAnimation field is mandatory. Its purpose is to indicates
which animation must be set at the beginning, before any manipulation
is made in your program:
InitialAnimation = "Running"
-
The Frequency field is not completly mandatory inside the root scope
of the sprite: it must be defined globaly, or at least, localy, inside
the animation description node.
The Frequency node indicates at how many frame per second the animation
is running, its unit is the Hertz. Example:
[Animations
 
]
Frequency = 3
Or
[Animations
  [Running
   
    Frequency = 3
  ]
  [Jumping
   
    Frequency = 3
  ]
]
Or
[Animations
  [Running
   
    Frequency = 3
  ]
  [Jumping
   
  ]
]
Frequency = 3
A global Frequency may be precised for all nodes.
It a node precise itself a Frequency value, it is the one that is used.
-
Inside the Animations node should be at least one node describing an
animation. In these node, there is several mandatory fields:
-
The Frame field is mandatory. It indicates how many picture clips are
being used by the animation.
-
The Position array is composed of two cases: 0 and 1 and it indicates
respectively the coordinates as X and Y of the first picture clip
that compose the animation:
[Animlations
  [Running
   
    Position=100,200
  ]
]
Optionnal fields
Inside the Animations node should be at least one node describing an
animation. In these node, there is several optionnal fields:
-
The AnimationPlay or RepeatAnimation field tells how many time
the full animation must loop before being stopped. Note that
AnimationPlay and RepeatAnimation are the same field, it is just
an alternative name. By default, this field value is -1, which means
infinit repeatition if there is no next animation:
[Animations
  [Running
   
    RepeatAnimation=3 'Repeat three times the animation
  ]
]
-
The FramePlay array must have same length as the animation.
This length match the value given in the Frame field. The
FramePlay array describe, case after case, how many time
length frames. For example:
[Animations
  [Idle
    Frame=5
    Frequency=4
    {FramePlay
      20, 1, 1, 1, 1
    }
  ]
]
This animation show a still character on frame 0, which
brush its hair on frame 1, 2, 3 and 4. The frame 0
last 20 times more than other frame and as written with
Frequency=4, there is 4 frames per seconds.
Write 0 as frame repeat have the same effect as writing 1.
-
The Browsing field can value "LeftToRight", "RightToLeft" or
"BackAndForth" and indicates the way the clips composing the
animation are played:
[Animations
  [Running
   
    Browsing="LeftToRight"
  ]
]
By default, this field value is "LeftToRight"
-
The NextAnimation field indicates which animation will
follow the described one after its termination. It allows
animation to follow eachother, and even to cycle them:
[Animations
  [Jumping
   
    NextAnimation="Idle"
  ]
  [Running
   
    NextAnimation="Idle"
  ]
  [Idle
   
  ]
]
By default, there is no next animation, and the animation stop
or loop depending of other fields.
Here is a complete working example:
RessourceFile="./ressource/pinkman.png"
Frequency=5
InitialAnimation="Running"
[Clip
  Size=100,100 'Size of a single frame
]
[Animations
  [Running
    Position=0,0
    Frame=5
    RepeatAnimation=5
    NextAnimation="Idle"
  ]
  [Idle
    Position=0,100 'Note that Clip.Size[1] is 100. so this is the line under
    Frame=5
    Browsing="BackAndForth"
    {FramePlay
      20, 1, 1, 1, 1
    }
    Frequency=3
  ]
]
INI format and complete field description
This is the architecture of the INI format by example, with the same script
as for Dabsic:
RessourceFile="./ressource/pinkman.png"
Frequency=5
InitialAnimation="Running"
[Clip]
Size=100,100
[Animations.Running]
Position=0,0
Frame=5
RepeatAnimation=5
NextAnimation="Idle"
[Animations.Idle]
Position=0,100
Frame=5
Browsing="BackAndForth"
FramePlay=20,1,1,1,1
Frequency=3
INDEX
Description
  This function animates the sent sprite accordingly
to its configuration and accordingly to the sent elapsed time.
INDEX
Description
  Return true if the animation is stopped.
Return value
This function returns if the animation is stopped.
INDEX
Parameters
-
const char *animation_name:
  The name to hash.
Return value
Return the hash of the sent string.
INDEX
Description
  Set to a specific animtaion the sent sprite.
Return value
Return true if the animation was existing and set.
INDEX
Description
  Set to a specific animtaion the sent sprite.
Return value
Return true if the animation was existing and set.
INDEX
Description
  Set to a specific animtaion the sent sprite.
Return value
Return true if the animation was existing and set.
INDEX
Description
  Get the name under hash format of the currently being played
animation.
Return value
Return the hash of the name.
INDEX
Description
  Stop the animation of the sent sprite.
INDEX