-
Notifications
You must be signed in to change notification settings - Fork 13
Sprite Sheets
Sprite sheets are used to describe the area and animation properties of a 2D sprite within a texture atlas. They are read / written in the crogine Config Format, and can be parsed specifically with the SpriteSheet class. An example sprite sheet looks like this:
SpriteSheet MySprite
{
src = "assets/images/texture_atlas.png"
blend_mode = alpha
sprite player_one
{
bounds = 0,0,16,32
animation walk
{
frame = 0,0,16,32
frame = 16,0,16,32
frame = 32,0,16,32
frame = 16,0,16,32
loop = true
frame_rate = 12.5
}
animation idle
{
frame = 0,0,16,32
loop = false
}
}
sprite player_two
{
bounds = 0,32,16,32
animation walk
{
frame = 0,32,16,32
frame = 16,32,16,32
frame = 32,32,16,32
frame = 16,32,16,32
event = 0,1
loop = true
frame_rate = 12.5
}
animation idle
{
frame = 0,32,16,32
loop = false
}
}
}
Note that multiple sprites can be described each with their own object within the sprite sheet. Each sprite requires one bounds
property that describes the left, bottom, width and height of the default area to display when the sprite is loaded. Each sprite can have zero or more animations, each of which contain a series of frames described as a bounds rectangle, along with properties describing whether or not the animation is looped as well as the animation's frame rate. Each sprite can also specify its own blend_mode
property, which will override any blend_mode
declared globally in the sprite sheet.
Animations can also contain events, which are a numeric pair, the first representing an event ID and the second value being the frame on which the event is triggered. For example event = 0,1
would trigger a SpriteAnimationEvent
on the message bus with the ID of 0 every time the animation displays frame 1. The event ID can be any value the user desires, for example to represent the sprite's footstep when walking. Multiple even IDs can be assigned to the same frame:
event = 0,1
event = 5,1
Sprite sheets can be edited by hand, or with the Sprite Sheet editor in the Editor project repository.