How to store and prepare 2D sprites (3 directions) for later use

Hello,

I have a couple of sprites for a 2d character, containing the following categories:

  • body
  • head
  • hair
  • shirt
  • jacket

Each version of an “item” has one sprite for three different directions (up, side, down).

What I am currently trying to do is creating a way to store these sprites with a name, so that I can just set the hair to “Curly” or “Long”, so the sprites for all three directions need to be stored under this name. Unfortunately I don’t have any idea how to start. Anyone has some tips or at least keywords that will help me get started?

By up down and side i assume you mean character movement? Or are you talking about a character creator type thing?

I mean the orientation of the sprites. So I have for example hair shown from the side, shown from behind and shown from the front.

Here is an example:

Character should use this when walking upwards:
3228977--247771--upload_2017-9-21_23-10-29.png

This when walking sideways:
3228977--247772--upload_2017-9-21_23-11-21.png

And this when walking downwards:
3228977--247773--upload_2017-9-21_23-11-44.png

I have a script that takes care of this. The only thing the script needs to know is “Okay the character has curly hair, so I have to use this sprite now because the character walks sideways.”. And because I plan to have a ton of different hair styles it should be easy to maintain and expand at any time.

Hmm, theres many ways you can go about swapping out the hair (im guessing its a seperate sprite on the main character?),

anyways, if you already have the button promps like if up hairstyle = up
then you can do something like this to control and add new hairstyles when you please

public class CharacterFeatureControl : MonoBehaviour
{

    [System.Serializable]
    public class HairStyles
    {
        public string styleName;
        public Sprite top;
        public Sprite down;
        public Sprite side;
    }

    public HairStyles[] hairStyles; // create an array of hairstyles

    public int currentHairStyle = 0
        ; // change this for the hair style you want from the hairStyle array e.g 0 = curly 1 = afro
    // Use this for initialization

    void Start()
    {
        // assign the new sprites in here like
        topHairSprite = hairStyles[currentHairStyle].top;
        downHairStyle = hairStyles[currentHairStyle].down;
        sideHairStyle = hairStyles[currentHairStyle].side;

    }
}

Screenshot - a5cd8d96d0ace0760f33e766b3e2759b - Gyazo - this is what it will look like in the inspector, if you get my idea you can just increase the hairstyle up or down by 1 to change it

1 Like

That should work just fine :slight_smile: I am currently implementing it since a couple of things need to be adjusted in my scripts. Thank you very much for the idea!