Changing colour of animations

Place to get help with not working mods / modding interface.
Post Reply
danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu May 18, 2017 2:22 pm
Contact:

Changing colour of animations

Post by danielbrauer »

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?

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Changing colour of animations

Post by darkfrei »

danielbrauer 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?
LuaRendering.draw_light

Code: Select all

rendering.draw_light(table)
Where table is

Code: Select all

table = {sprite = "utility/light_small", color={r = 1, g = 0, b = 0},
      surface = entity.surface,
      target = entity}

danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu May 18, 2017 2:22 pm
Contact:

Re: Changing colour of animations

Post by danielbrauer »

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.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Changing colour of animations

Post by darkfrei »

danielbrauer wrote:
Tue Mar 05, 2019 10:34 pm
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.
See also https://lua-api.factorio.com/latest/Lua ... _animation

danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu May 18, 2017 2:22 pm
Contact:

Re: Changing colour of animations

Post by danielbrauer »

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.

danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu May 18, 2017 2:22 pm
Contact:

Re: Changing colour of animations

Post by danielbrauer »

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?

danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu May 18, 2017 2:22 pm
Contact:

Re: Changing colour of animations

Post by danielbrauer »

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.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Changing colour of animations

Post by darkfrei »

I've tried this and it works
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
  }
})
May be it works for animation too, not tried.

in control.lua

Code: Select all

function add_glow (entity)
  rendering.draw_light 
    {
      sprite = sprite_name,
      surface = entity.surface,
      target = entity
    }
end

danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu May 18, 2017 2:22 pm
Contact:

Re: Changing colour of animations

Post by danielbrauer »

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.

Post Reply

Return to “Modding help”