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

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

Similar Resources

Example app using labstack/echo and ozzo-validator.

Example app using labstack/echo and ozzo-validator.

Oct 17, 2022

Onboarding exercise to create todo list using golang and postgres

Todo List API Description A RESTful API that allows a user to create, update, view, filter, and delete todos API Documentation Copy the contents of th

Dec 1, 2021

Converts NFAs (and DFAs) to a regular expressions using the state removal method

nfa2regex: convert NFAs (and DFAs) to regular expressions An implementation of the state removal technique for converting an NFA to a regular expressi

Apr 29, 2022

Web app built with Go/Golang and Buffalo, deployed on Heroku, using Heroku Postgres

hundred-go-buffalo Background Read Go Read Buffalo Read Getting Started on Heroku with Go Recommended Tools PowerShell terminal Chocolatey Windows pac

Dec 18, 2021

Executor - Wrapper for exec.Command for simple using and multi commands executing

executor Examples package main import ( "fmt" "github.com/solar-jsoc/execut

Feb 12, 2022

[TOOL, CLI] - Filter and examine Go type structures, interfaces and their transitive dependencies and relationships. Export structural types as TypeScript value object or bare type representations.

typex Examine Go types and their transitive dependencies. Export results as TypeScript value objects (or types) declaration. Installation go get -u gi

Dec 6, 2022

Visualize call graph of a Go program using Graphviz

Visualize call graph of a Go program using Graphviz

go-callvis go-callvis is a development tool to help visualize call graph of a Go program using interactive view. Introduction The purpose of this tool

Dec 31, 2022

generate my_github status using GitHub Actions

generate my_github status using GitHub Actions

generate my_github status using GitHub Actions

Sep 21, 2022

Geth client which picks the most profitable blocks to mine using a greedy algorithm

Greeden-Geth Greeden-Geth is a protocol-agnostic client which uses a greedy algorithm to pick the most profitable blocks to submit to the network out

Nov 16, 2022
Comments
  • Question about day_duration

    Question about day_duration

    day_duration is initially set to minutes:

    https://github.com/hiulit/Godot-3-2D-Day-Night-Cycle/blob/bfa41a7978b4ea489b54a0f92c33ef365c1bd76a/DayNightCycle.gd#L3

    then it's converted to seconds:

    https://github.com/hiulit/Godot-3-2D-Day-Night-Cycle/blob/bfa41a7978b4ea489b54a0f92c33ef365c1bd76a/DayNightCycle.gd#L34

    but there are only 60 seconds in a minute, so why does it multiply the result by 60 again?

    I ask because I'm currently looking into an issue with my game and to fix it I need to understand this code.

  • Use exclusive comparison operator for end of cycle

    Use exclusive comparison operator for end of cycle

    This change set fixes up the comparison logic a bit.

    As an example: if you start the game at dawn, it will correctly color the canvas for dawn, rather than coloring it for night.

    Thanks!

  • Refactor DayNightCycle

    Refactor DayNightCycle

    • Move the time-specific code into a Time singleton
    • Add a debug overlay that shows the current time, date and period, well as a slider to change the time.

    Kapture 2019-09-03 at 19 25 24

  • seconds_elapsed_remainder disregarded

    seconds_elapsed_remainder disregarded

    Hey there - was playing with your project and noticed that in the main timer you overwrite seconds_elapsed_remainder each time _physics_process gets called, so fractions of a second are potentially getting lost every cycle. Change to "seconds_elapsed_remainder += delta * IN_GAME_SECONDS_PER_REAL_TIME_SECONDS" fixes this.

Day-1 is apart of my 6 days of Christmas challenge where i write in two new languages everyday, and make something weird out of it.

Day-1 is apart of my 6 days of Christmas challenge where i write in two new languages everyday, and make something weird out of it. today was a HTTP server written with PostGreSQL using Golang, R, and shell script read more

Dec 21, 2021
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar

Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star.

Dec 6, 2021
If you accept that 1 day is 24 hours in some situations, you might want to parse it in Go too.

relaxduration If you accept that 1 day is 24 hours in some situations, you might want to parse it in Go too. This package tries to handle situations w

Dec 7, 2022
Purpose: dump slack messages, users and files using browser token and cookie.

Slack Dumper Purpose: dump slack messages, users and files using browser token and cookie. Typical usecase scenarios: You want to archive your private

Jan 2, 2023
A distributed unique ID generator of using Sonyflake and encoded by Base58

Indigo About A distributed unique ID generator of using Sonyflake and encoded by Base58. ID max length is 11 characters by unsigned int64 max value. A

Nov 24, 2022
An example event-driven application using Atmo and NATS

Atmo + NATS Example Project This repo is an example of using Atmo with NATS as a streaming messaging layer. In this example, Atmo connects to NATS and

Oct 27, 2021
A BPMN engine, meant to be embedded in Go applications with minim hurdles, and a pleasant developer experience using it.

A BPMN engine, meant to be embedded in Go applications with minim hurdles, and a pleasant developer experience using it. This approach can increase transparency for non-developers.

Dec 29, 2022
skiptable is a jump table that mimics redis' zset using go, and implements most of the features of redis zset

skiptable is a jump table that mimics redis' zset using go, and implements most of the features of redis zset

Oct 25, 2021
It is a basic todo app which has CRUD operation using Buffalo and golang

It is a basic todo app which has CRUD operation using Buffalo and golang

Nov 1, 2021
A ready to use Pastebin written in Go Lang, fork the files and start editing/using it.

A ready to use Pastebin written in Go Lang, fork the files and start editing/using it.

Dec 31, 2021