# SDL Sprite Customization

I am currently working in C++ with SDL2. I plan on making a game that utilizes character visual customization. More specifically, equipping clothes and items changes the appearance of characters. However I don't know how to approach this situation. With that being said, how would I achieve this character customization in SDL2?

Right now I have two ideas...

1. Create a sprite sheet for every possible combination.( Way too much time).
2. Break the sprite into different rects to draw each article of clothing or item. (Not sure if this is efficient)
• #2 is de facto the industry standard for this sort of circumstances. Note, however, that depending on how elaborate the characters are, this will require a serious effort put into the development of an advanced animation system if you want to animate the characters. If that's the case than maybe broad customization is not the best idea to implement and you will want to choose #1. If you don't need to animate characters, or the animations are just basic ones, #2 is probably the way to go. – sjaustirni Jan 18 '18 at 20:57

Choose the second option. This way you will only have the necessary parts images, which will reduce the number of assets that would probably be huge with so many specific combinations, thus leaving the final set of your game much smaller and with fewer assets to load.

And to program, use switch/case rather than if/else. Here is why. (summarizing: switch / case has more performance when it comes to many conditions)

For example:

enum Outfit
{
HELMET,
ARMOR,
AXE,
// ... bunch of enums
};

void insert_clothing(const Outfit& piece)
{
switch(piece) {
case HELMET:
// ..
break;

case ARMOR:
// ..
break;

case AXE:
// ..
break;

// ... bunch of cases

default: std::cout<<"Non-existent enum"; break;
}
}

void remove_clothing(const Outfit& piece)
{
// Same thing, only changing the case definition
}


And when you call the functions, call using the piece you want to wear on/remove from the character:

void f()
{
insert_clothing(HELMET);
insert_clothing(ARMOR);
remove_clothing(HELMET);
}

• I would be very surprised if you were able to measure a speed difference in an actual game unless you had far more than the 8 or so clothing type I would expect most games like this to have. I think a decent compiler should be able to output a jump table for an if-else chain that just checks enum equality. – Ryan1729 Jan 19 '18 at 4:55
• I assumed he intended to make a non-trivial game by having about 30 items or more. Just imagine how many images of separate combinations he would have? As I said: "...switch / case has more performance when it comes to MANY conditions". Not just one. – Dormin Jan 19 '18 at 13:36