Skip to content

Latest commit

 

History

History
125 lines (105 loc) · 5.07 KB

new-graphics.md

File metadata and controls

125 lines (105 loc) · 5.07 KB

New Graphics

Create new animation

you can add your own models to projectiles, players, enemies, bosses and backgrounds.
Using png format

1. Add your png spritesheets to the resources folder

Add their path from directory root underneath cmrc_add_resource_library(
only the client needs those resources, so only add it inside function(build_client)

{% code title="CMakeLists.txt" %}

    cmrc_add_resource_library(
        client-resources

        ALIAS client::rc
        NAMESPACE client

        // Add the path to your new file here
        resources/r-typesheet1.png
        resources/r-typesheet2.png
        resources/r-typesheet3.png
        resources/r-typesheet5.png
        resources/r-typesheet7.png
        resources/r-typesheet8.png
        resources/r-typesheet9.png
        ...

{% endcode %}

{% hint style="warning" %} Always recompile after changing the resource files since
cmrc loads them into the executable {% endhint %}

2. Create new Animation::AnimationID enum

enum AnimationID {
    Orb,
    Vortex,
    Cluster,
    Laser,
    Lost,
    SpaceshipLightblue,
    SpaceshipPink,
    SpaceshipGreen,
    SpaceshipRed,
    SpaceshipDarkblue,
    SpaceshipRGB,
    Background,
    Death,
    // Only add new enums down here
};

{% hint style="danger" %} Always add your new enum at the end of the list to not change values {% endhint %}

3. Add a new instance of Animation::Sheet

  • Go to the std::map<> sheets in src/shared/ECS/components.hpp
  • Add your new Animation::AnimationID enum and an instance of the Sheet struct

{% code title="src/shared/ECS/components.hpp" %}

static std::map<Animation::AnimationID, Animation::Sheet> Sheets = {
    {Animation::AnimationID::Orb, {"resources/r-typesheet3.png", 1, 1, 16, 16, 12, 1, 1, 0, 0}},
    {Animation::AnimationID::Vortex, {"resources/r-typesheet30a.png", 1, 3, 32, 32, 3, 1, 2, 0, 0}},
    {Animation::AnimationID::Cluster, {"resources/r-typesheet32.png", 0, 0, 259, 142, 2, 3, 1, 1, 1}},
    {Animation::AnimationID::Laser, {"resources/r-typesheet43.png", 1, 41, 48, 4, 8, 1, 2, 0, 0}},
    {Animation::AnimationID::Lost, {"resources/lost.png", 0, 0, 639, 513, 8, 1, 1, 0, 0}},

    {Animation::AnimationID::SpaceshipLightblue, {"resources/r-typesheet42.png", 1, 3, 32, 16, 5, 1, 0, 0, 1, 0.2}},
    {Animation::AnimationID::SpaceshipPink, {"resources/r-typesheet42.png", 1, 20, 32, 16, 5, 1, 0, 0, 1, 0.2}},
    {Animation::AnimationID::SpaceshipGreen, {"resources/r-typesheet42.png", 1, 37, 32, 16, 5, 1, 0, 0, 1, 0.2}},
    {Animation::AnimationID::SpaceshipRed, {"resources/r-typesheet42.png", 1, 54, 32, 16, 5, 1, 0, 0, 1, 0.2}},
    {Animation::AnimationID::SpaceshipDarkblue, {"resources/r-typesheet42.png", 1, 71, 32, 16, 5, 1, 0, 0, 1, 0.2}},
    {Animation::AnimationID::SpaceshipRGB, {"resources/r-typesheet42.png", 1, 3, 32, 16, 1, 5, 0, 1, 0, 0.2}},
    
    {Animation::AnimationID::Background, {"resources/background.png", 0, 0, 256, 64, 1, 1, 0, 0, 0, 0, 1}},
    {Animation::AnimationID::Death, {"resources/background.png", 0, 0, 256, 64, 1, 1, 0, 0, 0, 0, 1}},
};

{% endcode %}

the Sheet is defined as:

{% code title="src/shared/ECS/components.hpp" %}

struct Sheet {
    std::string path;
    float startX;
    float startY;
    float frameWidth;
    float frameHeight;
    int animWidth;
    int animHeight;
    int separationX;
    int separationY;
    // adds the same frames in reverse to the animation
    bool reverse;
    double interval = 0.1;
    bool tile = false;
};

{% endcode %}

struct Sheet variables:
std::string path = path to .png file in resources folder
float startX, startY = x and y position of the upper left pixel from first frame
float frameWidth, frameHeight = width and height of single frame in sprite sheet
int animWidth, animHeight = number of horizonal and vertical frames in sprite sheet
int separationX, separationY = pixels between two frames in sprite sheet
bool reverse = if true doesnt repeat the animation at the end but reverses it
double interval = seconds between two frames of animation
bool tile = only for backgrounds to infinitely repeat

{% hint style="info" %} the path will only be found if you have loaded it into the client executable {% endhint %}