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

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