Prototype/Sprite: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
m (whitespace)
(Updated styling of prototype doc migration note)
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<div class="stub"><p>'''The prototype docs have moved to a new website with an improved format.''' This documentation page can now be found here: [https://lua-api.factorio.com/latest/prototypes/SpritePrototype.html https://lua-api.factorio.com/latest/prototypes/SpritePrototype.html]
</p><p>This wiki page is no longer updated and '''will be removed at some point in the future''', so please update your browser bookmarks or other links that sent you here. If you'd like to contribute to the new docs, you can leave your feedback [https://forums.factorio.com/viewforum.php?f=233 on the forums].</p></div>
{{Prototype parent}}
{{Prototype parent}}
Specifies a picture that can be used with https://lua-api.factorio.com/latest/Concepts.html#SpritePath during runtime.
Specifies a picture that can be used with https://lua-api.factorio.com/latest/Concepts.html#SpritePath during runtime.
Line 20: Line 26:
If this property is present, all Sprite definitions have to be placed as entries in the array, and they will all be loaded from there. Each item (Sprite definition) in the array may also have the <code>layers</code> property.
If this property is present, all Sprite definitions have to be placed as entries in the array, and they will all be loaded from there. Each item (Sprite definition) in the array may also have the <code>layers</code> property.


If this property is present, all other properties are ignored and the mandatory properties do not have to be defined.
If this property is present, <code>filename</code> and all other optional properties are ignored. The mandatory properties <code>name</code> and <code>type</code> still have to be defined.
 
Layers may not be an empty table.


{{Prototype property|hr_version|[[Types/Sprite|Sprite]]|optional=true}}
{{Prototype property|hr_version|[[Types/Sprite|Sprite]]|optional=true}}
If this property exists and high resolution sprites are turned on, its contents are used to load the sprite.
If this property exists and high resolution sprites are turned on, its contents are used to load the sprite.


{{Prototype property|slice|[[Types/SpriteSizeType|SpriteSizeType]]|optional=true}}
{{Prototype property|slice or dice|[[Types/SpriteSizeType|SpriteSizeType]]|optional=true}}
Number of slices this is sliced into when using the "optimized atlas packing" option. If you are a modder, you can just ignore this property.
Number of slices this is sliced into when using the "optimized atlas packing" option. If you are a modder, you can just ignore this property.


Example: If this is 4, the sprite will be sliced into a 4×4 grid.
Example: If this is 4, the sprite will be sliced into a 4×4 grid.


{{Prototype property|slice_x|[[Types/SpriteSizeType|SpriteSizeType]]|optional=true}}
{{Prototype property|slice_x or dice_x|[[Types/SpriteSizeType|SpriteSizeType]]|optional=true}}
Same as <code>slice</code> above, but this specifies only how many slices there are on the x axis.
Same as <code>slice</code> above, but this specifies only how many slices there are on the x axis.


{{Prototype property|slice_y|[[Types/SpriteSizeType|SpriteSizeType]]|optional=true}}
{{Prototype property|slice_y or dice_y|[[Types/SpriteSizeType|SpriteSizeType]]|optional=true}}
Same as <code>slice</code> above, but this specifies only how many slices there are on the y axis.
Same as <code>slice</code> above, but this specifies only how many slices there are on the y axis.


{{Prototype property|priority|[[Types/string|string]]|"medium"|optional=true}}
{{Prototype property|priority|[[Types/SpritePriority|SpritePriority]]|"medium"|optional=true}}
Possible values:
* "extra-high-no-scale"
* "extra-high"
* "high"
* "medium"
* "low"
* "very-low"


{{Prototype property|flags|[[Types/SpriteFlags|SpriteFlags]]||optional=true}}
{{Prototype property|flags|[[Types/SpriteFlags|SpriteFlags]]|optional=true}}


{{Prototype property|size|[[Types/SpriteSizeType|SpriteSizeType]] or [[Types/table|table]] of [[Types/SpriteSizeType|SpriteSizeType]]|optional=true}}
{{Prototype property|size|[[Types/SpriteSizeType|SpriteSizeType]] or [[Types/table|table]] of [[Types/SpriteSizeType|SpriteSizeType]]|optional=true}}
Line 75: Line 76:


{{Prototype property|draw_as_shadow|[[Types/bool|bool]]|false|optional=true}}
{{Prototype property|draw_as_shadow|[[Types/bool|bool]]|false|optional=true}}
Only one of <code>draw_as_shadow</code>, <code>draw_as_glow</code> and <code>draw_as_light</code> can be true. <code>draw_as_shadow</code> takes precedence over <code>draw_as_glow</code> and <code>draw_as_light</code>.
{{Prototype property|draw_as_glow |[[Types/bool|bool]]|false|optional=true}}
Only one of <code>draw_as_shadow</code>, <code>draw_as_glow</code> and <code>draw_as_light</code> can be true. <code>draw_as_glow</code> takes precedence over <code>draw_as_light</code>.
Draws first as a normal sprite, and again as a light layer.<sup>[https://forums.factorio.com/91682]</sup>
{{Prototype property|draw_as_light |[[Types/bool|bool]]|false|optional=true}}
Only one of <code>draw_as_shadow</code>, <code>draw_as_glow</code> and <code>draw_as_light</code> can be true.


{{Prototype property|mipmap_count|[[Types/uint8|uint8]]|0|optional=true}}
{{Prototype property|mipmap_count|[[Types/uint8|uint8]]|0|optional=true}}
Only loaded if this is an icon (has flag "icon").
Only loaded if this is an icon (has flag "group=icon" or "group=gui").


{{Prototype property|apply_runtime_tint|[[Types/bool|bool]]|false|optional=true}}
{{Prototype property|apply_runtime_tint|[[Types/bool|bool]]|false|optional=true}}
Line 83: Line 93:
{{Prototype property|tint|[[Types/Color|Color]]|<nowiki>{r=1, g=1, b=1, a=1} (white)</nowiki>|optional=true}}
{{Prototype property|tint|[[Types/Color|Color]]|<nowiki>{r=1, g=1, b=1, a=1} (white)</nowiki>|optional=true}}


{{Prototype property|blend_mode|[[Types/string|string]]|"normal"|optional=true}}
{{Prototype property|blend_mode|[[Types/BlendMode|BlendMode]]|"normal"|optional=true}}
Possible values:
* "normal"          ''-- Result = Active_RGB * Active_Alpha + Background_RGB * ( 1 - Active_Alpha )''
* "additive"        ''-- Result = Active_RGB + Background_RGB''
* "additive-soft"    ''-- Result = Active_RGB * ( 1 - Background_RGB ) + Background_RGB''
* "multiplicative"  ''-- Result = Active_RGB * Background_RGB''
* "overwrite"        ''-- Result = Active_RGBA or Background_RGBA''
 
Note: Unless <code>premul_alpha</code> is set to false, Active_RGB is considered to be premultiplied with alpha.


{{Prototype property|load_in_minimal_mode|[[Types/bool|bool]]|false|optional=true}}
{{Prototype property|load_in_minimal_mode|[[Types/bool|bool]]|false|optional=true}}
Line 100: Line 102:


{{Prototype property|generate_sdf|[[Types/bool|bool]]|false|optional=true}}
{{Prototype property|generate_sdf|[[Types/bool|bool]]|false|optional=true}}
Unused.


== Example ==
== Example ==

Latest revision as of 10:43, 21 September 2023

The prototype docs have moved to a new website with an improved format. This documentation page can now be found here: https://lua-api.factorio.com/latest/prototypes/SpritePrototype.html

This wiki page is no longer updated and will be removed at some point in the future, so please update your browser bookmarks or other links that sent you here. If you'd like to contribute to the new docs, you can leave your feedback on the forums.


Prototype definitions » Prototype/Sprite


Specifies a picture that can be used with https://lua-api.factorio.com/latest/Concepts.html#SpritePath during runtime.


Prototype/Sprite — sprite
filename::FileName
name::string
type::string
apply_runtime_tint::bool (optional)
blend_mode::BlendMode (optional)
draw_as_glow::bool (optional)
draw_as_light::bool (optional)
draw_as_shadow::bool (optional)
flags::SpriteFlags (optional)
generate_sdf::bool (optional)
height::SpriteSizeType (optional)
hr_version::Sprite (optional)
layers::table of Sprite (optional)
load_in_minimal_mode::bool (optional)
mipmap_count::uint8 (optional)
position::table of SpriteSizeType (optional)
premul_alpha::bool (optional)
priority::SpritePriority (optional)
scale::double (optional)
shift::vector (optional)
size::SpriteSizeType or table of SpriteSizeType (optional)
slice or dice::SpriteSizeType (optional)
slice_x or dice_x::SpriteSizeType (optional)
slice_y or dice_y::SpriteSizeType (optional)
tint::Color (optional)
width::SpriteSizeType (optional)
x::SpriteSizeType (optional)
y::SpriteSizeType (optional)

Mandatory properties

type

Type: string
Must be "sprite".

name

Type: string
Name of the sprite. Must be unique. Can be used as a https://lua-api.factorio.com/latest/Concepts.html#SpritePath.

filename

Type: FileName
Default: ""
Technically optional, but path to sprite cannot be empty.

Optional properties

layers

Type: table of Sprite
If this property is present, all Sprite definitions have to be placed as entries in the array, and they will all be loaded from there. Each item (Sprite definition) in the array may also have the layers property.

If this property is present, filename and all other optional properties are ignored. The mandatory properties name and type still have to be defined.

Layers may not be an empty table.

hr_version

Type: Sprite
If this property exists and high resolution sprites are turned on, its contents are used to load the sprite.

slice or dice

Type: SpriteSizeType
Number of slices this is sliced into when using the "optimized atlas packing" option. If you are a modder, you can just ignore this property.

Example: If this is 4, the sprite will be sliced into a 4×4 grid.

slice_x or dice_x

Type: SpriteSizeType
Same as slice above, but this specifies only how many slices there are on the x axis.

slice_y or dice_y

Type: SpriteSizeType
Same as slice above, but this specifies only how many slices there are on the y axis.

priority

Type: SpritePriority
Default: "medium"

flags

Type: SpriteFlags

size

Type: SpriteSizeType or table of SpriteSizeType
The width and height of the sprite. If this is an array, the first member of the array is the width and the second is the height. Otherwise the size is both width and height.

Width and height may only be in the range of 0-8192.

width

Type: SpriteSizeType
Mandatory if size is not given. Width of the picture in pixels, from 0-8192.

height

Type: SpriteSizeType
Mandatory if size is not given. Height of the picture in pixels, from 0-8192.

x

Type: SpriteSizeType
Default: 0
Horizontal position of the sprite in the source file in pixels.

y

Type: SpriteSizeType
Default: 0
Vertical position of the sprite in the source file in pixels.

position

Type: table of SpriteSizeType
Loaded only when x and y are both 0. The first member of the array is x and the second is y.

shift

Type: vector
Default: {0, 0}
In tiles. util.by_pixel() can be used to divide the shift by 32 which is the usual pixel height/width of 1 tile in normal resolution. Note that 32 pixel tile height/width is not enforced anywhere - any other tile height or width is also possible.

scale

Type: double
Default: 1
Values different than 1 specify the scale of the sprite on default zoom. Scale 2 means that the picture will be 2 times bigger on screen (and more pixelated).

draw_as_shadow

Type: bool
Default: false
Only one of draw_as_shadow, draw_as_glow and draw_as_light can be true. draw_as_shadow takes precedence over draw_as_glow and draw_as_light.

draw_as_glow

Type: bool
Default: false
Only one of draw_as_shadow, draw_as_glow and draw_as_light can be true. draw_as_glow takes precedence over draw_as_light.

Draws first as a normal sprite, and again as a light layer.[1]

draw_as_light

Type: bool
Default: false
Only one of draw_as_shadow, draw_as_glow and draw_as_light can be true.

mipmap_count

Type: uint8
Default: 0
Only loaded if this is an icon (has flag "group=icon" or "group=gui").

apply_runtime_tint

Type: bool
Default: false

tint

Type: Color
Default: {r=1, g=1, b=1, a=1} (white)

blend_mode

Type: BlendMode
Default: "normal"

load_in_minimal_mode

Type: bool
Default: false
Minimal mode is entered when mod loading fails. You are in it when you see the gray box after (part of) the loading screen that tells you a mod error (Example). If you are a modder, you can just ignore this property.

premul_alpha

Type: bool
Default: true
Whether alpha should be premultiplied.

generate_sdf

Type: bool
Default: false
Unused.

Example

   {
     type = "sprite"
     name = "accumulator-sprite",
     filename = "__base__/graphics/entity/basic-accumulator/basic-accumulator.png",
     priority = "extra-high",
     width = 124,
     height = 103,
     shift = {0.7, -0.2}
   }