Set layer modulate

Godot Version

4.2.1

Question

in this game, we are trying to make some walls transparent when the player goes behind them, but the problem is: when the game starts, all of those walls and obsticals are already transparent and the player has to go behind them and come out to make them normal again.



Screenshot 2024-02-25 131206
Screenshot 2024-02-25 131231
Screenshot 2024-02-25 131254

and here is the code for making the layers transparent and untransparent:
extends TileMap
@export var invisible_color: Color = Color(1.0, 1.0, 1.0, 0.22)
@export var visible_color: Color = Color(1.0, 1.0, 1.0, 1.0)

func _untrans1(c, d):
set_layer_modulate(c, d)
func _trans1(a, b):
set_layer_modulate(a, b)

func _on_area_2d_body_exited(body):
_untrans1(1, visible_color)
func _on_area_2d_body_entered(body):
_trans1(1, invisible_color)

func _on_area_2d_2_body_exited(body):
_untrans1(8, visible_color)
func _on_area_2d_2_body_entered(body):
_trans1(8, invisible_color)

func _on_archive_body_exited(body):
_untrans1(13, visible_color)
func _on_archive_body_entered(body):
_trans1(13, invisible_color)

It’s because you don’t check which body enter. Your tile map enter the area 2d right at the start of your scene and you need to enter the area and exit with your player to make it visible again.
check if the body is your player before modulate the layer.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.