Hats.wiki
author Wuzzy
Fri, 14 Sep 2018 19:45:42 +0100
changeset 1555 87afdf066822
parent 1419 b47b108c9885
child 1980 c46ebe308440
permissions -rw-r--r--
Taunts: fix Illgetyou and Justyouwait

#summary Explanation of hats, how Hedgewars draws them and how one can create them

= Hats =
== Introduction ==

In Hedgewars, every hedgehog can optionally wear its own hat as decoration. They can be selected on a per-hog basis in the team editor.

== Types of hats ==
There are two types of hats: normal hats and team hats.
Normal hats look always the same.
Team hats are hats which will be colored accordingly to the team color.
I.e. if a hedgehog plays in a red team, its hat will we red.

Additionally, hats can be either static or animated.

In the default Hedgewars installation, most hats are normal hats, and many hats are animated.
Examples for team hats in the default Hedgewars installation are `cap_team` and `hair_team`.

== Data structure ==
Hats are specified as PNG files with alpha channel.
They consist of a set of sub-images of a size 32px×32px each.
Hedgewars counts the sub-images, or animation frames, from top-left to
bottom-left, then it goes on with the next column, etc.

=== Static normal hats ===
These are the simplest hats. It's just a single 32×32 image containing the hat. This image will be put on the hedgehog's head with a vertical offset of 5 pixels.

That's it!

=== Static team hats ===
This is a 64px×32px image with 2 frames. The left half is the base coloring of the hat, the right half should _only_ use grayscale colors for the parts of the hat for which to use the team colors. The left part may be even completely blank. The same offset of 5 pixels applies here.

To create the final hat, Hedgewars will first colorize the right part to the team color, then overlay that on top of the left base image.

=== Animated normal hats ===
Animated normal hats use an image of a total size of 64px×512px. Only the first
19 frames are used, the remainder of the image is unused. It is best to keep the unused area transparent.

For animated hats, we highly recommend the use of the template (see below).

=== Animated team hats ===
Animated team hats use an image of a total size of 128px×512px. This image is similar to that of animated normal hats, the same pattern is repeated 64 pixels to the right.

The team hat image consists of two “halves”: The left half is the base coloring of the helmet, the right half should _only_ use grayscale colors. The left part may be completely blank. So you have basically two sets of helmet animations. Again, both animations have exactly 19 frames, the remainder is unused.

Hedgewars will use the right grayscale frames to color them and overlay them on the base color frames to the left.

Transparent pixels on the right part will not be overlayed. This way, you can decide which parts of the helmet become colored and which won’t.

== Alignment of hats ==
When creating hats, it is important to know where the hat will be actually placed.

For static hats, this is trivial: Hedgewars will just move the hat up by 5 pixels before drawing it on the hedgehog.
The hat will automatically slightly bounce up and down with the hedgehog idle animation.

Now to animated hats:
In the game, Hedgewars will use the idling frames (see `Data/Graphics/Hedgehog/Idle.png`)
together with the hat frames. For static hats, the reference point is the first frame of `Idle.png`.
If a hat is used, Hedgewars will draw the hat over the idling hedgehog for each frame, but
first it will move the hat’s frame up by 5 pixels.

The first frame of the hat animation will be drawn over the first frame of the idle animation,
the second frame of the hat animation will be drawn over the second frame of the idle animation,
and so on.

Another tricky part in creating hats is the fact that the idle hedgehog moves slightly up and down.
This means, a good hat must consider this, otherwise the hat does not seem to be actually on the
hedgehog’s hat, because it does not move with the hedgehog.

This table shows the relative height of the idle hedgehog compared to the frist frame of `Idle.png`:
|| *nth frame of `Idle.png`* || *Offset to first frame* ||
|| 1 || 0 px ||
|| 2 || 0 px ||
|| 3 || +1 px ||
|| 4 || 0 px ||
|| 5 || 0 px ||
|| 6 || 0 px ||
|| 7 || 0 px ||
|| 8 || +1 px ||
|| 9 || 0 px ||
|| 10 || 0 px ||
|| 11 || 0 px ||
|| 12 || 0 px ||
|| l3 || +1 px ||
|| 14 || 0 px ||
|| 15 || 0 px ||
|| 16 || 0 px ||
|| 17 || −1 px ||
|| 18 || 0 px ||
|| 19 || 0 px ||

This is how to read this table: If you would like to create a simple hat with no fancy animation, like, let’s say, a fedora, you would like the hat to “follow” the hedgehog. You could, for example, draw and align the hat image on the first frame, then copy it on all other frames and apply the offsets to the four “special” frames.


== Installation ==
To install a hat, you have to save the file into `Data/Graphics/Hats` in your Hedgewars
user data directory. The file name _must_ end with “`.png`”.

The Hedgewars frontend will display the same name as the file name you used, minus the file name
suffix. For example, the file “`Awesome Example Hat.png`” would be displayed as “Awesome Example Hat”.

Hedgewars will always use the very first frame of a hat image to create the preview in the team editor. This also applies to team hats.


== Templates ==
For your convenience, we have created some templates to ease the creation of hats to help you to align the hats pixel-perfectly. Use them as background layer.

 * Static normal hat: [https://www.hedgewars.org/images/Static_Hat_Template.png Static_Hat_Template.png]
 * Static team hat: [https://www.hedgewars.org/images/Static_Team_Hat_Template.png Static_Team_Hat_Template.png]
 * Animated normal hat: [https://www.hedgewars.org/images/Hat_Template.png Hat_Template.png]
 * Animated team hat: [https://www.hedgewars.org/images/Team_Hat_Template.png Team_Hat_Template.png]

For GIMP users, we also have XCF files with layers for your convenience:
 * Animated normal hat: [https://www.hedgewars.org/images/Hat_Template.xcf Hat_Template.xcf]
 * Animated team hat: [https://www.hedgewars.org/images/Team_Hat_Template.xcf Team_Hat_Template.xcf]

=== Quick explanation ===
Use these images as a temporary background layer. They show a colored checkerboard pattern, each field represents an animation frame. The green and red fields are those where the idle hedgehog has an offset of +1px or −1 px (see above). The black fields are the unused frames.

In the front, the idle hedgehog can be seen, already shifted correctly. The gray hedgehogs remind you of the fields which need to be in grayscale for team hats.

== Sharing hats ==
Custom hats (hats which are not part of the official Hedgewars installation) are only visible to other players if they have the hat installed under the same file name.

In case the other player does not have the custom hat installed, the player will see no hat instead.

You are encouraged to share your hats in the thread “[https://www.hedgewars.org/node/690 Hats! additions, submissions, information.]”, where submissions are considered for official inclusion into Hedgewars.