How do I change entity color?

Place to get help with not working mods / modding interface.
User avatar
thereaverofdarkness
Filter Inserter
Filter Inserter
Posts: 561
Joined: Wed Jun 01, 2016 5:07 am
Contact:

How do I change entity color?

Post by thereaverofdarkness »

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.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: How do I change entity color?

Post by bobingabout »

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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
thereaverofdarkness
Filter Inserter
Filter Inserter
Posts: 561
Joined: Wed Jun 01, 2016 5:07 am
Contact:

Re: How do I change entity color?

Post by thereaverofdarkness »

That's what I wanted to do, just add the tint tag. Where do I put it and how do I format it?

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 },
  },
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.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: How do I change entity color?

Post by darkfrei »

thereaverofdarkness wrote:That's what I wanted to do, just add the tint tag. Where do I put it and how do I format it?
code
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.
It's function, so you need

Code: Select all

tint = {r=178/255, g=173/255, b=100/255}
And place tint near your filename:

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
          }
        },
New icons (instead of icon):

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.
User avatar
thereaverofdarkness
Filter Inserter
Filter Inserter
Posts: 561
Joined: Wed Jun 01, 2016 5:07 am
Contact:

Re: How do I change entity color?

Post by thereaverofdarkness »

I put it in like you said:

Code: Select all

    {
      filename = "__base__/graphics/entity/radar/radar-integration.png",
      local tint = {r=128/255, g=0/255, b=0/255},
      priority = "low",
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'
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: How do I change entity color?

Post by darkfrei »

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'
Here just so:

Code: Select all

  filename = "__base__/graphics/entity/radar/radar-integration.png",
  tint = {r=128/255, g=0/255, b=0/255},
  priority = "low",
See also manual (15 minutes): http://tylerneylon.com/a/learn-lua/
User avatar
thereaverofdarkness
Filter Inserter
Filter Inserter
Posts: 561
Joined: Wed Jun 01, 2016 5:07 am
Contact:

Re: How do I change entity color?

Post by thereaverofdarkness »

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.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: How do I change entity color?

Post by darkfrei »

thereaverofdarkness wrote:It loads the mod, but the radar is not tinted at all.
Just attach your mod, then it will be much easy to understand your code.
User avatar
fishycat
Filter Inserter
Filter Inserter
Posts: 315
Joined: Thu Apr 09, 2015 7:38 pm
Contact:

Re: How do I change entity color?

Post by fishycat »

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 = ...
User avatar
thereaverofdarkness
Filter Inserter
Filter Inserter
Posts: 561
Joined: Wed Jun 01, 2016 5:07 am
Contact:

Re: How do I change entity color?

Post by thereaverofdarkness »

darkfrei wrote:
thereaverofdarkness wrote:It loads the mod, but the radar is not tinted at all.
Just attach your mod, then it will be much easy to understand your code.
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.

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 = ...
D'oh! So I did.
Got it working.

Image

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.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: How do I change entity color?

Post by bobingabout »

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 :P
Don't bother including alpha, I just added it so you can see that it is an option.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
thereaverofdarkness
Filter Inserter
Filter Inserter
Posts: 561
Joined: Wed Jun 01, 2016 5:07 am
Contact:

Re: How do I change entity color?

Post by thereaverofdarkness »

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?
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: How do I change entity color?

Post by bobingabout »

In theory you could try and set a value higher than 1, but I've not tried it personally.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
Post Reply

Return to “Modding help”