Difference between revisions of "RealSprites"

From GRFSpecs
Jump to navigationJump to search
m (10 revisions)
m (Bot: Automated text replacement (--= +==))
Line 1: Line 1:
   
 
== Introduction ==
'''''Sprites that actually get drawn on the screen'''''
 
   
 
=Real Sprites=
 
=Real Sprites=
Line 6: Line 6:
 
The sprites that the user actually sees.
 
The sprites that the user actually sees.
   
{maketoc}
 
   
-=Introduction=-
 
   
 
Real sprites are the graphical part of .grf files; they are what the user actually sees in-game.
 
Real sprites are the graphical part of .grf files; they are what the user actually sees in-game.
   
  +
==Syntax==
-=Format=-
 
   
 
A real sprite has the following format:
 
A real sprite has the following format:
   
<pre>-+&lt;Sprite-number&gt; &lt;filename&gt; &lt;xpos&gt; &lt;ypos&gt; &lt;compression&gt; &lt;ysize&gt; &lt;xsize&gt; &lt;xrel&gt; &lt;yrel&gt;+-</pre>
+
<Sprite-number> <filename> <xpos> <ypos> <compression> <ysize> <xsize> <xrel> <yrel>
   
  +
{|
||'''Element'''|[[GRFActionsDetailed|'''Size''']]|'''Description'''
+
!Element!![[GRFActionsDetailed|Size]]!!Description
   
  +
|-
&lt;Sprite-number&gt;|dec|A sequential sprite number
+
|<Sprite-number>||dec||A sequential sprite number
   
  +
|-
&lt;filename&gt;|string*|The name of the .pcx file in which the sprite will be found
+
|<filename>||string*||The name of the .pcx file in which the sprite will be found
   
  +
|-
&lt;xpos&gt;|dec|The x position of the upper-left corner of the sprite in the file
+
|<xpos>||dec||The x position of the upper-left corner of the sprite in the file
   
  +
|-
&lt;ypos&gt;|dec|The y position of the upper-left corner of the sprite in the file
+
|<ypos>||dec||The y position of the upper-left corner of the sprite in the file
   
  +
|-
&lt;compression&gt;|B|The &quot;compression&quot;; see below
+
|<compression>||B||The "compression"; see below
   
  +
|-
&lt;ysize&gt;|dec|The y size of the sprite
+
|<ysize>||dec||The y size of the sprite
   
  +
|-
&lt;xsize&gt;|dec|The x size of the sprite
+
|<xsize>||dec||The x size of the sprite
   
  +
|-
&lt;xrel&gt;|dec|The x position of the upper-left corner of the sprite, relative to the &quot;center&quot; (usually negative)
+
|<xrel>||dec||The x position of the upper-left corner of the sprite, relative to the "center" (usually negative)
   
  +
|-
&lt;yrel&gt;|dec|The y position of the upper-left corner of the sprite, relative to the &quot;center&quot; (usually negative)||
+
|<yrel>||dec||The y position of the upper-left corner of the sprite, relative to the "center" (usually negative)
  +
|}
   
<nowiki><nowiki>*</nowiki></nowiki> Unlike strings in pseudo-sprites, this string should not have a terminating &quot;00&quot; and should not be placed in quotes.
+
<nowiki>*</nowiki> Unlike strings in pseudo-sprites, this string should not have a terminating "00" and should not be placed in quotes.
   
-=Filling in the Terms=-
+
==Filling in the Terms==
   
 
===filename===
 
===filename===
Line 52: Line 61:
 
===xpos, ypos, ysize, and xsize===
 
===xpos, ypos, ysize, and xsize===
   
These are pretty easy to set, as long as you remember that the order is &nbsp;X, Y, Y, X, and not X, Y, X, Y.
+
These are pretty easy to set, as long as you remember that the order is X, Y, Y, X, and not X, Y, X, Y.
   
 
Also, no sprite may contain zero pixels; ysize and xsize must both be at least 1.
 
Also, no sprite may contain zero pixels; ysize and xsize must both be at least 1.
Line 60: Line 69:
 
Andrex's [http://www.divxland.org/ttd/files/nfoeditor.zip|NFOEditor] can often be helpful for setting these four values.
 
Andrex's [http://www.divxland.org/ttd/files/nfoeditor.zip|NFOEditor] can often be helpful for setting these four values.
   
'''WARNING:''' NFOEditor is replete with bugs, limitations, &amp;c.;: You MUST specify absolute paths, and paths must be delimited by backslashes (decode with grfcodec 0.9.5); comments MUST NOT contain &quot;*&quot;; and sprite numbers MUST be correct. Also, moving too far outside the size of the .pcx file will cause NFOEditor to crash, so save early and often.
+
'''WARNING:''' NFOEditor is replete with bugs, limitations, &amp;c.;: You MUST specify absolute paths, and paths must be delimited by backslashes (decode with grfcodec 0.9.5); comments MUST NOT contain "*"; and sprite numbers MUST be correct. Also, moving too far outside the size of the .pcx file will cause NFOEditor to crash, so save early and often.
   
 
===compression===
 
===compression===
Line 66: Line 75:
 
Unlike the other numbers, the compression is a hexadecimal bit-field. Currently, the following bits are supported:
 
Unlike the other numbers, the compression is a hexadecimal bit-field. Currently, the following bits are supported:
   
  +
{|
||bit|value|meaning
+
!bit!!value!!meaning
   
  +
|-
0|1|Color index 0 is transparent (should be '''always''' set; ignored if bit 3 is set)
+
|0||1||Color index 0 is transparent (should be '''always''' set; ignored if bit 3 is set)
   
  +
|-
1|2|Store compressed sprite in memory
+
|1||2||Store compressed sprite in memory
   
  +
|-
3|8|Sprite is in chunked data format (aka &quot;tile compression&quot;)
+
|3||8||Sprite is in chunked data format (aka "tile compression")
   
  +
|-
6|40|Sprite should not be cropped. (obeyed by GRFCodec r1604 and later)||
+
|6||40||Sprite should not be cropped. (obeyed by GRFCodec r1604 and later)
  +
|}
   
 
The chunked data format is designed to compress tiles and diagonal views of vehicles; things with lots of transparency around the edges, and a contiguous block of non-transparent pixels in the middle. Using the chunked data format may provide advantages in drawing speed.
 
The chunked data format is designed to compress tiles and diagonal views of vehicles; things with lots of transparency around the edges, and a contiguous block of non-transparent pixels in the middle. Using the chunked data format may provide advantages in drawing speed.
Line 104: Line 119:
 
===Other notes===
 
===Other notes===
   
It is a common practice, in action 1 blocks, to use the pseudosprite &quot;-1 * 1 00&quot; to take the place of a real sprite that will never be used. The most common use is for vehicle sets that will only be used in the purchase window. This reduces the size of the .grf file when compared to replacing them with one-pixel sprites (but not when compared to splitting the action 1 and making the second one define only one sprite), but does not save real-sprite slots. If TTD ever attempts to draw one of these sprites, it will, at best, crash.
+
It is a common practice, in action 1 blocks, to use the pseudosprite "-1 * 1 00" to take the place of a real sprite that will never be used. The most common use is for vehicle sets that will only be used in the purchase window. This reduces the size of the .grf file when compared to replacing them with one-pixel sprites (but not when compared to splitting the action 1 and making the second one define only one sprite), but does not save real-sprite slots. If TTD ever attempts to draw one of these sprites, it will, at best, crash.
   
 
===Transparency and glass effect===
 
===Transparency and glass effect===
Line 110: Line 125:
 
Transparency and glass effects can be achieved by means of [[RecolorSprites]]
 
Transparency and glass effects can be achieved by means of [[RecolorSprites]]
   
-=Example=-
+
==Example==
   
 
The best way to see real sprites is to decode one of TTD's standard .grf files. With very few exceptions, all sprites in those files are real sprites; the few that are not are RecolorSprites.
 
The best way to see real sprites is to decode one of TTD's standard .grf files. With very few exceptions, all sprites in those files are real sprites; the few that are not are RecolorSprites.

Revision as of 23:32, 14 June 2011

Introduction

Real Sprites

The sprites that the user actually sees.


Real sprites are the graphical part of .grf files; they are what the user actually sees in-game.

Syntax

A real sprite has the following format:

<Sprite-number> <filename> <xpos> <ypos> <compression> <ysize> <xsize> <xrel> <yrel>
Element Size Description
<Sprite-number> dec A sequential sprite number
<filename> string* The name of the .pcx file in which the sprite will be found
<xpos> dec The x position of the upper-left corner of the sprite in the file
<ypos> dec The y position of the upper-left corner of the sprite in the file
<compression> B The "compression"; see below
<ysize> dec The y size of the sprite
<xsize> dec The x size of the sprite
<xrel> dec The x position of the upper-left corner of the sprite, relative to the "center" (usually negative)
<yrel> dec The y position of the upper-left corner of the sprite, relative to the "center" (usually negative)

* Unlike strings in pseudo-sprites, this string should not have a terminating "00" and should not be placed in quotes.

Filling in the Terms

filename

This specifies the name and path of the .pcx file. The path may be specified one of two ways:

  1. An absolute path. (eg C:\GRF\sprites\filename.pcx)
  2. A relative path; these are specified relative to the location of the .grf file. (eg sprites\filename.pcx)

For most purposes, relative paths are preferred, since .nfo files with relative paths are more portable than .nfo files with absolute paths.

xpos, ypos, ysize, and xsize

These are pretty easy to set, as long as you remember that the order is X, Y, Y, X, and not X, Y, X, Y.

Also, no sprite may contain zero pixels; ysize and xsize must both be at least 1.

There is a bug in grfcodec 0.9.7 and earlier that prevents them from properly encoding a sprite with a smaller ypos value than any earlier sprite. The best way to circumvent this bug is to upgrade to the newest version.

Andrex's [1] can often be helpful for setting these four values.

WARNING: NFOEditor is replete with bugs, limitations, &c.;: You MUST specify absolute paths, and paths must be delimited by backslashes (decode with grfcodec 0.9.5); comments MUST NOT contain "*"; and sprite numbers MUST be correct. Also, moving too far outside the size of the .pcx file will cause NFOEditor to crash, so save early and often.

compression

Unlike the other numbers, the compression is a hexadecimal bit-field. Currently, the following bits are supported:

bit value meaning
0 1 Color index 0 is transparent (should be always set; ignored if bit 3 is set)
1 2 Store compressed sprite in memory
3 8 Sprite is in chunked data format (aka "tile compression")
6 40 Sprite should not be cropped. (obeyed by GRFCodec r1604 and later)

The chunked data format is designed to compress tiles and diagonal views of vehicles; things with lots of transparency around the edges, and a contiguous block of non-transparent pixels in the middle. Using the chunked data format may provide advantages in drawing speed.

The most common values for the compression are 01 and 09. 03 is useful for large sprites that are infrequently used, as it reduces memory usage at the cost of slower drawing speed. It is generally a bad idea to use any other value, as that may cause problems. FF is an especially bad idea.

xrel and yrel

These two numbers will probably become the bane of your existence.

TTD stores a single point for every sprite. xrel and yrel specify how far right and down (respectively) to go from the TTD point to the upper-left hand corner of the sprite.

Halving xsize and ysize and negating the results produces a decent starting point for these values, and further adjustments may be done manually, with NFOEditor, or (in TTDPatch 2.0.1 alpha 69 and later) with the GRFAuthorHelperWindow.

Ranges

The ranges for the four numbers after the compression are as follows:

ysize: 1..255

xsize: 1..65535

xrel: -32768..32767

yrel: -32768..32767

ysize*xsize may not exceed 65535.

Other notes

It is a common practice, in action 1 blocks, to use the pseudosprite "-1 * 1 00" to take the place of a real sprite that will never be used. The most common use is for vehicle sets that will only be used in the purchase window. This reduces the size of the .grf file when compared to replacing them with one-pixel sprites (but not when compared to splitting the action 1 and making the second one define only one sprite), but does not save real-sprite slots. If TTD ever attempts to draw one of these sprites, it will, at best, crash.

Transparency and glass effect

Transparency and glass effects can be achieved by means of RecolorSprites

Example

The best way to see real sprites is to decode one of TTD's standard .grf files. With very few exceptions, all sprites in those files are real sprites; the few that are not are RecolorSprites.

Example real sprites can also be found at the bottom of Action1 or ActionA.

Those sprites use absolute paths. Removing the C:\TTD\ part of each filename would work just as well, assuming you want the .grf file to appear in C:\TTD.