[F8] Palette swapping sprite graphics
I am developing an engine for my game and a large majority of the way things are drawn to the screen is directly dependent upon the ability to set the fill color of parts of the sprite programmatically.
I've posted about it before, but I'll reiterate for clarity. If a character has brown hair, the shade of brown is the midtone, which is determined mathematically. An overlay of black set to approximately 33% opacity gives the shadows and another overlay of white with the same opacity gives the highlights.
The reason I want to split things up into layers like this is so I can make the character editor highly flexible while relying on the smallest quantity of reusable graphic elements as possible. In other words, I don't want to have characters with a million sprite resources or only two supplied colors to choose from.
I have already developed and nearly finalized a class that allows the user to select virtually any color using a hue, saturation, value hexagonal color swatch, so the range of colors and how to acquire them isn't an issue.
The trick is at render time. I'm already certain that I could apply the adjustments once, then use them for the lifespan of the sprite. What I want to do is use simulated lightmaps and compositing to place my characters into the scenery.
How would I go about doing this? Imagine a simple example of a character standing beneath a tree in a sunny field. If I wanted to simulate patches of light poking through the canopy and falling on my character who is otherwise in shadow, how would I achieve this? The graphic resources of the sprite would have to remain untainted somehow and simply merged with other layers to create this end result, but would that dictate the necessity of using multiple synchronous focusRects on every layer of the final render, then blending them all per frame to get the expected result?
If so, what's the cap on layers I can merge before it starts to choke?
Keep in mind, I'm probably only going to be using bitwise operations, maybe threshold (if that) when it comes to filters.
I'll find out once I start getting into things. For now, I don't want to get geared up in the wrong direction, then have to rewrite most of my engine because I didn't prepare first.
Not 100% sure I understand correctly, but..
You're looking for a system to set the hue/tint affects on a sprite dynamically during runtime?
Quote:
Color.prototype.setTint = function (r, g, b, amount) {
var percent = 100 - amount;
var trans = new Object();
trans.ra = trans.ga = trans.ba = percent;
var ratio = amount / 100;
trans.rb = r * ratio;
trans.gb = g * ratio;
trans.bb = b * ratio;
this.setTransform(trans);
}//Robert Penner June 2001 -
www.robertpenner.com
So then set it to whatever mc you like;
Quote:
newColor = new Color(your_mc);
newColor.setTint(255, 255, 255, 100);
Quote:
newColor.setTint(0, 0, 0, 0);
deletes it. (or was it delete newColor ..i forgot)
First 3 parameters represent the hue RGB values, and the final one is the opacity.
What you would do is you would create a base greyscale bitmap for your hair that contains a dark area for the shadows, lighter in the midtones and almost white in the highlights. Then, once someone selects the colour they want from the colour palette menu,you get the RGB, enter the values in setTint and set the opacity at about 60.
Then when your kiddie goes under the sunray you just reapply the setTint with the same values but a different opacity. Worked very well for the shadows and lightning effects in my zombie game.
Should work if I even understood your enquiry correctly.