Godot 3 2D Day/Night Cycle

A simple 2D ā˜€ļø Day / šŸŒ‘ Night cycle using CanvasModulate.

Godot 3 2D Day/Night Cycle GIF

Now with a šŸŒ• Moon effect using Light2D!

Without a Moon

Godot 3 2D Day/Night Cycle GIF

With a Moon

Godot 3 2D Day/Night Cycle GIF

With a moving Moon

Godot 3 2D Day/Night Cycle GIF

Installation

  • Download the repository ZIP file.
  • Copy DayNightCycle.tscn and DayNightCycle.gd in your project.
  • Copy Moon.tscn, Moon.gd and light.png in your project.

Usage

DayNightCycle

  • Instance DayNightCycle.tscn and attach DayNightCycle.gd as a script.

You can change all these variables right from the Inspector.

Inspector

Tips

Instance one DayNightCycle.tscn in your background scene and another DayNightCycle.tscn in your main scene or level scene, etc. and set the Day start hour in the background scene a little after than the Day start hour in the main scene to have the effect that the background starts changing before the foreground.

Main
ā”œā”€ā”€ Background
ā”‚   ā””ā”€ā”€ DayNightCycle
ā”œā”€ā”€ Player
ā”œā”€ā”€ OtherStuff
ā””ā”€ā”€ DayNightCycle

Example

  • Background scene - Day start hour: 10.2
  • Main scene - Day start hour: 10

Moon

Warning!

Before using the Moon you should know that it is intrinsically connected with DayNightCycle. This is where singletons come in handy.

This project has a Global.gd that serves as a singleton. Its function is to have DayNight and Moon variables available always and from everywhere.

You can copy those variables and add them to your own singleton. In that case, you'll have to change all the Global.xxx variables accordingly.

  • Instance Moon.tscn and attach Moon.gd as a script.
  • In DayNightCycle.gd, uncomment the commented following line:
func _ready():
    # Global.DayNight = self

You can change all these variables right from the Inspector.

Inspector

Documentation

DayNightCycle

Day Duration

Name Type Description
day_duration float The duration of the day in minutes.

Day Start Hour

Name Type Description
day_start_hour float The starting hour of the day. 24 hours time (0-23).

Day Start Number

Name Type Description
day_start_number float The starting day number.

Color (DAWN)

Name Type Description
color_dawn Color The color of the DAWN state in RGBA.

Color (DAY)

Name Type Description
color_day Color The color of the DAY state in RGBA.

Color (DUSK)

Name Type Description
color_dusk Color The color of the DUSK state in RGBA.

Color (NIGHT)

Name Type Description
color_night Color The color of the NIGHT state in RGBA.

State (DAWN) Start Hour

Name Type Description
state_dawn_start_hour float The starting hour of the DAWN cycle state. 24 hours time (0-23).

State (DAY) Start Hour

Name Type Description
state_day_start_hour float The starting hour of the DAY cycle state. 24 hours time (0-23).

State (DUSK) Start Hour

Name Type Description
state_dusk_start_hour float The starting hour of the DUSK cycle state. 24 hours time (0-23).

State (NIGHT) Start Hour

Name Type Description
state_night_start_hour float The starting hour of the NIGHT cycle state. 24 hours time (0-23).

State Transition Duration

Name Type Description
state_transition_duration float The duration of the transition between cycle states in hours.

Debug mode

Name Type Description
debug_mode bool Enables/disables debug mode. It prints current_day_number, current_day_hour and cycle_state

On

Name Type Description
move bool Enables/disables the node.

Moon

State (DAWN) Energy

Name Type Description
state_dawn_energy float The energy value of the DAWN state. The larger the value, the stronger the light.

State (DAY) Energy

Name Type Description
state_day_energy float The energy value of the DAY state. The larger the value, the stronger the light.

State (DUSK) Energy

Name Type Description
state_dusk_energy float The energy value of the DUSK state. The larger the value, the stronger the light.

State (NIGHT) Energy

Name Type Description
state_night_energy float The energy value of the NIGHT state. The larger the value, the stronger the light.

State Transition Duration

Name Type Description
state_transition_duration float The duration of the transition between cycle states in hours.

Move

Name Type Description
move bool Enables/disables the Moon movement.

On

Name Type Description
move bool Enables/disables the node.

Authors

Me šŸ˜› @hiulit.

Credits

Thanks to:

License

MIT License.

Godot 3 2d Day Night Cycle

A simple 2D Day/Night cycle using CanvasModulate and a Moon light effect using Light2D

Godot 3 2d Day Night Cycle Info

ā­ Stars 61
šŸ”— Source Code github.com
šŸ•’ Last Update a year ago
šŸ•’ Created 3 years ago
šŸž Open Issues 2
āž— Star-Issue Ratio 31
šŸ˜Ž Author hiulit