[SOLVED] - Fog of war - turn based game

I know that is a wide question.
I would like to create a turn based strategy game and I need to create fog of war.

Is someone knows how to do that in gdevelop ?


Use fog tiles and reduce their opacity when units get close. :slight_smile:

Hi, thanks but it is not heavy ?
I mean it will have a lot of checks.

When unit move we need to increase the black tiles opacity around the unit.
It will be very costly to check collisions when collide (reduce opacity or opacity to 0) AND when not collide (opacity to 255) isn’it ?


You only need a distance check.

Ok. How did you that in gdevelop ? Pseudo code please :slight_smile:

If unit is moving
→ if distance of fog to unit < unit.variable (vision)
→ -> change opacity of fog set to 55/0
→ if distance of fog to unit >=unit.variable(vision)
->-> change opacity of fog set to 255

Thank you but I do not find a distance function in GD. Sorry, I come from Unity world. I would do that with raycast or check distance function in update.
Is there a distance function in GD ?


Hmmm I read again your code and I have a question.
“If distance of fog to unit”
How do you get the fog object (sprite) ?
In clear, I understand in pseudo code but in real code how do you that ?


Ok find the object.distance(object) function. :wink:

I found another way to do that.
Create a black background.
At the begining of the scene reduce every tile sprite opacity to transparent.
Increase opacity to max for every tile in unit field of vision (check with distance method for example).
It will avoid to use black tiles and save some memories.
What do you think about this way ?


I have tested and it works.
You need to loop tiles with foreach.