Hi, I'm trying to do the following . Sorry for the long post!
I want to be able to construct lots of NPCs with variations without having to draw every single frame, shade and animate them by hand.
Not sure if I'm taking the right approach here :
Construct an ImageTexture or Texture based on low res (currently between 16 and 32 pixels) pngs (base color, 3 tone value map) and palette Resources . I load the images in variables, create a new Image and fill it with the data of the base Image, and then iterate over the base Image and value map Image.
I then use get_pixel() to get the color data per pixel, check the alpha to only process the non-zero ones and then use get_pixel() to get the value and adjust the color based on the value map. Works fine, since I only check for the highlight color (white), or the shadow color (black).
There's a step between those and that's where the problem occurs : After checking the alpha of the base color I use match to see if it matches the color of the palette Resource I made. I have a default one and an alternative one for now. I color picked the colors of the sprite since one of the default ones was off I found :
# abstract resource
extends Resource
class_name PlayerColors
export(String) var scheme_name = "default"
export(Color) var hair_color = Color(70/255.0, 34/255.0, 74/255.0, 1.0)
export(Color) var skin_color = Color(202/255.0, 137/255.0, 101/255.0, 1.0)
export(Color) var mouth_color = Color(176/255.0, 48/255.0, 18/255.0, 1.0)
export(Color) var shirt_color = Color(51/255.0, 153/255.0, 113/255.0, 1.0)
export(Color) var pants_color = Color(80/255.0, 100/255.0, 201/255.0, 1.0)
export(Color) var sword_color = Color(88/255.0, 88/255.0, 103/255.0, 1.0)
I just named them based on the sprite for now. Turns out they never match. I print the values of the pixel data I got using get_pixel() and the one I get from colors_default which I created from the abstract resource above and then color picked off the base image in Godot. I print them to a txt file since 22x22 results in too much for the debugger to handle. They look identical to me:
pants_color : 0.313726,0.392157,0.788235,1 <- picked off the png by loading the Resource in the Inspector
base_px : 0.313726,0.392157,0.788235,1 <- from Image.get_pixel()
But according to Godot they don't match.
I have a working workaround: not use the color of the resource and just sample base colors. But I want to use the resources. I did find out using that workaround that Color(80/255.0, 100/255.0, 201/255.0, 1.0) and Color(80/255, 100/255, 201/255, 1) is not considere the same.
Is there a difference between how get_pixel() gets color data and how the color picked of the Inspector gets color data ? Is there a better workaround where I make them have the same format?