re-colour at render time

Started by
4 comments, last by jbadams 20 years, 4 months ago
I''m currently working on a fairly simple 2d games project (clone of an old game called Medieval Warriors), in which there is multiplay. Each player has a certain number of warriors, which can be one of 4 different types. We have a sprite for each type, and its quite easy to display these. I''m using DirectX8. What I''m wondering, is the best way of re-colouring parts of the sprites for each player. ie. in strategy games, you might be the red team, so part of each of your units turns red to reflect this. The sprites actually have 2 different recolourable sections, which can be re-coloured to 2 colours chosen by the players from a list of 8 or so colour choices when they set up thier team. At the moment I''m doing this by rendering the sprite, then rendering another graphic over the top of it which is the desired colour, but which is completely transparent except for the bit I wish to change. This works fine, but means that every time I place a single character on the screen I have to render 3 different graphics (plus another because you can also change the weapons they have, but that isnt relevant to my question). When rendering my sprites, I set aside a certain colour key, and it is made transparent, so I dont have blocks around the sprites. I''m wondering if theres a way of setting aside 2 more colour keys, and using them in a similar way to render with the players selected colours, and if this IS possible, is it actually better than my current method? Could someone provide me some info, or links to tutorials or whatnot about this? Thanks in advance.

- Jason Astle-Adams

Advertisement
Unless you are using several thousands of warriors storing a seperate warrior sprite for each color seems to be the best way.

or else

If you are using a 256 color mode you can always play with the palette.
Wouldn''t it be faster to have 8 (or however many different colors) sets of textures? That seems faster than the way you are currently doing it.
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
Thanks for the replies guys. Could you please explain what you mean in a bit more detail RhoneRanger? (or someone else)

- Jason Astle-Adams

He probably means this.

Blue = warriorblue.bmp
Green = warriorgreen.bmp

meaning you have a different texture for every different color.

If you allow the player to choose the color from a palette of maybe more than 20, then you will need to have a base sprite with the parts you want for color in a unique color.

Then when loading the game, you could generate the sprite based on what color the player chose and modify the unique color from the base sprite and use that instead.
quote:If you allow the player to choose the color from a palette of maybe more than 20, then you will need to have a base sprite with the parts you want for color in a unique color.

Then when loading the game, you could generate the sprite based on what color the player chose and modify the unique color from the base sprite and use that instead.


Yes - thats what I was thinking about - but I dont know how to do so. I assume it would be similar to how I use a certain colour for transparency, but I dont know how to replace a colour instead of doing transparency. Can someone point me in the direction of an appropriate tutorial?


[edited by - kazgoroth on December 13, 2003 11:10:39 PM]

- Jason Astle-Adams

This topic is closed to new replies.

Advertisement