3
\$\begingroup\$

I want to generate a competitive game like Age of Empires where each player has access to a variety of units, and each player can be distinguished by a color in each unit

In Age of Empires, the unit colors change to match the player.

And instead of sprites create 8 different colors, would have only one, with a mark where that color is changed, for example:

A car model, where I can change the color of the middle stripe.

How do I change color of one part of sprite in Game Maker?

\$\endgroup\$
0
1
\$\begingroup\$

There are two common ways.

  1. Without a shader. Split a sprite to the two parts. First of them will contain elements which must be drawed "as is", without changes (won't be colorized). And second part will contain elements which must be colorized (the elements must be white/grayscale).

In your example first part will contain green and black elements and second part will contain fuchsia element (but it must be white) Drawing will be like this:

var color = c_fuchsia;
draw_sprite_ext(sprite_index, 0, x, y, image_xscale, image_yscale, image_angle, c_white, 1);
draw_sprite_ext(sprite_index, 1, x, y, image_xscale, image_yscale, image_angle, color, 1);
  1. Using simple shader.

Pass new color to your shader. Shader must check the color of the drawing pixel and change it to new color, if need. If you have no experience with shaders, then see Demos -> Advanced -> Simple Shader Examples (Shader Demo 5, Simple Colour Swapping) in GMS. But instead comparsion like this:

if ((col.r == 1.0) && (col.g == 0.0) && (col.b == 1.0))

use something like this:

if ((col.r > 0.99) && (col.g < 0.01) && (col.b > 0.99))

Shaders provide many ways and abilities (just one color, skins, palettes, etc).

P.S. Also you may use one of shaders from Marketplace: Retro Palette Swapper, Palette Based Drawing (but both are paid)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.