Before I start this article, I may as well answer the question some of you probably have right now: What is palette swapping?
You've probably seen palette swapping before. Ever played any of the oldMortal Kombats? Noticed how all the ninjas look the same, except for the colors? Well, there's your explanation. Palette swapping is basically switching one color of an object to a different color, i.e. switching red with blue.
II. How to do Palette Swapping in MMF
Step 1: Create an active object (now known as Active1)
Step 2: Go to the event editor. Make up an event. Right click on the box below Active1, go to the Animation submenu and select "Replace Color".
Step 3: Right now you're looking at a table of colors. This table represents the color you want to be replaced. So, if you're objects red, and you want it to be blue, you would click on the red box.
Step 4: Another table of colors pops up. This table represents the color you want to take the previous color's place. If we were using the current example, we would choose blue, because we want the object to be blue and not red.
Step 5: TADA! You're done with your first palette swap in MMF.
However, this is rather weak. If we continue swapping colors this way, we would need dozens of lines of code for multiple colors. Luckily, there's an easier way to make it change to any color you want to in MMF. I will show you how below.
Step 1: Repeat Steps #1 and #2 in the previous example.
Step 2: Right now you're seeing the table of colors. Click on the "Calculate" button.
Step 3: You're in the expression editor. Click on the "Retrieve data from an object" button, right click on Active1, and then select "Get RGB at..."
Step 4: You're given something like
RGBAt( "Active", > Enter value here <, > Enter value here < )
. The two values are the co-ordinates in Active1. The RGBAt() function will get the color that is on that co-ordinate (so if (1,1) is red, it will get red). The first value is the x-coordinate, and the second value is the y-coordinate. Plug those numbers in.
NOTE: 0,0 is the top left corner.
Step 5: Pick the color you want to replace it with, or you can do another RGBAt() function. Viola! You're finished!
WARNING: Using RGBAt() on an object with the same color in two different places will result in both places having a color change. The same thing will happen with using the regular tables. You must split up your actives to have shirt/sleeves/pants/etc. to have independent colors.
III. What can I use this for?
There are many possibilities in which you can use palette swapping. Probably the most obvious and the best possibility is alternate costums. Alternate costumes give the feel that effort was put into the game, and you can make them by simply swapping colors. With this technique, you don't need to worry about Groups. Plus, it saves space, since it doesn't need to store all those pictures in the .exe!
This technique can also be used in:
(a cool effects without taking a lot of space
(b day to night transitions
(c anything to do with colors
Well, that ends this article. I hope you've learned something.
Good article!
About "Get RGB at".. usually the active objects has different frames.. if I give the coordinate, in example, [0,0], from which animation frame MMF will pick the colour? From the first frame? From the current frame? Thank you..
problem is, each instance of an active gets its color replaced, so if you have like multiple usesrs in an mmorpg, you cant change one of the dudes shirt..
good enough but can it be used for changing, say something with hundreds of shades of a colour? ive always been *slightly* confused with Replace Colour
I played around with this once, but abandoned it when I sadly discovered it replaces all instances, as thewreck said. This means you can't have lots of the same object all with diff. colours
That's why you split up the object. A lot of times, this can actually improve the game, because you can do more with the separate objects than with only one (i.e. better collision detectoin).
another way to replace a bunch of color is to make a loop which scan all the pixel of the object using RGBAt() and store the color used in a array , then your olny have to generate the other part of the array and then you olny have to scan your array for swapping the palette (and your code can prevent bugs if you wish to reswap the palette to its origial form)