Sprites Tutorial

 
What are sprites:
 
Sprites are texture, mostly animated, that will be drawn over others , they are mostly used by functions to create effects, for example an explosion, or smoke and also the hud for the player state.
Sprites are very often used with a transparency effect.
The sprite size must be a multiple of 8 . Animated sprite, made of several images must use the same palette of 256 colors for each image.

There is 4 settings types for sprites textures

Additive Those sprites can have 256 colors and are mixed with an additive transparency, it's the mostly used type.
Alphatest Tose sprites can use 255 colors, the last color of the palette is transparent. Exemple : agrunt1, blood, crosshairs, rope ...
Indexalpha Those sprites are gray scale type, but they are drawn in color in the game with the palette as alpha channel. Black is transparent and white is opaque. the last color of the palette is the sprite color. Exemples : bigspit, bubble, mommablob, steam ...
Normal Same as additive practically, in colors, but no mix or transparency. Exemple : lgtning
 
Tutorial Additive:
 
We are going to use 640_pain.spr as exemple. The additive type can use 256 colors and be mixed with an additive transparency.
We extract 640_pain.spr from .pak file and we open it with the Sprite Viewer. We save the sequence to the .BMP format. We get 4 images as 640_pain00x.bmp
We can open them in a imaging program to edit them if needed.
We save them in BMP format 256 colors, all images must use the same palette.
Now we have to create a QC file to be able to compile, compilation will be launched with a BAT file.

640_pain.qc file

// 640_pain  
//  
$spritename 640_pain name of compiled sprite file
$type vp_parallel always same type!
$texture additive additive type
$load 640_pain001.bmp name of the first .bmp source file
$frame 0 0 128 48 offset (x,y) et size (x,y), offset is used if the sprite is part of a large sprite file composed of many sprites as the hud for example
$load 640_pain002.bmp  
$frame 0 0 48 128  
$load 640_pain003.bmp  
$frame 0 0 128 48  
$load 640_pain004.bmp  
$frame 0 0 48 128  
 
Finally copy the sprite file in the half-life\valve\sprites folder or in the sprites folder of the mod folder to use it.
 
Tutorial Alphatest:
 
We are going to use crosshairs.spr as exemple. The alphatest type can use 255 colors, last one of the palette is for transparency.
We extract sprite from pak and open with Sprite Viewer , save it in BMP format .
We can open them in a imaging program to edit them if needed, before saving, check the palette (256 colors) and see if the last one is the one defined as transparent
Crooshairs have a maximum of 24x24 pixels, zoom 104x16.
Now we have to create a QC file to be able to compile, compilation will be launched with a BAT file.

crosshairs.qc file

// crosshairs  
//  
$spritename crosshairs name of sprite, it will be compiled in crosshairs.spr
$type vp_parallel allways vp_parallel
$texture alphatest sprite type
$load crosshairs.bmp name of the .bmp source file
$frame 0 0 128 128 offset (x,y) and size (x,y)
 
Tutorial Indexalpha;
 
These sprites are gray scale type but will be drawn in color in the game with the palette as alpha channel.
The last color of the palette will be the sprite color in the game.
You need to create a texture in 256 gray scales, Then edit the palette to give the last color the color to be used by the sprite.
 
An example is the sprite mommaspit.spr, you can extract ut an open it with the Sprite Viewer , you will have to save the sequence in .BMP format.
Then edit if needed, all the sprite textures must have the same palette and the last palette color is the sprite color.
 
Now we have to create a QC file to be able to compile, compilation will be launched with a BAT file.
 

mommaspit.qcfile

// mommaspit  
//  
$spritename mommaspit sprite name, it will be compiled in mommaspit.spr
$type vp_parallel allways vp_parallel
$texture indexalpha sprite type
$load mommaspit001.bmp name of the first .bmp source file
$frame 0 0 32 32 offset (x,y) and size (x,y)
$load mommaspit002.bmp  
$frame 0 0 32 32  
$load mommaspit003.bmp  
$frame 0 0 32 32  
$load mommaspit004.bmp  
$frame 0 0 32 32  
 
Finally copy the sprite file in the half-life\valve\sprites folder or in the sprites folder of the mod folder to use it.