Page 1 of 2

one image, multiple sprites, different colors?

Posted: Sat Jun 04, 2016 5:56 am
by sparr
I want to programmatically create sprites to match the custom fluid colors in other mods. Can that be done?

Re: one image, multiple sprites, different colors?

Posted: Sat Jun 04, 2016 8:03 am
by Supercheese
You can make use of the "tint" property to repurpose existing sprites into recolored ones.

For an example, you can check how the base game assembles biter/spitter/spawner sprites.

Re: one image, multiple sprites, different colors?

Posted: Sat Jun 04, 2016 9:01 am
by sparr
Using the tint property will mean defining many different entities, but I'll just need one sprite image?

Is there a way to have just one entity and multiple colors of it?

Re: one image, multiple sprites, different colors?

Posted: Mon Jun 06, 2016 8:07 am
by bobingabout
to properly use tint, you should recolour the image to white first in a program like photoshop. this will allow it to remap to any colour and look right, otherwise it'll skew and look off when using colours that aren't already in the entity.

Re: one image, multiple sprites, different colors?

Posted: Mon Jun 06, 2016 8:43 am
by sparr
Yeah, I've got it working with one white sprite and many entities with tinted pictures (https://github.com/sparr/factorio-mod-w ... lua#L7-L33)

Is there any way I can get one entity to show up in different colors?

Re: one image, multiple sprites, different colors?

Posted: Mon Jun 06, 2016 3:55 pm
by bobingabout
Split your sprite into multiple parts, you can then use the layers definition to use multiple tint layers, and give each a different tint colour.

Re: one image, multiple sprites, different colors?

Posted: Mon Jun 06, 2016 7:38 pm
by sparr
Can you give me an example of that? Say if I have one entity that I'd like to display in two different colors.

Re: one image, multiple sprites, different colors?

Posted: Tue Jun 07, 2016 7:57 am
by bobingabout
Look at the Biters.
The behemoth for example has green with orange stripes. These are all from one master set of Biter sprite sheets.

Re: one image, multiple sprites, different colors?

Posted: Tue Jun 07, 2016 3:21 pm
by sparr
The biters have a complex network of functions producing their entity definitions. I haven't been able to fully follow them :(

Re: one image, multiple sprites, different colors?

Posted: Tue Jun 07, 2016 3:54 pm
by bobingabout
Basically.....

Code: Select all

animation={
  layers={
    {layer 1 definition},
    {layer 2 definition},
    {layer 3 definition}
  }
}

Layer 1 would be the image that doesn't change colours at all.
Layer 2 would have a tint= tag that uses tint colour 1.
Layer 3 would have a tint= tag that uses tint colour 2.

That's about it.

It's pretty much just the same thing you'd do with adding 1 tint layer, but instead of just 1, you add 2. or 3... there's really no limit. (though practically, you don't want too many)

Re: one image, multiple sprites, different colors?

Posted: Wed Jun 08, 2016 3:19 am
by sparr
So once I define those layers, how do I pick a layer for an entity?

Re: one image, multiple sprites, different colors?

Posted: Thu Jun 09, 2016 9:30 am
by bobingabout
I don't understand the question... all layers would be on the entity simultaneously, they're drawn on top of each other.

I thought that's what you wanted, an entity that has more than one tint shown simultaneously.

Re: one image, multiple sprites, different colors?

Posted: Thu Jun 09, 2016 10:52 am
by sparr
No. I want one entity that can be blue or red, determined at run time.

Re: one image, multiple sprites, different colors?

Posted: Thu Jun 09, 2016 2:14 pm
by bobingabout
That's what Tint does... though as far as I know, the tint is pre-set per entity. I think there's a tag (used on turrets, and maybe cars) that changes colour to match that of the player that placed it, but one that changes colour on runtime? I don't think that's possible.

Re: one image, multiple sprites, different colors?

Posted: Thu Jun 09, 2016 3:57 pm
by sparr
I notice that many base decorative entities have multiple pictures. How are those selected between?

Re: one image, multiple sprites, different colors?

Posted: Thu Jun 09, 2016 7:58 pm
by keyboardhack
This won't work for all entities as not all support it.
You can use the property apply_runtime_tint which does the same as a tint but the color is determined by the color of the player who placed the entity which can be changed at runtime.
Here is an example of how to use it(code is from the gate)

Code: Select all

vertical_base =
    {
      layers =
      {
        {
          filename = "__base__/graphics/entity/gate/gate-base-vertical.png",
          width = 32,
          height = 32
        },
        {
          filename = "__base__/graphics/entity/gate/gate-base-vertical-mask.png",
          width = 32,
          height = 32,
          apply_runtime_tint = true
        }
      }
    }
Now when you want to change the color of your entity you just change the color of the player who placed the entity. To not change an actual playing players color you should make a dummy player and use it to place the entities for you.

Re: one image, multiple sprites, different colors?

Posted: Thu Jun 09, 2016 8:02 pm
by sparr
That's a clever hack. Does the entity color change when the player's color changes later, or can I use one dummy player to set a bunch of entities to different colors one at a time?

Re: one image, multiple sprites, different colors?

Posted: Thu Jun 09, 2016 8:05 pm
by keyboardhack
sparr wrote:That's a clever hack. Does the entity color change when the player's color changes later, or can I use one dummy player to set a bunch of entities to different colors one at a time?
The entities color changes the instant the players color changes which means you would need multiple players if you wanted different entities to be different colors.

Re: one image, multiple sprites, different colors?

Posted: Thu Jun 09, 2016 8:07 pm
by sparr
Damn, that doesn't help, then. If I want 16 colors I have to create 16 entities or 16 players, no improvement either way. I'm trying to make fewer than 16 new things :(

Re: one image, multiple sprites, different colors?

Posted: Thu Jun 09, 2016 8:16 pm
by keyboardhack
sparr wrote:Damn, that doesn't help, then. If I want 16 colors I have to create 16 entities or 16 players, no improvement either way. I'm trying to make fewer than 16 new things :(
In that case you could use cars. When you want a new color you just change the direction of the car because the car uses a different sprite for each direction. Set the cars property operable to false and remove the flags "pushable" and "placeable-off-grid" and then the car should behave like a static entity. use direction to change the direction of the car.
Have a look at how Nixie tubes uses a cars directions to change what the car looks like.