"Replace Color" action for Sprite object

This forum is currently in read-only mode.
From the Asset Store
Alot of High Quality Items sound effects for your game!
  • My game project is really pushing the limits of people on the screen - there's gonna be at least 400 pedestrians in a layout at once. So too little visual difference makes it hard to make a good feeling of a city.

    I made a small system called "P.R.E" to randomize headwear for each civilian and that made it a little more bearable to watch crowds of people. I toyed with color filters but didn't achieve anything but red lava people.

    Then I realized what Construct really would need: color replacing!

    You can already crop out colors in corners of a sprite, why not replace one color with another?

    I could put specific colored areas to my little townsmen and then randomize the color on their chest to create different colored shirts and pants for every single citizen in my game!

    So please, to make my game wonderfully crowded I need a Replace Color action to the Sprite object.

    P.S, here's how the citizens are doing now: naked, without clothes and only headwear on

    <img src="http://www.cubeupload.com/files/2ebe00thepeoplestormint.png">

  • Isn't there a shader that does that?

    You really should use a shader, otherwise you'd be using extra VRAM for every texture with different colours.

  • This has been requested a lot in the past, and I believe the consensus was that it'd be really complicated, and slow rendering down a lot because of something something VRAM something, I don't know.

    [quote:3prsuodl]I toyed with color filters but didn't achieve anything but red lava people.

    If all you are getting is shades of red then your expression might be wrong. To get a full gamut of red, green, and blue you need to use the rgb(r, g, b) expression in the color filter box. Just typing in something like "200, 150, 150" or "random(255), random(255), random(255)" won't work, it will only recognize the first value and apply it to the red channel only.

    Also, if you make your people have pure white skin with shades of gray and black outlines, then you can set up a skintone generator kind of like so:

    http://dl.dropbox.com/u/529356/skintones.cap

    Of course, the numbers could be tweaked and you could make people more saturated and orangey looking like in your screenshot. Or you could always make a set of twelve or so preset filters and randomly assign them to your sprites.

    Or, of course, track down that color changing shader like Ash said. It only changes one color per shader, I believe, but since you seem to have only one skin color in your sprites that shouldn't be a problem.

  • If I use this shader to achieve, say, different colored shirts and pants, can each of them be randomized independently?

    So each and every pedestrian would have a differently colored shirt, pants and a varied skin color. That combined to the headwear will make everyone look different.

    And Deadeye, I know about the color filter thing - the thing is, should I make a white shirt sprite separate from the citizen, then attach it to the citizen and THEN randomize its color.

  • And Deadeye, I know about the color filter thing - the thing is, should I make a white shirt sprite separate from the citizen, then attach it to the citizen and THEN randomize its color.

    Sure, if you want to take the time to set it up:

    http://dl.dropbox.com/u/529356/scarypeople.cap

    There's an awful lot of women with bald heads or comb-overs in that example, though . And people with green hair. Anyway, animation would be a bit trickier to do. Not hard, really, just time consuming.

    Those totally random colored clothes are kind of odd looking too, as you can see. Like I said you may just want a set of a dozen or so colors to pick from.

    As far as that shader goes, yeah if you have one color for skin, one color for shirt, and one color for pants, then you would have to use three shaders. Each could be randomized.

    The benefits to using filters are you won't get slowdown like you would with a shader. The drawback is of course the time it takes to set up.

    The benefit to the shader is it's a lot easier to use, and you don't have to split up your objects into different parts. But rendering time might become an issue.

    I can't for the life of me find that shader now though... I know it's here somewhere on the board. I can't even remember who made it. It's not linkman's hue shader, because that changes all the colors at once, not just one of them. Argh, I really wish people would put their finished plugins into the Completed Addons section

  • Does the shader take into account semi transparencies, or offer a color range?

  • I can't for the life of me find that shader now though... I know it's here somewhere on the board. I can't even remember who made it. It's not linkman's hue shader, because that changes all the colors at once, not just one of them. Argh, I really wish people would put their finished plugins into the Completed Addons section

    It is called (tadaa) "Color Replace", created by lucid, and can be found in this thread:

    http://www.scirra.com/forum/viewtopic.php?f=17&t=4234&hilit=color+replace&start=10

    Does the shader take into account semi transparencies, or offer a color range?

    No, and no.

  • It is called (tadaa) "Color Replace", created by lucid, and can be found in this thread:

    http://www.scirra.com/forum/viewtopic.php?f=17&t=4234&hilit=color+replace&start=10

    > Does the shader take into account semi transparencies, or offer a color range?

    >

    No, and no.

    I couldn't make it do the transparencies I believe cuz it had premultiplied alphas or something. Someone who knew more about shaders explained why it didn't work to me

    also, there is another one on that same page for color ranges

    scroll down the page a little bit

    there is one called range tinter

  • Just do the same thing you did with the hats, but with the people's skin color.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • does Range Tinter work with alpha?

    Just in case it doesn't, or if you want to retrofit Color Replace with alpha support

    Premultiplied alpha means color rgb(0.8,0.8,0. with an opacity of 50% gets stored as rgba(0.4, 0.4, 0.4, 0.5).

    To get the original color, just divide by the stored alpha!

    color = rgb(0.4, 0.4, 0.4) / 0.5 = rgb(0.8,0.8,0.

    then do your color replacing magickqs and then re-multiply by alpha.

    *All vector notation here is faux and does not work at all like that in shader code.

  • You can store 3 masks in the RGB channels of a sprite and tint these areas independently. This method allows for gradients and semi transparent tinting as well, but this is the most basic implementation so any untinted areas will be black (which works fine for your citizens Namelezz).

    <img src="http://i2.photobucket.com/albums/y8/soggyclog/tint_mask.jpg">

    I put together a basic shader and sample CAP file (edit:forgot to include the .FX file before, but should be there now)

    http://www.filedropper.com/colourtinting2

    Right now the shader takes independent RGB values for all three masks so thats 9 numbers. I don't know if there's a more elegant way to have just 3 colour pickers or something.

    This shader can also be made much more useful if instead of storing the transparency in the alpha channel you store a 4th mask, and then have a seperate sprite beneath the tinting sprite to provide the monochrome detail and blend with an overlay mode. The down side to that would be that you need two sprites per character. But yeay, for this kind of pixel art stuff that's not really necessary.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)