CoriEngine
Loading...
Searching...
No Matches
Cori::Graphics::AnimationPack Class Reference

Represents a pack of sprite animations that were loaded from the drive from the pair of an image file and json config. More...

#include <AnimationPack.hpp>

Inheritance diagram for Cori::Graphics::AnimationPack:
Collaboration diagram for Cori::Graphics::AnimationPack:

Classes

class  Descriptor
 AnimationPack Descriptor meant to be used with AssetManager only. More...

Public Types

enum  ConfigType : uint8_t { ASEPRITE , CORI_UNIFORM , CORI_VARYING , INVALID }
 Available animation pack config types. More...

Public Member Functions

Animation GetAnimation (const uint32_t index)

Static Public Member Functions

static std::shared_ptr< AnimationPackCreate (const std::filesystem::path &jsonPath, ConfigType type, const std::string &name)
 Creates an AnimationPack.

Protected Attributes

friend Animation
std::vector< Internal::AnimationDatam_Animations
std::variant< std::shared_ptr< SpriteAtlas >, std::shared_ptr< Texture2D > > m_TextureOrAtlas
ConfigType m_Type

Detailed Description

Represents a pack of sprite animations that were loaded from the drive from the pair of an image file and json config.

I can load several types of configs: ASEPRITE, CORI_UNIFORM, CORI_VARYING.
ASEPRITE: uses the config that is generated by aseprite when extracting the animation, adds extruding to each sprite on animation atlas, all animation frames should be the same resolution.
CORI_UNIFORM: uses engine native json config layout to load a pack of animations, adds extruding to each sprite on animation atlas, all animation frames should be the same resolution.
Example of the json layout:

{
"meta": {
"frameSizeX": 32,
"frameSizeY": 32,
"textureFile": "Atlas.png"
},
"animations": [
{
"frames": [ { "x": 0, "y": 0, "ms": 100 }, { "x": 32, "y": 0, "ms": 100 }, { "x": 64, "y": 0, "ms": 100 }, { "x": 96, "y": 0, "ms": 100 }, { "x": 128, "y": 0, "ms": 100 }, { "x": 160, "y": 0, "ms": 100 } ]
},
{
"frames": [ { "x": 0, "y": 32, "ms": 100 }, { "x": 32, "y": 32, "ms": 100 }, { "x": 64, "y": 32, "ms": 100 }, { "x": 96, "y": 32, "ms": 100 }, { "x": 128, "y": 32, "ms": 100 }, { "x": 160, "y": 32, "ms": 100 } ]
},
{
"frames": [ { "x": 0, "y": 64, "ms": 100 }, { "x": 32, "y": 64, "ms": 100 }, { "x": 64, "y": 64, "ms": 100 }, { "x": 96, "y": 64, "ms": 100 }, { "x": 128, "y": 64, "ms": 100 }, { "x": 160, "y": 64, "ms": 100 } ]
}
]
}

Here we load animation from image 'Atlas.png' (path relative to the json config), we load 3 animation each with 6 frames all have frame size of 32x32, x and y pairs is the left upper corner of each animation frame, the lower right corner is calculated based on frameSizeX and frameSizeY.
CORI_VARYING: uses engine native json config layout to load a pack of animations, different animations can have different frame size, but at the cost of not adding padding to each frame sprite so texel bleeding can occur, be aware.
Example of the json layout:

{
"meta": {
"textureFile": "Atlas.png"
},
"animations": [
{
"frameSizeX": 32,
"frameSizeY": 32,
"frames": [ { "x": 0, "y": 0, "ms": 100 }, { "x": 32, "y": 0, "ms": 100 }, { "x": 64, "y": 0, "ms": 100 }, { "x": 96, "y": 0, "ms": 100 }, { "x": 128, "y": 0, "ms": 100 }, { "x": 160, "y": 0, "ms": 100 } ]
},
{
"frameSizeX": 48,
"frameSizeY": 48,
"frames": [ { "x": 0, "y": 32, "ms": 100 }, { "x": 48, "y": 32, "ms": 100 }, { "x": 96, "y": 32, "ms": 100 }, { "x": 96, "y": 32, "ms": 100 }, { "x": 144, "y": 32, "ms": 100 }, { "x": 192, "y": 32, "ms": 100 } ]
},
{
"frameSizeX": 64,
"frameSizeY": 64,
"frames": [ { "x": 0, "y": 80, "ms": 100 }, { "x": 64, "y": 80, "ms": 100 }, { "x": 128, "y": 80, "ms": 100 }, { "x": 192, "y": 80, "ms": 100 }, { "x": 256, "y": 80, "ms": 100 }, { "x": 320, "y": 80, "ms": 100 } ]
}
]
}

Here we load animation from image 'Atlas.png' (path relative to the json config), we load 3 animation each with 6 frames all have different frame size, x and y pairs is the left upper corner of each animation frame, the lower right corner is calculated based on frameSizeX and frameSizeY of each animation.

Warning
Each frame timing specified in ms in the config will be rounded to the nearest tick based on the tickrate, so for example if we have tickrate of 60 and our frame length is specified to be 110ms in the config it will be rounded to 7 ticks and that is 116.6...ms.

Definition at line 82 of file AnimationPack.hpp.

Member Enumeration Documentation

◆ ConfigType

Available animation pack config types.

Enumerator
ASEPRITE 
CORI_UNIFORM 
CORI_VARYING 
INVALID 

Definition at line 87 of file AnimationPack.hpp.

Member Function Documentation

◆ Create()

std::shared_ptr< AnimationPack > Cori::Graphics::AnimationPack::Create ( const std::filesystem::path & jsonPath,
ConfigType type,
const std::string & name )
staticnodiscard

Creates an AnimationPack.

Parameters
jsonPathPath to the config file.
typeType of the config file, specifies how the config file will be interpreted.
nameName to be assigned to the AnimationPack.
Returns
Shared ptr with the created AnimationPack.

Definition at line 24 of file AnimationPack.cpp.

Here is the call graph for this function:

◆ GetAnimation()

Animation Cori::Graphics::AnimationPack::GetAnimation ( const uint32_t index)
nodiscard

Definition at line 226 of file AnimationPack.cpp.

Member Data Documentation

◆ Animation

friend Cori::Graphics::AnimationPack::Animation
protected

Definition at line 147 of file AnimationPack.hpp.

◆ m_Animations

std::vector<Internal::AnimationData> Cori::Graphics::AnimationPack::m_Animations
protected

Definition at line 149 of file AnimationPack.hpp.

◆ m_TextureOrAtlas

std::variant<std::shared_ptr<SpriteAtlas>, std::shared_ptr<Texture2D> > Cori::Graphics::AnimationPack::m_TextureOrAtlas
protected

Definition at line 151 of file AnimationPack.hpp.

◆ m_Type

ConfigType Cori::Graphics::AnimationPack::m_Type
protected

Definition at line 158 of file AnimationPack.hpp.


The documentation for this class was generated from the following files: