Hi, I'm just getting started with modding documentation and I was wondering if someone could point me to where it is defined what an entity looks like?
Specifically, I was inspired by the 0.17 tutorial where a science lab was flashing red. How is this accomplished? Could I make labs flash different colours depending on their recipe?
Changing colour of animations
-
- Long Handed Inserter
- Posts: 93
- Joined: Thu May 18, 2017 2:22 pm
- Contact:
Re: Changing colour of animations
LuaRendering.draw_lightdanielbrauer wrote: ↑Mon Mar 04, 2019 2:19 pm
Specifically, I was inspired by the 0.17 tutorial where a science lab was flashing red. How is this accomplished? Could I make labs flash different colours depending on their recipe?
Code: Select all
rendering.draw_light(table)
Code: Select all
table = {sprite = "utility/light_small", color={r = 1, g = 0, b = 0},
surface = entity.surface,
target = entity}
-
- Long Handed Inserter
- Posts: 93
- Joined: Thu May 18, 2017 2:22 pm
- Contact:
Re: Changing colour of animations
Thanks! That seems like it will handle the light effect, and then I can probably use the tint parameter in the animation call to change its colour.
I’ll try these things out.
I’ll try these things out.
Re: Changing colour of animations
See also https://lua-api.factorio.com/latest/Lua ... _animationdanielbrauer wrote: ↑Tue Mar 05, 2019 10:34 pmThanks! That seems like it will handle the light effect, and then I can probably use the tint parameter in the animation call to change its colour.
-
- Long Handed Inserter
- Posts: 93
- Joined: Thu May 18, 2017 2:22 pm
- Contact:
Re: Changing colour of animations
Thanks. Looking at the data (the sprite sheets in base/graphics/entity/lab/) it seems I'll have to duplicate and tint the animation in its entirety, since the colour is baked in. Hopefully straightforward enough, though.
-
- Long Handed Inserter
- Posts: 93
- Joined: Thu May 18, 2017 2:22 pm
- Contact:
Re: Changing colour of animations
Ok, so thinking about this a bit more:
The lab entity has an on_animation field with several layers, one of which is the sheet with the building itself and the animated electricity.
I would like this animation to include cycles with different colours depending on the recipe being researched. e.g. early research would cause your labs to animate red electricity, and then when green science gets introduced they would alternate green/red, etc.
Can I register for on_research_started and use that to change the on_animation of the prototype at runtime, depending on the recipe?
It appears that animations need to be in a single sprite sheet. Is there any way of stitching together multiple animations so that I don't have to create enormous sheets for each permutation of colours?
The lab entity has an on_animation field with several layers, one of which is the sheet with the building itself and the animated electricity.
I would like this animation to include cycles with different colours depending on the recipe being researched. e.g. early research would cause your labs to animate red electricity, and then when green science gets introduced they would alternate green/red, etc.
Can I register for on_research_started and use that to change the on_animation of the prototype at runtime, depending on the recipe?
It appears that animations need to be in a single sprite sheet. Is there any way of stitching together multiple animations so that I don't have to create enormous sheets for each permutation of colours?
-
- Long Handed Inserter
- Posts: 93
- Joined: Thu May 18, 2017 2:22 pm
- Contact:
Re: Changing colour of animations
I did a successful proof of concept where I spliced multiple coloured versions of the lab animation into its on_animation in the data stage.
However, it seems that the animation can't be accessed after the data stage. Is there any workaround for this?
Right now I'm thinking of making one prototype for each permutation of colours, but that seems cumbersome and I'm not sure I could do the conversion efficiently or at all.
However, it seems that the animation can't be accessed after the data stage. Is there any workaround for this?
Right now I'm thinking of making one prototype for each permutation of colours, but that seems cumbersome and I'm not sure I could do the conversion efficiently or at all.
Re: Changing colour of animations
I've tried this and it works
in data.lua
May be it works for animation too, not tried.
in control.lua
in data.lua
Code: Select all
data:extend ({
{
type = "sprite",
name = sprite_name,
filename = file_path_and_name,
priority = "extra-high",
flags = {"no-crop" }, -- idk why no crop
width = 102, height = 180
}
})
in control.lua
Code: Select all
function add_glow (entity)
rendering.draw_light
{
sprite = sprite_name,
surface = entity.surface,
target = entity
}
end
-
- Long Handed Inserter
- Posts: 93
- Joined: Thu May 18, 2017 2:22 pm
- Contact:
Re: Changing colour of animations
So to be clear, what I have been trying to do is replace the on_animation of all science labs at runtime. Lights are secondary: what I want is to change the colour of the electricity in the science lab animation. The default blue is baked into the sprites, so making different colours requires more sprites.
I don't think calling animation/light functions at runtime would be a good approach. This would require me to get all the science labs in a game and do work for each of them. Modifying the prototype, or at the very least the instance data, seems like a much more reasonable option.
I don't think calling animation/light functions at runtime would be a good approach. This would require me to get all the science labs in a game and do work for each of them. Modifying the prototype, or at the very least the instance data, seems like a much more reasonable option.