Java – Customizable player avatar in 2D games

Customizable player avatar in 2D games… here is a solution to the problem.

Customizable player avatar in 2D games

How can I have a feature in my game where players can change their hairstyle, appearance, clothing style, etc. so that whenever they wear a different outfit, their avatar is updated with it.

I should:

  • Have my designer create all possible combinations of armor, hairstyles, and faces as sprites (which can take a lot of work).

  • When a player chooses their appearance when introducing the game, my code automatically creates this sprite, along with all possible combinations of headgear/armor with that sprite. Then every time they select some different armor, a sprite for that armor/appearance combination is loaded.

  • Is it possible to split a character’s sprite into multiple parts, such as face, shirt, jeans, shoes, and the pixel dimensions of each part. Then whenever the player changes his Helm, for example, we use pixel dimensions to place the Helm image where its face image would normally be. (I’m building this game using Java)

  • This is not possible in 2D, should I use 3D for this?

  • Is there another way?

Please advise.

Best Solution

A major factor to consider is animation. If a character has armor with shoulder pads, these shoulder pads may need to move with his torso. Similarly, if he wears a Boot, the Boot must follow the same cycle as a hidden barefoot.

Essentially, what your designer needs is a sprite sheet that allows your artist to see all possible animation frames of your base character. You can then let them create custom hairstyles, boots, armor, and more based on these tables. Yes, this requires a lot of work, but in most cases the elements will require minimal redraws; Boot is the only thing I can see that really requires a lot of work to remake because they change multiple animation frames. Be ruthless to your sprite and minimize the required amount.

Once you’ve accumulated your element library, you can start cheating. Recycle the same hairstyle and adjust its color in Photoshop or directly in the game using the slider in the character creator.

To ensure good performance in the game, the last step is to flatten the sprite table of all the different elements into a single sprite table, which is then split and stored in the sprite buffer.

Related Problems and Solutions