Godot 3 2D Day/Night Cycle
by hiulit
Godot 3 2D Day/Night Cycle
A 2D ☀️ Day / 🌔 Night cycle using CanvasModulate and a moon light effect using Light2D.

Examples

Cycle without the moon light.

Cycle with the moon light static.

Cycle with the moon light moving.
🕹️ Demo
- Clone the repository or download it in a ZIP file.
- Open
day_night_cycle/project.godot. - Play around 🙂.
📑 Documentation
🛠️ Setup
- Clone the repository or download it in a ZIP file.
- Copy the following files and folders to your project:
time.gdfile (day_night_cycle/src/singletons/time.gd).day_night_cyclefolder (day_night_cycle/src/day_night_cycle).moon_lightfolder (day_night_cycle/src/moon_light).debug_overlayfolder (day_night_cycle/src/debug_overlay).
🚀 Usage
- Prerequisites
- Add a simple cycle
- Add a cycle with a moon light
- Add a delay between cycles
- Add a debug overlay
Prerequisites
Add the Time singleton:
- Go to
Project->Project Settings. - Go to the
AutoLoadtab. - Add the
time.gdfile. - Enable it.

Change the Time parameters to your liking.
Add a simple cycle
Instance the DayNightCycle node in the root scene.
Node
├── TileMap
├── Player
├── OtherStuff
└── DayNightCycle
Change the DayNightCycle parameters to your liking.
Add a cycle with a moon light
Instance the DayNightCycle node and the MoonLight node in the root scene.
Node
├── TileMap
├── Player
├── OtherStuff
├── DayNightCycle
└── MoonLight
Sync the MoonLight with the DayNightCycle.
The MoonLight can be static or moving in sync with a DayNightCycle.
Change the DayNightCycle parameters and the MoonLight parameters to your liking.
Add a delay between cycles
- Create a
CanvasLayerfor the background and set itslayerto-1. - Instance the
DayNightCyclenode in the backgroundCanvasLayerpreviously created. - Instance another
DayNightCyclenode in the root scene and add a delay. - Instance the
MoonLightin the root scene and sync it to theDayNightCyclenode with a delay.
Something like this:
Node
├── CanvasLayer (layer = -1)
│ └── BackgroundSprite
│ └── DayNightCycleBackground (delay = 0)
├── TileMap
├── Player
├── OtherStuff
└── DayNightCycleForeground (delay = 1800)
└── MoonLight (cycle_sync_node_path = DayNightCycleForeground)
This will create the effect that the background starts changing before the foreground.
Add a debug overlay
Test the passing of time, the cycles and the moon light.

- Create a
CanvasLayerand set itslayerto1. - Instance the
DebugOverlaynode.
Something like this:
Node
├── TileMap
├── Player
├── OtherStuff
├── DayNightCycle
├── MoonLight
└── CanvasLayer (layer = 1)
└── DebugOverlay
🗒️ Changelog
See CHANGELOG.
👤 Author
- hiulit
🤝 Contributing
Feel free to:
- Open an issue if you find a bug.
- Create a pull request if you have a new cool feature to add to the project.
🙌 Supporting this project
If you find this project helpful, please consider supporting it through any size donations to help make it better.
If you can't, consider sharing it with the world...
... or giving it a star.
👏 Credits
Thanks to:
- Solo CodeNet - For the YouTube video tutorial that inspired this project.
- Terkwood - For helping with an issue about comparison operators in the cycle state.
- Mitch Curtis - For an amazing PR (#4) that helped improve the project big time.
- Luis Zuno - For creating the Sunny Land assets.
- Twemoji - For the emojis.
- Andrea Calabró - For creating the Godot logo.
📝 Licenses
- Source code: MIT License.
- Documentation (GDScriptify): MIT License.
- Emojis: CC BY 4.0
- Godot logo: CC BY 3.0.
- Sunny Land assets: Public domain.
Download
Support
If you need help or have questions about this plugin, please contact the author.
Contact Author