Difference between revisions of "RecolorSprites"

From GRFSpecs
Jump to navigationJump to search
 
Line 52: Line 52:
 
TTD already defines a number of recolour sprites for various uses, e.g. for the semi-transparency of glass or the re-colouring of the tubular bridges, company colours or some houses.
 
TTD already defines a number of recolour sprites for various uses, e.g. for the semi-transparency of glass or the re-colouring of the tubular bridges, company colours or some houses.
   
||'''Sprite number'''|'''Description'''
+
||'''Sprite number (dec)'''|'''Sprite number (hex)'''|'''Description'''
   
0x303| A pulsating red tile is drawn if you try to build a wrong tunnel or raise/lower land where it is not possible
+
775|0x303| A pulsating red tile is drawn if you try to build a wrong tunnel or raise/lower land where it is not possible
   
0x304| Makes a square red. is used when removing rails or other stuff
+
776|0x304| Makes a square red. is used when removing rails or other stuff
   
0x305 | This draws a blueish square (catchment areas for example)
+
777|0x305 | This draws a blueish square (catchment areas for example)
   
0x307 | company colour to dark blue
+
'''translations for the company colour (blue-ish colours are replaced)'''
   
0x308 | company colour to pale green
+
778|0x307 | company colour to dark blue
   
0x309 | company colour to pink
+
779|0x308 | company colour to pale green
   
0x30A | company colour to yellow
+
780|0x309 | company colour to pink
   
0x30B | company colour to red
+
781|0x30A | company colour to yellow
   
0x30C | company colour to light blue
+
782|0x30B | company colour to red
   
0x30D | company colour to green
+
783|0x30C | company colour to light blue
   
0x30E | company colour to dark green
+
784|0x30D | company colour to green
   
0x30F | company colour to blue
+
785|0x30E | company colour to dark green
   
0x310 | company colour to cream
+
786|0x30F | company colour to blue
   
0x311 | company colour to mauve
+
787|0x310 | company colour to cream
   
0x312 | company colour to purple
+
788|0x311 | company colour to mauve
   
0x313 | company colour to orange
+
789|0x312 | company colour to purple
   
0x314 | company colour to brown
+
790|0x313 | company colour to orange
   
0x315 | company colour to grey
+
791|0x314 | company colour to brown
   
0x316 | company colour to white
+
792|0x315 | company colour to grey
   
  +
793|0x316 | company colour to white (darker parts are blue-ish)
0x317 | bare land, for rail and road (crossings)
 
   
  +
'''translations for "brownish red" colour used by some town buildings and bridges'''
0x31B | structure to blue
 
   
 
794|0x317 | bare land, for rail and road (crossings)
0x31C | structure to brownish (e.g. cantilever bridges)
 
   
0x31D | structure to white
+
795|0x31B | structure to blue
   
0x31E | structure to red (e.g. bridges)
+
796|0x31C | structure to brownish (e.g. cantilever bridges)
   
0x31F | structure to green (e.g. bridges)
+
797|0x31D | structure to white
   
0x320 | structure to concrete (e.g. suspension bridge)
+
798|0x31E | structure to red (e.g. bridges)
   
0x321 | structure to yellow (e.g. suspension bridge + tubular)
+
799|0x31F | structure to green (e.g. bridges)
   
 
800|0x320 | structure to concrete (e.g. suspension bridge)
0x322 | glass effect
 
   
0x323 | structure to grey (e.g. tubular bridge)
+
801|0x321 | structure to yellow (e.g. suspension bridge + tubular)
   
  +
'''special colour translations'''
0x324 | crashed vehicle (grey-ish)
 
   
 
802|0x322 | glass effect
0x59E | church red
 
   
  +
803|0x323 | maps to grey (e.g. tubular bridge or newspaper)
0x59F | church cream||
 
  +
 
804|0x324 | crashed vehicle (grey-ish)
  +
 
1438|0x59E | church red
  +
 
1439|0x59F | church cream||
  +
  +
For the company colour translation a translation to dark blue (0x307) is the identity translation which replaces every colour with itself. You can use it in cases where a remapping is needed, but you don't want to recolor anything.

Revision as of 15:54, 12 December 2010

Changing how other sprites are drawn

Recolor Sprites

Changing how other sprites are drawn

-=Introduction=-

Recolor sprites are pseudosprites used to recolor other sprites, most often to apply company colors. A recolour sprite is simply a re-mapping of TTDs original colour table.

-=Format=-

A recolor sprite has the following format:

 -+<Sprite-number> * 257 00 <recolor-table>+-

||Element|Size|Description

<Sprite-number>|dec|A sequential sprite number

257|dec|The total number of bytes used in this action, always 257

00|B|literal 00

<recolor-table>|256*B|See below||

-=Filling in the Terms=-

00

At first glance, it is easy to confuse a recolor sprite with an action 0, most often for trains. Attempting to read the recolor sprite as an action 0 will usually reveal that there are far too many bytes. Another clue is that recolor sprites are always 257 bytes long.

The correct method to distinguish recolor sprites and action 0s is to note that recolor sprites can only appear in an Action5 or ActionA block, and action 0s can only appear outside such a block.

recolor-table

A 256-byte recolor table. A byte at the offset equal to the index of the source color specifies the color to be drawn.

Note that the offsets and bytes are different depending on whether the GRF is being loaded in TTD DOS or TTD Win. If you create a grf that contains recolor sprites, you may find it necessary to maintain two separate versions, or use an Action7 that checks variable 83 to guard the introducing action 5/A and the recolor sprite(s).

-=Usage=-

Recolor sprites are applied in one of two ways.

Non-transparently
Each pixel in the sprite is looked up in the recolor table, and then the color specified at that offset is drawn on the screen. If the resultant color is 00 ("transparent blue"), then if the sprite's compression bit 3 is not set, nothing is drawn; otherwise (i.e. if the sprite is in chunked data format) the actual color 00 (which is black) is drawn.
Transparently
For each sprite pixel that is not transparent, the current (on-screen) color of the pixel at the location where the sprite pixel would be drawn is looked up in the recolor table, and then redrawn in the new color. If the recolor lookup returns 00 ("transparent blue"), the resultant color is actually black. Other than is-transparent-blue/not-transparent-blue, the actual colors of the pixels in a sprite that is drawn transparently are meaningless.

-=Default recolour sprites=-

TTD already defines a number of recolour sprites for various uses, e.g. for the semi-transparency of glass or the re-colouring of the tubular bridges, company colours or some houses.

||Sprite number (dec)|Sprite number (hex)|Description

775|0x303| A pulsating red tile is drawn if you try to build a wrong tunnel or raise/lower land where it is not possible

776|0x304| Makes a square red. is used when removing rails or other stuff

777|0x305 | This draws a blueish square (catchment areas for example)

translations for the company colour (blue-ish colours are replaced)

778|0x307 | company colour to dark blue

779|0x308 | company colour to pale green

780|0x309 | company colour to pink

781|0x30A | company colour to yellow

782|0x30B | company colour to red

783|0x30C | company colour to light blue

784|0x30D | company colour to green

785|0x30E | company colour to dark green

786|0x30F | company colour to blue

787|0x310 | company colour to cream

788|0x311 | company colour to mauve

789|0x312 | company colour to purple

790|0x313 | company colour to orange

791|0x314 | company colour to brown

792|0x315 | company colour to grey

793|0x316 | company colour to white (darker parts are blue-ish)

translations for "brownish red" colour used by some town buildings and bridges

794|0x317 | bare land, for rail and road (crossings)

795|0x31B | structure to blue

796|0x31C | structure to brownish (e.g. cantilever bridges)

797|0x31D | structure to white

798|0x31E | structure to red (e.g. bridges)

799|0x31F | structure to green (e.g. bridges)

800|0x320 | structure to concrete (e.g. suspension bridge)

801|0x321 | structure to yellow (e.g. suspension bridge + tubular)

special colour translations

802|0x322 | glass effect

803|0x323 | maps to grey (e.g. tubular bridge or newspaper)

804|0x324 | crashed vehicle (grey-ish)

1438|0x59E | church red

1439|0x59F | church cream||

For the company colour translation a translation to dark blue (0x307) is the identity translation which replaces every colour with itself. You can use it in cases where a remapping is needed, but you don't want to recolor anything.