Types/Animation

From Official Factorio Wiki
Jump to navigation Jump to search

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/types/Animation.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.


Basics

Specifies animation that can be used in the game.

Note that if any frame of the animation is specified from the same source as any other Types/Sprite or frame of other animation, it will be shared.

Optional properties

layers

Type: Types/table of Types/Animation

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

If this property is present, all other properties are ignored and the mandatory properties do not have to be defined.

Layers may not be an empty table.

hr_version

Type: Types/Animation

If this property exists and high resolution sprites are turned on, its contents are used to load the Animation.

filename

Type: Types/FileName

Default: ""

Mandatory if "stripes" is not specified.

priority

Type: Types/SpritePriority

Default: "medium"

flags

Type: Types/SpriteFlags

size

Type: Types/SpriteSizeType or Types/table of Types/SpriteSizeType

The width and height of the one frame. 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: Types/SpriteSizeType

Mandatory if size is not given. Width of one frame in pixels, from 0-8192.

height

Type: Types/SpriteSizeType

Mandatory if size is not given. Height of one frame in pixels, from 0-8192.

x

Type: Types/SpriteSizeType

Default: 0

Horizontal position of the animation in the source file in pixels.

y

Type: Types/SpriteSizeType

Default: 0

Vertical position of the animation in the source file in pixels.

position

Type: Types/table of Types/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: Types/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: Types/double

Default: 1

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

draw_as_shadow

Type: Types/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: Types/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: Types/bool

Default: false

Only one of draw_as_shadow, draw_as_glow and draw_as_light can be true.

mipmap_count

Type: Types/uint8

Default: 0

Only loaded if this is an icon (has flag "group=icon" or "group=gui").
Note: mipmap_count doesn't make sense in animation, as it is not possible to layout mipmaps in a way, that would load correctly both the animation and the mipmaps (besides animations with just one frame).[2]

apply_runtime_tint

Type: Types/bool

Default: false

tint

Type: Types/Color

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

blend_mode

Type: Types/BlendMode

Default: "normal"

load_in_minimal_mode

Type: Types/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: Types/bool

Default: true

Whether alpha should be premultiplied.

generate_sdf

Type: Types/bool

Default: false

Unused.

run_mode

Type: Types/string

Default: "forward"

Possible values are:

  • forward
  • backward
  • forward-then-backward

frame_count

Type: Types/uint32

Default: 1

Can't be 0.

line_length

Type: Types/uint32

Default: 0

Once the specified number of pictures is loaded, other pictures are loaded on other line. This is to allow having longer animations in matrix, to input files with too high width. The game engine limits the width of any input files to 8192px, so it is compatible with most graphics cards. 0 means that all the pictures are in one horizontal line.

animation_speed

Type: Types/float

Default: 1

Modifier of the animation playing speed, the default is 1, which means one animation frame per tick (60 fps). The speed of playing can often vary depending on the usage (output of steam engine for example). Has to be greater than 0. If layers are used then the animation_speed only has to be defined in one layer. All layers will run at the same speed.

max_advance

Type: Types/float

Default: MAX_FLOAT

If layers are used then max_advance only has to be defined in one layer.

repeat_count

Type: Types/uint8

Default: 1

How many times to repeat the animation to complete an animation cycle. E.g. if one layer is 10 frames, a second layer of 1 frame would need repeat_count = 10 to match the complete cycle.

Can't be 0.

dice

Type: Types/uint8

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.

dice_x

Type: Types/uint8

Same as dice above, but this specifies only how many slices there are on the x axis.

dice_y

Type: Types/uint8

Same as dice above, but this specifies only how many slices there are on the y axis.

frame_sequence

Type: Types/AnimationFrameSequence

stripes

Type: table (array) of Stripe

Example

Specification of animation of a beacon

animation =
{
  filename = "__base__/graphics/entity/beacon/beacon-antenna.png",
  width = 54,
  height = 50,
  line_length = 8,
  frame_count = 32,
  shift = { -0.03125, -1.71875},
  animation_speed = 0.5
},

Prototype properties that use this type