Skip to content

A 2D β˜€οΈ Day / πŸŒ” Night cycle using CanvasModulate and a moon light effect using Light2D.

License

Notifications You must be signed in to change notification settings

hiulit/Godot-3-2D-Day-Night-Cycle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Godot 3 2D Day/Night Cycle

Godot v3.x GitHub release (latest by date) GitHub license

A 2D β˜€οΈ Day / πŸŒ” Night cycle using CanvasModulate and a moon light effect using Light2D.

Godot 3 2D Day/Night Cycle Banner

Examples

Cycle without the moon light

Cycle without the moon light.

Cycle with the moon light static

Cycle with the moon light static.

Cycle with the moon light moving

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.gd file (day_night_cycle/src/singletons/time.gd).
    • day_night_cycle folder (day_night_cycle/src/day_night_cycle).
    • moon_light folder (day_night_cycle/src/moon_light).
    • debug_overlay folder (day_night_cycle/src/debug_overlay).

πŸš€ Usage

Prerequisites

Add the Time singleton:

  • Go to Project -> Project Settings.
  • Go to the AutoLoad tab.
  • Add the time.gd file.
  • Enable it.

Enable the time.gd singleton

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 CanvasLayer for the background and set its layer to -1.
  • Instance the DayNightCycle node in the background CanvasLayer previously created.
  • Instance another DayNightCycle node in the root scene and add a delay.
  • Instance the MoonLight in the root scene and sync it to the DayNightCycle node 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.

Debugg overlay example

  • Create a CanvasLayer and set its layer to 1.
  • Instance the DebugOverlay node.

Something like this:

Node
β”œβ”€β”€ TileMap
β”œβ”€β”€ Player
β”œβ”€β”€ OtherStuff
β”œβ”€β”€ DayNightCycle
β”œβ”€β”€ MoonLight
└── CanvasLayer (layer = 1)
    └── DebugOverlay

πŸ—’οΈ Changelog

See CHANGELOG.

πŸ‘€ Author

  • hiulit

🀝 Contributing

Feel free to:

πŸ™Œ Supporting this project

If you find this project helpful, please consider supporting it through any size donations to help make it better.

Become a patron

Suppor me on Ko-Fi

Buy me a coffee

Donate Paypal

If you can't, consider sharing it with the world...

... or giving it a star.

πŸ‘ Credits

Thanks to:

πŸ“ Licenses