A 2D βοΈ Day / π Night cycle using CanvasModulate and a moon light effect using Light2D.
Cycle without the moon light.
Cycle with the moon light static.
Cycle with the moon light moving.
- Clone the repository or download it in a ZIP file.
- Open
day_night_cycle/project.godot. - Play around π.
- 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).
- Prerequisites
- Add a simple cycle
- Add a cycle with a moon light
- Add a delay between cycles
- Add a debug overlay
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.
Instance the DayNightCycle node in the root scene.
Node
βββ TileMap
βββ Player
βββ OtherStuff
βββ DayNightCycle
Change the DayNightCycle parameters to your liking.
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.
- 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.
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
See CHANGELOG.
- hiulit
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.
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.
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.
- Source code: MIT License.
- Documentation (GDScriptify): MIT License.
- Emojis: CC BY 4.0
- Godot logo: CC BY 3.0.
- Sunny Land assets: Public domain.





