Coder Social home page Coder Social logo

honsa / godot-3-2d-day-night-cycle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hiulit/godot-3-2d-day-night-cycle

0.0 1.0 0.0 48.97 MB

A simple 2D Day/Night cycle using CanvasModulate and a Moon light effect using Light2D

License: MIT License

GDScript 100.00%

godot-3-2d-day-night-cycle's Introduction

Godot 3 2D Day/Night Cycle

A simple 2D โ˜€๏ธ Day / ๐ŸŒ‘ Night cycle using CanvasModulate.

Godot 3 2D Day/Night Cycle GIF

Now with a ๐ŸŒ• Moon effect using Light2D!

Without a Moon

Godot 3 2D Day/Night Cycle GIF

With a Moon

Godot 3 2D Day/Night Cycle GIF

With a moving Moon

Godot 3 2D Day/Night Cycle GIF

Installation

  • Download the repository ZIP file.
  • Copy DayNightCycle.tscn and DayNightCycle.gd in your project.
  • Copy Moon.tscn, Moon.gd and light.png in your project.

Usage

DayNightCycle

  • Instance DayNightCycle.tscn and attach DayNightCycle.gd as a script.

You can change all these variables right from the Inspector.

Inspector

Tips

Instance one DayNightCycle.tscn in your background scene and another DayNightCycle.tscn in your main scene or level scene, etc. and set the Day start hour in the background scene a little after than the Day start hour in the main scene to have the effect that the background starts changing before the foreground.

Main
โ”œโ”€โ”€ Background
โ”‚   โ””โ”€โ”€ DayNightCycle
โ”œโ”€โ”€ Player
โ”œโ”€โ”€ OtherStuff
โ””โ”€โ”€ DayNightCycle

Example

  • Background scene - Day start hour: 10.2
  • Main scene - Day start hour: 10

Moon

Warning!

Before using the Moon you should know that it is intrinsically connected with DayNightCycle. This is where singletons come in handy.

This project has a Global.gd that serves as a singleton. Its function is to have DayNight and Moon variables available always and from everywhere.

You can copy those variables and add them to your own singleton. In that case, you'll have to change all the Global.xxx variables accordingly.

  • Instance Moon.tscn and attach Moon.gd as a script.
  • In DayNightCycle.gd, uncomment the commented following line:
func _ready():
    # Global.DayNight = self

You can change all these variables right from the Inspector.

Inspector

Documentation

DayNightCycle

Day Duration

Name Type Description
day_duration float The duration of the day in minutes.

Day Start Hour

Name Type Description
day_start_hour float The starting hour of the day. 24 hours time (0-23).

Day Start Number

Name Type Description
day_start_number float The starting day number.

Color (DAWN)

Name Type Description
color_dawn Color The color of the DAWN state in RGBA.

Color (DAY)

Name Type Description
color_day Color The color of the DAY state in RGBA.

Color (DUSK)

Name Type Description
color_dusk Color The color of the DUSK state in RGBA.

Color (NIGHT)

Name Type Description
color_night Color The color of the NIGHT state in RGBA.

State (DAWN) Start Hour

Name Type Description
state_dawn_start_hour float The starting hour of the DAWN cycle state. 24 hours time (0-23).

State (DAY) Start Hour

Name Type Description
state_day_start_hour float The starting hour of the DAY cycle state. 24 hours time (0-23).

State (DUSK) Start Hour

Name Type Description
state_dusk_start_hour float The starting hour of the DUSK cycle state. 24 hours time (0-23).

State (NIGHT) Start Hour

Name Type Description
state_night_start_hour float The starting hour of the NIGHT cycle state. 24 hours time (0-23).

State Transition Duration

Name Type Description
state_transition_duration float The duration of the transition between cycle states in hours.

Debug mode

Name Type Description
debug_mode bool Enables/disables debug mode. It prints current_day_number, current_day_hour and cycle_state

On

Name Type Description
move bool Enables/disables the node.

Moon

State (DAWN) Energy

Name Type Description
state_dawn_energy float The energy value of the DAWN state. The larger the value, the stronger the light.

State (DAY) Energy

Name Type Description
state_day_energy float The energy value of the DAY state. The larger the value, the stronger the light.

State (DUSK) Energy

Name Type Description
state_dusk_energy float The energy value of the DUSK state. The larger the value, the stronger the light.

State (NIGHT) Energy

Name Type Description
state_night_energy float The energy value of the NIGHT state. The larger the value, the stronger the light.

State Transition Duration

Name Type Description
state_transition_duration float The duration of the transition between cycle states in hours.

Move

Name Type Description
move bool Enables/disables the Moon movement.

On

Name Type Description
move bool Enables/disables the node.

Authors

Me ๐Ÿ˜› @hiulit.

Credits

Thanks to:

License

MIT License.

godot-3-2d-day-night-cycle's People

Contributors

hiulit avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.