Dynamic Lighting
Version: 1.5
Author: Marc of Fall From Eden
Date: March 17, 2012
Version History
- <Version 1.5> 2012.03.17 - Added the ability to enable or disable all light effects through a switch ID.
- <Version 1.4> 2012.03.14 - Merged the core script with the Player Lighting add-on and modified the core module accordingly.
- <Version 1.2> 2012.02.18 - Provided a major bug fix for Dynamic Lighting (lights would "stick" to the window), a minor fix for Player Lighting (lighting changes would not be saved after loading a game), and provided another add-on script (Player Vignette) in the demo.
- <Version 1.1> 2012.02.18 - Changed the way flickering is handled; also rearranged the "setup_lights" method and added the method "draw_lights". Also added the Player Lighting add-on.
- <Version 1.0> 2012.02.16 - Original Release
Description
This script allows you to place dynamic lights that emit from events on the map. The
main difference between this script and scripts such as Thomas Edison VX or Kylock's Light System is the fact that lights may be enabled or disabled while the scene is running without requiring the script call "$scene = Scene_Map.new" (which causes the screen to momentarily freeze). The opacity level of lights may also be changed while the scene is running, thus allowing you to event systems that allow lights to smoothly blink or strobe (or any other effect you can think of utilizing the visibility and opacity of lights).
The way light types are defined has changed dramatically as well, allowing you to define your own lights and their properties easily through a module. This way, you can have lights with differing x and y zoom values (in essence, creating lights with different shapes), and light types may also use different pictures (for instance, lanterns could have a different light picture displayed than torches).
The script also enables you to have a light effect dynamically created over the player's character in-game with the same dynamic qualities as any other light shown on the map.
The script demo also includes a module that attempts to recreate the light effects seen in Thomas Edison VX.
Features
- Allows the creation of lights which emit from events on the map.
- The visibility state and opacity of a light may be changed with script calls.
- These changes are done without reloading Scene_Map, and can be persistent across map loads (with some minor eventing).
- Given this, lights can be evented to blink or strobe directly on the map.
- Different light types may use different pictures for their lighting effect.
- All light types are written into a module that can be easily modified or extended.
- You can have a dynamic light effect over the player.
- Using the Player Vignette add-on, the player can optionally be surrounded by a dark vignette with modifiable size and opacity (perfect for dark dungeons and the like).
Screenshots Instructions
It is
highly recommended that you download the script demo so as to learn how the effects were done and how to use the Marc::Light module effectively.
In any case, the script itself
can be used as a drop-in replacement for Thomas Edison VX. By doing this, however, you may miss out on some of the more interesting features of this script (for instance, how to event lights so that they can blink or strobe on the map and save their visibility states).
You may create a light in the same way it is done in Thomas Edison VX: by creating a comment in the event you want to create light containing the name of the light type you want to emit (the light types are defined in the module Marc::Light and are clearly labeled). To hide the light effect when the map loads, simply append the word "INVISIBLE" to the name of the light type (for example, you could write the comment "FIRE INVISIBLE" without quotes to create a light of FIRE type that is hidden when the map is loaded).
To change the visibility state of a light on the map, you must make a script call. The method to set the visibility state is "set_light_visibility", and it takes up to two arguments: the event ID of the light you want to change, and the visibility state (which may be one of true, false, or "toggle"). If the visibility state argument is left out, the script will default to toggling the visibility of the light. So, to change the visibility state of the light on event ID 5, you could write any of the following (depending on the desired effect):
set_light_visibility(5, true)
set_light_visibility(5, false)
set_light_visibility(5, "toggle")
set_light_visibility(5) # functionally identical to set_light_visibility(5, "toggle")
Similarly, you can set the opacity level of a light on the map with the method "set_light_opacity". This method explicitly requires two arguments: the event ID of the light you want to modify, and the desired opacity level (from 0 to 255, 0 being fully transparent). The second argument can also use a variable (such as $game_variables[1]) that you can set with events.
set_light_opacity(5, 75)
set_light_opacity(5, $game_variables[1]) # sets the opacity to the value of Variable 1.
The last method, "light_visible?", simply returns true or false based on the visibility state of the light on the event ID specified by its argument. Given the nature of this method, the only argument you should provide is the event ID of the light you want to check.
light_visible?(5) # returns either true or false
This method can be used effectively in conditional branches for dynamic lights that you may wish the player to turn on and off via an external event (such as a floor plate or light switch). You could also potentially use this to create evented systems such as fire arrows that can light torches and give the player the ability to blow the torches back out.
With the Player Lighting add-on, a few new methods have been added to Game_Interpreter. These are the methods "player_light_visible?", "set_player_light_vis", "set_player_light_type", and "get_player_light_type".
The method "player_light_visible?" simply returns a true or false value based on the visibility of the player light. It requires no arguments, and doesn't expect any.
player_light_visible? # returns true or false
If you need to change the visibility of the player's light (for instance, if they turn off or lose whatever was generating the light), use the method "set_player_light_vis". This method has one optional argument: the visibility state to set the light to. This state can be one of true, false, or "toggle", and the method defaults to "toggle" if no argument is given.
set_player_light_vis(true)
set_player_light_vis("toggle")
set_player_light_vis # functionally identical to set_player_light_vis("toggle")
In order to change the light type shown on the player, use the method "set_player_light_type". This method takes one optional argument: the name of the type you wish to change the player's light to. If no argument is given, the type is reset to the default value supplied in the configuration section of the Player Lighting add-on.
NOTE: Light type changes are
not dynamic. If you change the player's light type while on the map, you
will have to make the script call "$scene = Scene_Map.new" due to the way light types are initialized.
set_player_light_type("TORCH")
set_player_light_type # reverts to default player light type
You can also get the current type of the player's light with the method "get_player_light_type". This method returns the player's light type as a string (which you could potentially use in Conditional Branches). No arguments are necessary or expected.
get_player_light_type
Script
You really should grab the demo. But in case you want just the script, you will have to grab the module
here, and the core script
here. You will also require a picture named "le" to use for your light effects if you use the supplied module. We recommend
the one we made for it. For the player vignette, use
this image for the default RMVX resolution or
this one for games using 640x480 resolution. If you use the 640x480 vignette, make sure to rename it to pv.png or change the value used for the vignette in the script's module.
Credit
Thanks
- BulletXT and Kylock for the original Thomas Edison VX script.
Support
You may receive support for this script in this topic or by sending us a personal message on these forums.
Known Compatibility Issues
This script will
technically function properly if used in conjunction with Thomas Edison VX, but that really defeats the entire purpose, and will layer two lights on each event. As obvious as that may seem, we still thought it was worth mentioning.
There is also a bug that we know about, but cannot seem to fix at the moment. If you have a map that is set to scroll horizontally, vertically, or both, the light effects will disappear if the same event is seen on the map twice and reappear once the event is shown on the map a single time. We think we know why this happens, but are currently at a loss as to how to fix the bug. If anyone has any ideas or thinks they can fix it, please feel free! Just let us know how you did it or how we can implement the bug fix.
Demo
Author's Notes
Download the demo. Really, it's
very useful to see how everything works.
With that said, this script was primarily written for our own needs while creating an atmospheric adventure-style game. Considering the thick atmosphere, we required lighting that could change dynamically in-game without reloading Scene_Map. After looking at the original Thomas Edison VX script, we decided to essentially rewrite the entire system from scratch... and ended up implementing it in a
very different way.
In any case, if anyone would like to suggest improvements to the script, please feel free to let us know what you have in mind!
Restrictions
This script is licensed under a Creative Commons BY-SA 3.0 license. Essentially, you may use it for commercial games, but proper attribution is required; as well, you may modify the script any way you like as long as the modified version retains attribution to the original author and is released under an
identical license.