0 votes

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
in Engine by (83 points)

1 Answer

0 votes

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.

by (148 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.