one image, multiple sprites, different colors?

Place to get help with not working mods / modding interface.
sparr
Smart Inserter
Smart Inserter
Posts: 1359
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

one image, multiple sprites, different colors?

Post by sparr »

I want to programmatically create sprites to match the custom fluid colors in other mods. Can that be done?

Supercheese
Filter Inserter
Filter Inserter
Posts: 841
Joined: Mon Sep 14, 2015 7:40 am
Contact:

Re: one image, multiple sprites, different colors?

Post 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.

sparr
Smart Inserter
Smart Inserter
Posts: 1359
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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?

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

sparr
Smart Inserter
Smart Inserter
Posts: 1359
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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?

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

sparr
Smart Inserter
Smart Inserter
Posts: 1359
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

sparr
Smart Inserter
Smart Inserter
Posts: 1359
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: one image, multiple sprites, different colors?

Post by sparr »

The biters have a complex network of functions producing their entity definitions. I haven't been able to fully follow them :(

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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)
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

sparr
Smart Inserter
Smart Inserter
Posts: 1359
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: one image, multiple sprites, different colors?

Post by sparr »

So once I define those layers, how do I pick a layer for an entity?

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

sparr
Smart Inserter
Smart Inserter
Posts: 1359
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: one image, multiple sprites, different colors?

Post by sparr »

No. I want one entity that can be blue or red, determined at run time.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

sparr
Smart Inserter
Smart Inserter
Posts: 1359
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: one image, multiple sprites, different colors?

Post by sparr »

I notice that many base decorative entities have multiple pictures. How are those selected between?

keyboardhack
Filter Inserter
Filter Inserter
Posts: 478
Joined: Sat Aug 23, 2014 11:43 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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.
Waste of bytes : P

sparr
Smart Inserter
Smart Inserter
Posts: 1359
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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?

keyboardhack
Filter Inserter
Filter Inserter
Posts: 478
Joined: Sat Aug 23, 2014 11:43 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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.
Waste of bytes : P

sparr
Smart Inserter
Smart Inserter
Posts: 1359
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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 :(

keyboardhack
Filter Inserter
Filter Inserter
Posts: 478
Joined: Sat Aug 23, 2014 11:43 pm
Contact:

Re: one image, multiple sprites, different colors?

Post 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.
Waste of bytes : P

Locked

Return to “Modding help”