It seems like there's nothing in the TileMap node to alter the colors of a particular cell (not tile). But I wonder if this could be achieved somehow, with shaders or something else?
This is specifically for a classic roguelike kind of game. So basically what I need is to have a 64x40 grid of characters (which I do already), but I need a way to change each of their colors during runtime. [EDIT: To be clear, I need control over the color of the text (foreground color), and over the color around the text (background color), separately.]
(A shader on a tile doesn't work, as that changes the color for all the instances of that same tile that are on the screen.)
(This is crossposted this from the Godot forums.)
EDIT2: I'm still interested in the using TileMaps, but in the meanwhile I figured out how to achieve what I want through shading loose sprites (no TileMap node). So basically I covered the screen with sprites, each of them with this shader:
uniform color fg; // foreground color
uniform color bg; // background color
if (COLOR.rgb == vec3(0.0, 0.0, 0.0)){ // I don't think I'll need alpha
COLOR.rgb = bg.rgb;
} else {
COLOR.rgb = fg.rgb;
}
Two things to keep in mind about this, as far as I've tested it:
- Each sprite is a preloaded Cell.tscn (Sprite as root, nothing else in it), as
the loading time seems way faster by instancing preloaded scenes than
to create Sprite objects on the fly.
- I have to create a CanvasItemMaterial for each sprite as I load them, so
that they each gets a unique material (to which I assign that shader above,
which is saved on a file).
That seems to work fine. The main "problem" is that while it performs rather well (at least without any game logic on top of it), the TileMap still performs ~4x better, and adding more TileMaps doesn't seem to make a significant difference in performance, while this way it does.
So I'm still very interested in doing it with TileMaps instead, if possible.