Day and Night lighting in 001 Game Creator


This is a cross post from my development blog, partysofa.net

For this week I figured I'd do a behind the scenes look at how the time of day lighting system works in Tales of Astya.

The first step was creating a huge array in 001, to hold each of the overworld map locations, like so. You can also see that it says Z 1/24. Each of the Z layers holds the color information for that hour. 

Setting up the array

Skjermbilde 2017-07-05 21.28.59

Now that's all fine and dandy, it's time to delve into the scripting side of it. The system consists of four different events, detailed below.

  • Initialize Sun color
    • Used at launch to fill the array with the correct color info, rather than doing it by hand. Efficient!
  • Set Map Sun Color
    • Sets a specific color for a specific map, at a specific hour. 
  • Set Region Sun Color
    • Same as map, but for an entire region.
  • Update Region Sun
    • Updates the sun color to the correct color, with color blending.

The code behind it

Let's take a closer look at each of them, starting with Initialize Sun Color.

Skjermbilde 2017-07-05 21.37.34.png

A very simple script that allows me to specify a color for each of the hours and fills the array on that Z index with the color code. Nothing fancy about this one.

Set Map Sun Color as well, very simple. It gets which region to use, then applies the proper offset on X and Y. In this screenshot the offsets have not been applied just yet, but it is in the game now. Skjermbilde 2017-07-05 21.41.27.png

The code for Set Region Sun looks pretty much the same, just with two for loops going through the X and Y axis. 

Then at last, it's Update Region Sun Color, the one that took the most amount of time to get working correctly. It consists of two more for loops, going through the X and Y axis of the array. Skjermbilde 2017-07-05 21.48.37.png

The above screenshot is from the X axis loop, where it uses Change Sun Color (built in event to change map lighting) to the specified color inside the array, and then changing the Fog Color to the same color, just a bit lighter to add depth to the scene. The Sub Script in the middle labeled DEFAULT is the legacy lighting system and is no longer being used. It was placed there as a fallback before I got around to making the Initialize Sun Color event in case the lighting value was 0.Skjermbilde 2017-07-05 21.51.23.png It was pretty bad, and would only update four times each day, instead of 24 like the new one. 

Updating the lighting at runtime

That's all for the code part of the system, but what about the implementation? Very simple! In a trigger on the player which is triggered whenever Hour is changed, this code is placed to update the lighting correctly.

Skjermbilde 2017-07-05 21.53.46.png

Benefits of this system

One of the biggest benefits of this system is that it allows for dynamic changing of the sun color, either on a regional or local level based on actions by the player. The sun/night sky could be different colors while the player is on a quest for example, or it could be contstant day all the time. The possibilities are endless.

That's all for now, make sure to leave a comment, either on this post or Facebook telling me what you think or if you want to read more posts like these :) It was a lot of fun to make, so thanks for reading!

 

Get Wanderboots

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.