how to grey/black out the level map

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ArthurER

I am working on a top down 2d RTS project and am wondering how to go about making so the view of the play area is greyed/blacked out until a player unit travels across it. I imagine a patern of area 2d set to hide after player collision would work but don’t know how to implement that so it can generate itself

this is the part of the map script that I think I could use to generate that, it is part of the level script to set camera limits and centre camera start position on the map

func _ready():
	screen_size = get_viewport_rect().size
	var map_limits = map.get_used_rect()
	var map_cell_size = map.cell_size
	$Camera2D.position.x = (map_limits.end.x * map_cell_size.x) / 2
	$Camera2D.position.y = (map_limits.end.y * map_cell_size.y) / 2
	$Camera2D.limit_left = map_limits.position.x * map_cell_size.x
	$Camera2D.limit_right = map_limits.end.x * map_cell_size.x
	$Camera2D.limit_top = map_limits.position.y * map_cell_size.y
	$Camera2D.limit_bottom = map_limits.end.y * map_cell_size.y
:bust_in_silhouette: Reply From: miskotam

There are multiiple ways to solve this.

  • If you are working with tilemaps, you could have a cover layer that is grey/black, and as the player collides with a tile you remove the cover layer tile.
  • You can have a black ColorRect on your tiles and animate their transparecy.
  • You can use Light2D, Godot has a nice demo for that.

I suggest you to search for fog of war and you will find plenty of examples and tutorials. And find the best for your use case.

thanks I tried searching fog of war godot and think we have differing views on what a lot of tutorials is lol . I did it with area2d instanced from script in a grid pattern using for loops , the size of the map and the size of the sprite. it is not perfect , lags a couple seconds on startup but it works for now and I have an idea to get a better look with less startup lag

ArthurER | 2020-10-06 22:49