Team colors - how are they done?
Moderator: Forum Moderators
Team colors - how are they done?
Hey all, I am developing a Wesnoth-ish game for Android at the moment in Java (as a for-fun project/to get better at coding). Although I'm reasonably far along, I had a couple of questions on how Battle for Wesnoth performs certain operations:
How are team colors calculated and applied from unit .png files? Right now, I see that all Wesnoth units have pink regions corresponding to the area where team colors will go. How are those pink regions detected and recolored? If you're not entirely sure, would it be possible to point me to the relevant section of the source code?
Note: I'm not interested in copying Wesnoth assets or code, I simply want to understand how things work so I can implement a similar system in my own game engine.
Thanks!
How are team colors calculated and applied from unit .png files? Right now, I see that all Wesnoth units have pink regions corresponding to the area where team colors will go. How are those pink regions detected and recolored? If you're not entirely sure, would it be possible to point me to the relevant section of the source code?
Note: I'm not interested in copying Wesnoth assets or code, I simply want to understand how things work so I can implement a similar system in my own game engine.
Thanks!
Re: Team colors - how are they done?
The WML API for this is pretty simple. Unit definitions include a name reference to the team color palette to use as the TC source. (For mainline units, this is always thekazi wrote:How are team colors calculated and applied from unit .png files? Right now, I see that all Wesnoth units have pink regions corresponding to the area where team colors will go. How are those pink regions detected and recolored? If you're not entirely sure, would it be possible to point me to the relevant section of the source code?
magenta
palette; flags use the flag_green
palette instead.) The game assigns a team color range to each side in a scenario.The mainline color ranges and color palettes are defined in
data/core/team-colors.cfg
. Palettes are pretty simple comma-separated lists of (exact) colors in hex RRGGBB notation, and color ranges are quartets of color values in the same format but with a more specific meaning, described near the start of the file:Code: Select all
# Each Team-color definition is made up of 4 hexadecimal colors,
# one byte each of red-green-blue information
# 1) the average shade of a unit's team-color portions
# 2) the maximum highlight shade of a unit's team-color portions
# 3) the minimum shadow shade of a unit's team-color portions
# 4) the color of the markers on the mini-map.
1
, which is equivalent to red
and used for side 1) on the source palette using the recolor_range()
function (warning: maths inside); then takes the target image and performs a pixel-by-pixel substitution using the color mappings returned by the function.Hope this helps!
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
Re: Team colors - how are they done?
Excellent, that's exactly what I was looking for. I'll give things a try and see what happens. (Implementation may be a bit tough, but at least it gives me a concept to start with)
Thanks for your help!
Thanks for your help!