A lightweight real-time (or manual) day/night cycle & timekeeper for GameMaker.
Uses a 24-color palette for hours in the day and smoothly blends between them.
Applies background and foreground tint & saturation effect for cinematic atmosphere without losing gameplay clarity.
DayTime gives your project:
Smooth day and night transitions
Separate foreground and background tint/saturation effects
Real-time sync OR fully manual time
“Freeze” mode for static atmospheres
Hooks for hour, day, and time-period changes
Formatting helpers for displaying time & date
Safe Effect Layer creation and rebuilding
You can drop in the example for immediately results, but it's highly configurable.
Creates a new DayTime controller.
_foreground_depth — depth where the foreground tint + saturation layers are created
_background_depth — depth where the background tint + saturation layers are created
Returns: the new DayTime instance
// Create or Room Start day = new DayTime(-100, 100); global.day.rebuild_layers();
Call update() once per Step.
// Step Event day.update();
This'll update the DayTime and give you:
Reads real-world time (or manual time if enabled)
Applies offsets
Blends the palette
Applies tint and saturation effects
Triggers hooks if things change (hour / period / date)
Returns to reading system clock time.
none
Returns: self
Switches to manual time mode and sets the time.
hour
0-23
minute
0-59
second
0-59
Returns: self
Values are clamped safely.
day.set_time(23, 45);
Locks the cycle at the current real-world time, but keeps it manual.
none
Returns: self
day.freeze_now();
Perfect for static ambience.
Offsets the time after reading it.
hour_offset
min_offset
Returns: self
Works in real-time or manual mode.
// Run the game 2 hours ahead day.set_offsets(2, 0);
Replaces the 24-hour palette.
array24
array of 24 GameMaker colors
Returns: self
First entry = midnight, index matches hour.
day.set_colors(my_palette);
Controls tint strength by layer.
foreground_strength
subtle wash applied to gameplay layer
background_strength s
trong grade behind gameplay
Returns: self
Night smoothly increases intensity.
Controls how desaturated FG/BG become at night.
fg_day
fg_night
bg_day
bg_night
Returns: self
0 = full color
1 = greyscale
Creates or repairs Effect Layers if missing.
none
Returns: self
This is safe to call anytime.
global.day.rebuild_layers();
DayTime will also auto-repair if a layer disappears.
Called whenever the hour changes.
fn(new_hour, old_hour)
Returns: self
Period changes include:
"night"
"dawn"
"day"
"dusk"
fn(new_period, old_period)
Returns: self
Triggered when the date changes.
fn(new_date_str, old_date_str)
Returns: self
day.set_on_hour_change(function(n, o) { show_debug_message("Hour: " + string(n)); });
These are great for UI.
Returns "13:07"
Returns "1:07 PM"
Returns "2025-03-07"
Returns something like:
"Fri, Mar 7 2025"
or
"Fri, March 7 2025"
Returns:
"Wednesday"
"Wed"
Returns:
"night"
"dawn"
"day"
"dusk"
DayTime exposes:
year
month
day
hour
minute
second
weekday_index
weekday_long_str
weekday_short_str
tint_color
night_amount (0-1)
These are updated every update() call.
// Create day = new DayTime(-100, 100); // Room Start day.rebuild_layers(); // Step day.update();
Then tweak:
day.set_tint_ranges(.2, .75) .set_saturation_ranges(0, .12, .1, .55);
Did you like this post? Tell us
Leave a comment
Log in with your itch.io account to leave a comment.