I need a CanvasModulate to obscure all nodes on screen except for a number of nodes stored on an array. I tried using CanvasLayer but it didn't work out.
Is it possible for a CanvasModulate to discriminate certain nodes through code?
Wouldn't it be easier to simply discriminate based on z-index or scenetree order? Also, how did you try CanvasLayer, perhaps you tried something wrong?
Megalomaniak This is my setup:
- The "Player" and a number of "Enemy" nodes are on the same layer, drawn over a "floor" and under a "ceiling" tilesets.
- When the player enters in contact with an enemy, it and all nearby enemies are added to an array.
- Then, I intend the CanvasLayer to become visible over the map and all actors that are not included on the array.
This is what I tried: - When I put the actors on a separate CanvasLayer, then they all are drawn over the Modulate, regardless of if they're on the array or not.
- I tried to put the sprite of each actor on their respective CanvasLayer to change the layers individually, but for some reason they refuse to render and just become invisible.
- Then, I tried to have a separate CanvasLayer and just "move" the nodes to it upon activation using this code:
func translate_node_to(node: Node, target: Node):
node.get_parent().remove_child(node)
target.add_child(node)
but for some reason this crashes the game (The debugger just forcibly closes without giving me any error).
Admittedly, this is my first time dealing with canvas stuff, and I'm getting frustrated too quickly. In any case, thanks for replying.
- Edited
CanvasLayers are meant more for Control Nodes, the UI stuff. So I think your best bet is likely to look into using z-index and perhaps even experiment with the Y-sort node. Study the SceneTree and how node order in the tree affects the draw order. I think understanding this is key to success here.
edit: To be clear, I'm not saying that CanvasLayers won't work with Node2Ds but that it can be less predictable perhaps. It would commonly be used for HUDs, so GUI but also for backgrounds. What you are trying to do might have similarities to a background, but perhaps a bit too dynamic and complex in comparison so I'm still inclined to say that perhaps Y-Sort nodes and/or manually modifying nodes z-index(thus draw order) might be a better solution here.
Megalomaniak Thanks, I'll try it
Ivann Ah I just edited the above comment and didn't yet see your reply. Chances are you might have missed the edit.