How do I change entity color?
- thereaverofdarkness
- Filter Inserter
- Posts: 561
- Joined: Wed Jun 01, 2016 5:07 am
- Contact:
How do I change entity color?
I made a radar mod and I want to change the spawned entities to be color tinted like the icons. I could just add color-tinted copies of the entity graphics, but I figure it'll be easier on people's video memory if I instead simply add a color mask to the entities. Is there a way to do this? If so, how do I do it?
I can determine the color values needed. I just need to know what code to use.
I can determine the color values needed. I just need to know what code to use.
Re: How do I change entity color?
Tint everything viewtopic.php?f=34&t=51574
Easy tinted entities:
https://mods.factorio.com/mod/AllMyFluids
https://mods.factorio.com/mod/df_belt_graphics
https://mods.factorio.com/mod/Loader-Furnace
And also inserters https://mods.factorio.com/mod/LinearInserters [0.15]
So, just picture with grayscale and tint={r=1, g=0.5, b=0}
Easy tinted entities:
https://mods.factorio.com/mod/AllMyFluids
https://mods.factorio.com/mod/df_belt_graphics
https://mods.factorio.com/mod/Loader-Furnace
And also inserters https://mods.factorio.com/mod/LinearInserters [0.15]
So, just picture with grayscale and tint={r=1, g=0.5, b=0}
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: How do I change entity color?
if you really wanted to, you could just copy the existing graphics code as is, but add the tint tag in there to change it's colour. It won't look as good as being edited to greyscale, or a custom made mask would, but it would work.
- thereaverofdarkness
- Filter Inserter
- Posts: 561
- Joined: Wed Jun 01, 2016 5:07 am
- Contact:
Re: How do I change entity color?
That's what I wanted to do, just add the tint tag. Where do I put it and how do I format it?
I tried putting in
tint = RGB{178, 173, 100}
As it is formatted in darkfrei's mod, but the mod won't even load until I nest it in brackets. But even then, it does not affect the color of the entity in-game.
Code: Select all
data:extend({
{
type = "radar",
name = "radar-red",
icon = "__base__/graphics/icons/radar.png",
icon_size = 32,
flags = {"placeable-player", "player-creation"},
minable = {hardness = 0.2, mining_time = 0.5, result = "radar-red"},
max_health = 800,
corpse = "big-remnants",
resistances =
{
{
type = "fire",
percent = 70
},
{
type = "impact",
percent = 30
}
},
collision_box = {{-1.4, -1.4}, {1.4, 1.4}},
selection_box = {{-1.5, -1.5}, {1.5, 1.5}},
energy_per_sector = "225kJ",
max_distance_of_sector_revealed = 8,
max_distance_of_nearby_sector_revealed = 4,
energy_per_nearby_scan = "2250kJ",
energy_source =
{
type = "electric",
usage_priority = "secondary-input"
},
energy_usage = "450kW",
integration_patch =
{
filename = "__base__/graphics/entity/radar/radar-integration.png",
priority = "low",
width = 119,
height = 108,
apply_projection = false,
direction_count = 1,
repeat_count = 64,
line_length = 1,
shift = util.by_pixel(1.5, 4),
hr_version =
{
filename = "__base__/graphics/entity/radar/hr-radar-integration.png",
priority = "low",
width = 238,
height = 216,
apply_projection = false,
direction_count = 1,
repeat_count = 64,
line_length = 1,
shift = util.by_pixel(1.5, 4),
scale = 0.5
}
},
pictures =
{
layers =
{
{
filename = "__base__/graphics/entity/radar/radar.png",
priority = "low",
width = 98,
height = 128,
apply_projection = false,
direction_count = 64,
line_length = 8,
shift = util.by_pixel(1, -16),
hr_version = {
filename = "__base__/graphics/entity/radar/hr-radar.png",
priority = "low",
width = 196,
height = 254,
apply_projection = false,
direction_count = 64,
line_length = 8,
shift = util.by_pixel(1, -16),
scale = 0.5
}
},
{
filename = "__base__/graphics/entity/radar/radar-shadow.png",
priority = "low",
width = 172,
height = 94,
apply_projection = false,
direction_count = 64,
line_length = 8,
shift = util.by_pixel(39,3),
draw_as_shadow = true,
hr_version = {
filename = "__base__/graphics/entity/radar/hr-radar-shadow.png",
priority = "low",
width = 343,
height = 186,
apply_projection = false,
direction_count = 64,
line_length = 8,
shift = util.by_pixel(39.25,3),
draw_as_shadow = true,
scale = 0.5
}
}
}
},
vehicle_impact_sound = { filename = "__base__/sound/car-metal-impact.ogg", volume = 0.65 },
working_sound =
{
sound = {
{
filename = "__base__/sound/radar.ogg"
}
},
apparent_volume = 2,
},
radius_minimap_visualisation_color = { r = 0.059, g = 0.092, b = 0.235, a = 0.275 },
},
tint = RGB{178, 173, 100}
As it is formatted in darkfrei's mod, but the mod won't even load until I nest it in brackets. But even then, it does not affect the color of the entity in-game.
Re: How do I change entity color?
It's function, so you needthereaverofdarkness wrote:That's what I wanted to do, just add the tint tag. Where do I put it and how do I format it?
codeI tried putting in
tint = RGB{178, 173, 100}
As it is formatted in darkfrei's mod, but the mod won't even load until I nest it in brackets. But even then, it does not affect the color of the entity in-game.
Code: Select all
tint = {r=178/255, g=173/255, b=100/255}
Code: Select all
{
filename = "__base__/graphics/entity/radar/radar.png",
tint=tint, -- it was(must be) predefined above
priority = "low",
width = 98,
height = 128,
apply_projection = false,
direction_count = 64,
line_length = 8,
shift = util.by_pixel(1, -16),
hr_version = {
filename = "__base__/graphics/entity/radar/hr-radar.png",
tint=tint,
priority = "low",
width = 196,
height = 254,
apply_projection = false,
direction_count = 64,
line_length = 8,
shift = util.by_pixel(1, -16),
scale = 0.5
}
},
Code: Select all
-- icon = "__base__/graphics/icons/radar.png",
icons = {{icon = "__base__/graphics/icons/radar.png", tint=tint}},
icon_size = 32,
Last edited by darkfrei on Tue May 15, 2018 6:44 pm, edited 1 time in total.
- thereaverofdarkness
- Filter Inserter
- Posts: 561
- Joined: Wed Jun 01, 2016 5:07 am
- Contact:
Re: How do I change entity color?
I put it in like you said:
And I'm getting this error:
Failed to load mods: __Reavers_RGB_Radars__/data.lua:3: __Reavers_RGB_Radars__/prototypes/entity.lua:37: unexpected symbol near 'local'
Code: Select all
{
filename = "__base__/graphics/entity/radar/radar-integration.png",
local tint = {r=128/255, g=0/255, b=0/255},
priority = "low",
Failed to load mods: __Reavers_RGB_Radars__/data.lua:3: __Reavers_RGB_Radars__/prototypes/entity.lua:37: unexpected symbol near 'local'
Re: How do I change entity color?
Here just so:thereaverofdarkness wrote:And I'm getting this error:
Failed to load mods: __Reavers_RGB_Radars__/data.lua:3: __Reavers_RGB_Radars__/prototypes/entity.lua:37: unexpected symbol near 'local'
Code: Select all
filename = "__base__/graphics/entity/radar/radar-integration.png",
tint = {r=128/255, g=0/255, b=0/255},
priority = "low",
- thereaverofdarkness
- Filter Inserter
- Posts: 561
- Joined: Wed Jun 01, 2016 5:07 am
- Contact:
Re: How do I change entity color?
It loads the mod, but the radar is not tinted at all.
I find it extremely difficult to learn code from manuals like that. The way they present the code is far too human and organic. I might feel like I understand it, but it won't help me when I'm neck-deep in syntax errors and the error messages almost unconditionally point to the wrong part of the mod. The best way for me to understand how the code works is to see examples of it that function.
I find it extremely difficult to learn code from manuals like that. The way they present the code is far too human and organic. I might feel like I understand it, but it won't help me when I'm neck-deep in syntax errors and the error messages almost unconditionally point to the wrong part of the mod. The best way for me to understand how the code works is to see examples of it that function.
Re: How do I change entity color?
Just attach your mod, then it will be much easy to understand your code.thereaverofdarkness wrote:It loads the mod, but the radar is not tinted at all.
Re: How do I change entity color?
You placed it in radar-integration.png, you want to place the tint in picture layers, under
Code: Select all
filename = "__base__/graphics/entity/radar/radar.png",
tint = ...
- thereaverofdarkness
- Filter Inserter
- Posts: 561
- Joined: Wed Jun 01, 2016 5:07 am
- Contact:
Re: How do I change entity color?
I already linked the mod in the OP. I guess I didn't make it clear enough. I apologize. I got it solved anyway though.darkfrei wrote:Just attach your mod, then it will be much easy to understand your code.thereaverofdarkness wrote:It loads the mod, but the radar is not tinted at all.
D'oh! So I did.fishycat wrote:You placed it in radar-integration.png, you want to place the tint in picture layers, under
Code: Select all
filename = "__base__/graphics/entity/radar/radar.png", tint = ...
Got it working.

So I see that the tint function alters the existing color levels in the entity. So 255/255 for all 3 colors results in the same image as untinted. This is nice because it preserves the shadows, but has the drawback of making the tinted image always darker than the original. Still works, actually works better than I expected. The red and green radar above are using 255/255 for their color and 127/255 for the other two colors, but I'll play with the values until I like the result.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: How do I change entity color?
I'm not sure where the 255/255 part came from. it just wants a value between 0 and 1 (Which I guess works with a divide)
EG
tint = {r = 1, g = 0.5, b = 0, a = 0.5}
a is Alpha, 0.5 makes it semi-transparent
Don't bother including alpha, I just added it so you can see that it is an option.
EG
tint = {r = 1, g = 0.5, b = 0, a = 0.5}
a is Alpha, 0.5 makes it semi-transparent

Don't bother including alpha, I just added it so you can see that it is an option.
- thereaverofdarkness
- Filter Inserter
- Posts: 561
- Joined: Wed Jun 01, 2016 5:07 am
- Contact:
Re: How do I change entity color?
Ah, that makes sense.
Is there a way to increase colors above the base value? Like a reverse tint, with 0 being the original sprite and 1 being white?
Is there a way to increase colors above the base value? Like a reverse tint, with 0 being the original sprite and 1 being white?
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: How do I change entity color?
In theory you could try and set a value higher than 1, but I've not tried it personally.