API Reference

A list of Sundial’s functions and settings, including what each argument does and what each function returns. If you’re new to Sundial, the other pages walk you through using it in your game.


Sundial

Sundial

Creates a Sundial with default colours, brightness and day/night timings. It starts at Morning with Auto Time turned off. By default, it takes over drawing the application surface until CleanUp() is called.

new Sundial(manage_application_surface)
Arguments
manage_application_surface optional Bool True to disable GameMaker's automatic application-surface drawing so Draw() can present the graded game. False to leave your renderer's setting untouched. Defaults to true. Creating a second managing Sundial before CleanUp() on the first causes an error.

Methods

Grading
SetGrading()Changes the grading colour for one of the six parts of the day.
SetGradingStrength()Changes how strongly a grading colour affects the scene.
SetBrightness()Sets how bright the outdoor scene should be during the day and at night. Sundial changes the brightness smoothly between the two.
Indoor and outdoor
SetIndoorGrading()Sets the base colour used for indoor areas. The indoor mask decides which parts of the scene this affects.
SetIndoorGradingStrength()Changes how strongly the indoor grading colour affects the scene.
SetIndoorDaylightInfluence()Controls how much of the outdoor grading colour reaches indoor areas. This changes colour, not brightness.
SetIndoorBrightness()Sets separate day and night brightness for indoor areas. Sundial blends between them as the day passes.
SetMask()Uses a surface to decide which parts of the scene are indoors. Black means outdoors, white means indoors, and grey blends the two. The mask can be any size. It will be stretched to fit the scene.
SetMaskSprite()Uses a sprite instead of a surface for the indoor mask. Black means outdoors, white means indoors, and grey blends the two. The sprite is stretched to fit the scene.
ClearMask()Removes the indoor mask. The whole scene will use the outdoor grading again.
HasMask()Checks whether the mask you supplied still exists, whether it is a surface or a sprite.
GetMask()Gets the surface or sprite currently being used as the indoor mask. Use HasMask() to check whether it still exists.
Time and clock
SetTimeOfDay()Moves Sundial to a position in the day from 0 to 1. Values outside that range wrap around. If a manual jump changes the period, only the new period's callbacks run.
GetTimeOfDay()Gets the current position in the day as a number from 0 to 1, where 0 is Morning and 1 is the end of the day.
SetDayPercent()Another name for SetTimeOfDay(). Sets how far through the day Sundial is, using a number from 0 to 1.
GetDayPercent()Another name for GetTimeOfDay(). Gets how far through the day Sundial is.
SetMorningTime()Sets what time on the 24-hour clock Morning begins. This changes the clock, not the length of the day or the grading.
GetMorningTime()Gets the 24-hour clock time when Morning begins.
SetTime()Moves Sundial to a particular time on the 24-hour clock. This does not turn Auto Time on or off, and skipped periods do not get their callbacks run.
GetTime()Gets the current time on Sundial's 24-hour clock.
GetHour()Gets the hour from Sundial's current clock time.
GetMinute()Gets the minute from Sundial's current clock time.
SetCycleTiming()Changes when the different parts of the day start and how long the colour changes between them take. All six values use a fraction of the day from 0 to 1. Invalid ordering causes a fatal error.
Automatic time
SetAutoTime()Turns automatic time on or off. When enabled, Sundial advances its clock using elapsed real time.
GetAutoTime()Checks whether Auto Time is turned on. It can still be turned on when the time speed is set to 0.
SetDayLength()Sets how many real seconds a complete day takes when Auto Time is on. This also changes the speed returned by GetSpeed().
GetDayLength()Gets how many real seconds a complete game day takes at the current speed.
SetSpeed()Sets how quickly Sundial's clock moves when Auto Time is on. This also changes its day length. Use 0 to pause it without turning Auto Time off.
GetSpeed()Gets the current speed of Sundial's automatic clock.
Update()Updates the automatic clock immediately, including any period callbacks. Normally you can leave this alone, as Draw() and getters such as GetTime() and GetPeriod() update it too.
Periods and callbacks
GetPeriod()Gets which of the six time periods is active. These are the periods you set in the IDE, rather than Sundial's additional colour-blending phases.
OnPeriodChanged()Adds a function that runs when Sundial moves from one period to another. You can add more than one.
OnPeriod()Adds a function to run when the specified period begins. Adding another function does not replace the ones already there.
OnMorning()Adds a function to run when Morning begins.
OnDay()Adds a function to run when Day begins.
OnAfternoon()Adds a function to run when Afternoon begins.
OnDusk()Adds a function to run when Dusk begins.
OnNight()Adds a function to run when Night begins.
OnDawn()Adds a function to run when Dawn begins.
Daylight and colour changes
GetSunlightAmount()Gets Sundial's current daylight value. Sundial uses this to work out brightness, but you can use it for your own lighting, shadows or other effects.
GetPhase()Gets the part of the day that currently has the strongest influence on the grading. This includes Sunset, Twilight and Predawn, which are separate from the six gameplay periods.
GetPhaseName()Gets the name of the current grading phase, such as "sunset" or "twilight".
Drawing and stopping
Draw()Colour grades your game and draws the result on screen. For most games, just call Draw() in Post Draw. By default, Sundial stops GameMaker from drawing your game a second time. You can also give it your own surface and choose where to draw it. The surface you give it is left unchanged.
CleanUp()Restores the application-surface drawing setting captured when this Sundial was created. Call this from your controller's Clean Up event when it stops presenting the game. Repeated calls are safe. Sundial does not free your surfaces or sprites.
SetGrading(stage, colour)

Changes the grading colour for one of the six parts of the day.

Arguments
stage Real Which part of the day to change, using eSundial (for example, eSundial.DUSK).
colour Real The GameMaker colour to use.
Returns
Struct.Sundial
SetGradingStrength(stage, strength)

Changes how strongly a grading colour affects the scene.

Arguments
stage Real Which part of the day to change, using eSundial.
strength Real 0 removes this stage's colour influence, 1 uses full strength, and values above 1 make it stronger. Cannot be negative.
Returns
Struct.Sundial
SetBrightness(day_brightness, night_brightness)

Sets how bright the outdoor scene should be during the day and at night. Sundial changes the brightness smoothly between the two.

Arguments
day_brightness Real Brightness during full daylight. 1 leaves brightness unchanged. Higher values brighten the scene.
night_brightness Real Brightness at night. 1 leaves brightness unchanged. Lower values darken the scene.
Returns
Struct.Sundial
SetIndoorGrading(colour)

Sets the base colour used for indoor areas. The indoor mask decides which parts of the scene this affects.

Arguments
colour Real The GameMaker colour to use indoors.
Returns
Struct.Sundial
SetIndoorGradingStrength(strength)

Changes how strongly the indoor grading colour affects the scene.

Arguments
strength Real 0 leaves the indoor base colour neutral, 1 uses the chosen indoor colour, and values above 1 make it stronger. Cannot be negative.
Returns
Struct.Sundial
SetIndoorDaylightInfluence(amount)

Controls how much of the outdoor grading colour reaches indoor areas. This changes colour, not brightness.

Arguments
amount Real 0 uses only the indoor colour, while 1 uses the full outdoor colour grading. Values between 0 and 1 blend them.
Returns
Struct.Sundial
SetIndoorBrightness(day_brightness, night_brightness)

Sets separate day and night brightness for indoor areas. Sundial blends between them as the day passes.

Arguments
day_brightness Real Indoor brightness during the day. 1 leaves brightness unchanged.
night_brightness Real Indoor brightness at night. 1 leaves brightness unchanged.
Returns
Struct.Sundial
SetMask(mask_surface)

Uses a surface to decide which parts of the scene are indoors. Black means outdoors, white means indoors, and grey blends the two. The mask can be any size. It will be stretched to fit the scene.

Arguments
mask_surface Real An existing surface to use as the mask. Sundial reads its red channel but will not delete the surface for you. If GameMaker destroys it, recreate it and call SetMask() again.
Returns
Struct.Sundial
SetMaskSprite(mask_sprite, [subimage])

Uses a sprite instead of a surface for the indoor mask. Black means outdoors, white means indoors, and grey blends the two. The sprite is stretched to fit the scene.

Arguments
mask_sprite Asset.GMSprite A bitmap sprite to use as the mask. Sundial reads its red channel, not its transparency. The sprite origin is ignored, and areas trimmed away by GameMaker count as outdoors.
subimage optional Real Which frame to use, starting from 0. Defaults to 0. Sundial will not animate the mask for you.
Returns
Struct.Sundial
ClearMask()

Removes the indoor mask. The whole scene will use the outdoor grading again.

Returns
Struct.Sundial
HasMask()

Checks whether the mask you supplied still exists, whether it is a surface or a sprite.

Returns
Bool
GetMask()

Gets the surface or sprite currently being used as the indoor mask. Use HasMask() to check whether it still exists.

Returns
Real|Asset.GMSprite
GetTimeOfDay()

Gets the current position in the day as a number from 0 to 1, where 0 is Morning and 1 is the end of the day.

Returns
Real
GetSunlightAmount()

Gets Sundial's current daylight value. Sundial uses this to work out brightness, but you can use it for your own lighting, shadows or other effects.

Returns
Real
GetPhase()

Gets the part of the day that currently has the strongest influence on the grading. This includes Sunset, Twilight and Predawn, which are separate from the six gameplay periods.

Returns
Real
GetPhaseName()

Gets the name of the current grading phase, such as "sunset" or "twilight".

Returns
String
SetCycleTiming(day_fraction, morning_duration, afternoon_start, sunset_duration, twilight_duration, predawn_duration)

Changes when the different parts of the day start and how long the colour changes between them take. All six values use a fraction of the day from 0 to 1. Invalid ordering causes a fatal error.

Arguments
day_fraction Real The point in the day where Dusk begins.
morning_duration Real How long Morning takes to fade into Day.
afternoon_start Real When the Afternoon colour starts blending in. This is not the same as when the Afternoon period begins.
sunset_duration Real How much time before Dusk is used for the sunset colour change.
twilight_duration Real How much time after Dusk is used for twilight before Night.
predawn_duration Real How much of the end of Night is used to blend through Dawn into Morning.
Returns
Struct.Sundial
SetTimeOfDay(time_of_day)

Moves Sundial to a position in the day from 0 to 1. Values outside that range wrap around. If a manual jump changes the period, only the new period's callbacks run.

Arguments
time_of_day Real Position in the day. 0 and 1 both represent Morning, at the start and end of the cycle.
Returns
Struct.Sundial
SetAutoTime(enabled)

Turns automatic time on or off. When enabled, Sundial advances its clock using elapsed real time.

Arguments
enabled Bool True to let Sundial advance time, false if your game will control the time itself.
Returns
Struct.Sundial
GetAutoTime()

Checks whether Auto Time is turned on. It can still be turned on when the time speed is set to 0.

Returns
Bool
SetDayLength(seconds)

Sets how many real seconds a complete day takes when Auto Time is on. This also changes the speed returned by GetSpeed().

Arguments
seconds Real Number of real seconds in one game day. Must be greater than 0. For a ten-minute day, use 600.
Returns
Struct.Sundial
GetDayLength()

Gets how many real seconds a complete game day takes at the current speed.

Returns
Real
SetSpeed(speed)

Sets how quickly Sundial's clock moves when Auto Time is on. This also changes its day length. Use 0 to pause it without turning Auto Time off.

Arguments
speed Real Number of game seconds that pass for every real second. For example, 120 makes two game minutes pass per second. Cannot be negative.
Returns
Struct.Sundial
GetSpeed()

Gets the current speed of Sundial's automatic clock.

Returns
Real
SetDayPercent(percent)

Another name for SetTimeOfDay(). Sets how far through the day Sundial is, using a number from 0 to 1.

Arguments
percent Real Position in the day, from 0 to 1. Values outside this range wrap around.
Returns
Struct.Sundial
GetDayPercent()

Another name for GetTimeOfDay(). Gets how far through the day Sundial is.

Returns
Real
SetMorningTime(hour)

Sets what time on the 24-hour clock Morning begins. This changes the clock, not the length of the day or the grading.

Arguments
hour Real Clock time in decimal hours. 6 means 06:00 and 6.5 means 06:30. Values wrap around 24 hours.
Returns
Struct.Sundial
GetMorningTime()

Gets the 24-hour clock time when Morning begins.

Returns
Real
SetTime(hour)

Moves Sundial to a particular time on the 24-hour clock. This does not turn Auto Time on or off, and skipped periods do not get their callbacks run.

Arguments
hour Real Clock time in decimal hours. For example, 18.5 means 18:30. Values wrap around 24 hours.
Returns
Struct.Sundial
Example
sundial.SetTime(18.5); // 18:30
GetTime()

Gets the current time on Sundial's 24-hour clock.

Returns
Real
GetHour()

Gets the hour from Sundial's current clock time.

Returns
Real
GetMinute()

Gets the minute from Sundial's current clock time.

Returns
Real
GetPeriod()

Gets which of the six time periods is active. These are the periods you set in the IDE, rather than Sundial's additional colour-blending phases.

Returns
Real
OnPeriodChanged(callback)

Adds a function that runs when Sundial moves from one period to another. You can add more than one.

Arguments
callback Function Function receiving the previous period and the new period, both as eSundialPeriod values.
Returns
Struct.Sundial
Example
sundial.OnPeriodChanged(function(_from, _to) {
    global.current_period = _to;
});
OnPeriod(period, callback)

Adds a function to run when the specified period begins. Adding another function does not replace the ones already there.

Arguments
period Real Which period to watch, using eSundialPeriod.
callback Function Function to run when that period begins.
Returns
Struct.Sundial
OnMorning(callback)

Adds a function to run when Morning begins.

Arguments
callback Function Function to run when Morning begins.
Returns
Struct.Sundial
OnDay(callback)

Adds a function to run when Day begins.

Arguments
callback Function Function to run when Day begins.
Returns
Struct.Sundial
OnAfternoon(callback)

Adds a function to run when Afternoon begins.

Arguments
callback Function Function to run when Afternoon begins.
Returns
Struct.Sundial
OnDusk(callback)

Adds a function to run when Dusk begins.

Arguments
callback Function Function to run when Dusk begins.
Returns
Struct.Sundial
OnNight(callback)

Adds a function to run when Night begins.

Arguments
callback Function Function to run when Night begins.
Returns
Struct.Sundial
OnDawn(callback)

Adds a function to run when Dawn begins.

Arguments
callback Function Function to run when Dawn begins.
Returns
Struct.Sundial
Update()

Updates the automatic clock immediately, including any period callbacks. Normally you can leave this alone, as Draw() and getters such as GetTime() and GetPeriod() update it too.

Returns
Struct.Sundial
CleanUp()

Restores the application-surface drawing setting captured when this Sundial was created. Call this from your controller's Clean Up event when it stops presenting the game. Repeated calls are safe. Sundial does not free your surfaces or sprites.

Returns
Struct.Sundial
Draw([source_surface], [x], [y], [width], [height])

Colour grades your game and draws the result on screen. For most games, just call Draw() in Post Draw. By default, Sundial stops GameMaker from drawing your game a second time. You can also give it your own surface and choose where to draw it. The surface you give it is left unchanged.

Arguments
source_surface optional Real The surface to grade. Leave this out in Post Draw to use the application surface. Omitting a surface while trying to Draw in another Draw event causes a fatal error (as you cannot draw a surface onto itself).
x optional Real Where to draw it horizontally. Defaults to the correct window position for the application surface, or 0 for your own surface.
y optional Real Where to draw it vertically. Defaults to the correct window position for the application surface, or 0 for your own surface.
width optional Real Draw width. Defaults to the application surface's displayed width, or your supplied surface's width.
height optional Real Draw height. Defaults to the application surface's displayed height, or your supplied surface's height.
Returns
Id.Surface
Example
// In Post Draw, colour grade your game.
sundial.Draw();

// Or draw your own surface at a chosen position and size.
sundial.Draw(my_surface, 0, 0, 1280, 720);

Starting, stopping and loading

SundialStart([preset_name])

Starts Sundial using a preset from the Visual Editor. Sundial will handle the drawing for you and keep working when you change rooms. If it's already running, calling this again won't restart the day or change the preset. Call SundialStop() first if you want to switch presets.

Arguments
preset_name optional String The name of the preset to load. Leave this out to use the default preset. To switch presets later, call SundialStop() first.
Returns
Struct.Sundial
Example
sundial = SundialStart();
sundial.SetDayLength(600);
SundialStop()

Stops Sundial if you started it with SundialStart(). It puts GameMaker's drawing setting back the way it was. You can call it more than once. It won't change other Sundials you created yourself or masks you supplied.

Example
SundialStop();
SundialImport([preset_name], [manage_application_surface])

Loads a Sundial preset you saved using Sundial Visual Editor. Without a name, it loads whichever preset you marked as Default.

Arguments
preset_name optional String Exact name of the preset to load. Leave this out to load the default preset. An unknown name causes an error.
manage_application_surface optional Bool True to let Sundial manage application-surface drawing until CleanUp() is called. False to leave your renderer's setting untouched. Defaults to true. Pass undefined for the preset name to use the default preset with this option.
Returns
Struct.Sundial
Example
sundial = SundialImport();

// Or load one named preset.
winter_sundial = SundialImport("Winter");
See also

Enums

Grading colours

eSundial

The six parts of the day you can give their own colours and grading strengths.

Values
MORNING Use this to change the Morning colour.
DAY Use this to change the Day colour.
AFTERNOON Use this to change the Afternoon colour.
DUSK Use this to change the Dusk colour, including sunset and twilight.
NIGHT Use this to change the Night colour.
DAWN Use this to change the Dawn colour, as night turns into Morning.
NUM The number of grading choices. It is not a part of the day.

Time

eSundialPeriod

The six parts of the day reported by GetPeriod() and used by functions such as OnMorning() and OnNight().

Values
MORNING Morning, when Sundial's day begins.
DAY Daytime.
AFTERNOON Afternoon.
DUSK Dusk.
NIGHT Nighttime.
DAWN Dawn.
NUM The number of periods. Not a period itself.
eSundialPhase

More detailed parts of the day used by Sundial's colour changes, including Sunset, Twilight and Predawn.

Values
MORNING The Morning part of the colour changes.
DAY The Day part of the colour changes.
AFTERNOON The Afternoon part of the colour changes.
SUNSET Sunset, when the colours are moving towards Dusk.
TWILIGHT Twilight, between Dusk and Night.
NIGHT Nighttime.
PREDAWN The change from Night through Dawn and back to Morning.
NUM The number of phases. Not a phase itself.

Version

SUNDIAL_VERSION

The version of Sundial you have installed.

Value
"1.0.0"

Symbol index

C
CleanUp() | Sundial
ClearMask() | Sundial
D
Draw() | Sundial
G
GetAutoTime() | Sundial
GetDayLength() | Sundial
GetDayPercent() | Sundial
GetHour() | Sundial
GetMask() | Sundial
GetMinute() | Sundial
GetPeriod() | Sundial
GetPhase() | Sundial
GetPhaseName() | Sundial
GetSpeed() | Sundial
GetTime() | Sundial
GetTimeOfDay() | Sundial
H
HasMask() | Sundial
O
OnAfternoon() | Sundial
OnDawn() | Sundial
OnDay() | Sundial
OnDusk() | Sundial
OnMorning() | Sundial
OnNight() | Sundial
OnPeriod() | Sundial
U
Update() | Sundial
Macros