RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Simple Shadows

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 60
Simple Shadows
Version: 1.1b
Author: Marc of Fall From Eden
Date: April 12, 2012

Version History


  • <Version 1.1b> 2012.04.12 - Minor bug fix. Events casting "sun" shadows would not have their shadows erased if the event graphic was changed to None.
  • <Version 1.1> 2012.03.23 - Added an option in the Marc::Shadow module to enable or disable showing shadows only on floor tiles (for compatibility purposes).
  • <Version 1.0> 2012.03.15 - Original Release

Description


This is a cosmetic script originally intended to work in tandem with Marc's Dynamic Lighting script in order to create shadows that are cast from the player and other events based on how close they are to a light source.

Features

  • Generates shadows from defined light sources that may be cast on the player and other events.
  • These light sources can be automatically generated if you are using Marc's Dynamic Lighting script.
  • You may also create a "sun" effect that creates a constant shadow for exterior maps.
  • Shadows are based on a picture rather than character or event graphics (making for smooth shadows).
  • Shadows may only cast on "floor" tiles (tiles from TileA1, TileA2, and TileA5), not walls.
  • For compatibility purposes, you can disable shadows being shown only on floor tiles.
  • These effects may be enabled or disabled through a switch.
  • It's eye-candy! :V

Screenshots



Instructions

This script is relatively easy to use, particularly if you are already using Marc's Dynamic Lighting script (seeing as dynamic lights used in that system automatically generate shadows with this script). By default, however, no other events cast shadows, nor are they considered light sources that generate them.

In order to create a light source, add the comment SHADOW_SOURCE to the event you want to use as a light source. This will make the event generate shadows which will be displayed on shadow-casting events. To make an event cast shadows, add the comment SHADOW_CAST to the event.

For exterior scenes, you may also create a "sun" effect by adding the comment SHADOW_SUN to any event on the map. This will create a persistent shadow that is generated by all shadow-casting events on the map with a pre-defined angle and opacity.

The script also makes use of the Marc::Shadow module, which allows you to change some of the default settings of the script. The first thing you will likely want to change is the SHADOW_SWITCH, which you should set to the switch ID that you want to enable or disable the shadow effects. SHADOW_ENABLED determines whether or not you wish to have the SHADOW_SWITCH turned "ON" automatically when a new game is started (this does not affect saved and loaded games). By default, the player also generates shadows; if you want this effect disabled, change PLAYER_SHADOW to "false" (without quotes). If you are using Marc's Dynamic Lighting script, you can have light effects automatically generate shadows by setting AUTO_SHADOW to "true" (without quotes); if this is not desired, set it to "false" (again, without quotes).

NOTE: If the SHADOW_SWITCH is turned "OFF" or "ON" while the map is running, you will have to make the script call "$scene = Scene_Map.new" in order to clear or add the shadow effects!

To change the file used to create shadows, change the value of SHADOW_FILE to the name of the picture you would like to use as a shadow. Likewise, you may change the maximum opacity of shadows with SHADOW_OPACITY. The maximum range of shadows is represented as a number of tiles in SHADOW_RANGE (so a range of 4 will show shadows up to four tiles away from the light source).

You can also change the angle of "sun" effects with SUN_ANGLE, and the opacity of shadows generated by the "sun" effect with SUN_OPACITY.

The SHADOWS_ONLY_ON_FLOOR constant determines whether or not you want the shadows to be cast on floor tiles (TileA1, TileA2 and TileA5) or on all tiles. Set it to true to only show shadows on floors, false to show them on all tiles. Setting this to true makes the shadows look a bit nicer overall, but may reduce compatibility; setting it to false, on the other hand, does not look quite as good, but should be very compatible with other scripts.

Any of the values written in the Marc::Shadow module may be modified in-game by making a script call. For example, to change the maximum range of all shadows, make the script call "Marc::Shadow::SHADOW_RANGE = <new value>". Note that some of these changes will require the script call "$scene = Scene_Map.new" to take effect immediately. (With some ingenuity, you could use this with a time script to change the angle of the "sun" shadows based on the current time, since changing the angle and opacity of the "sun" effect does not require renewing the scene. ;))

Script


You may get the latest version of this script from my public Dropbox here. You will also require this image in your Graphics/Pictures directory, or this image if you are using Mack-style characters. (NOTE: You will need to rename the image for Mack-style characters to "sh.png" or change the value of SHADOW_FILE to "sh_mack" in the script.)

Credit


  • Marc of Fall From Eden
  • rataime (for shadow-related formulas)

Support


You may receive support for this script in this topic or by sending us a personal message on these forums. Support in this topic is for the Simple Shadows script only, not the Dynamic Lighting script included in the demo!

Known Compatibility Issues

This script aliases quite a bit in Spriteset_Map, including overwriting how tilemaps are assigned to viewports. As such, there are likely to be compatibility problems with scripts which modify tileset viewports or make other extensive modifications to Spriteset_Map. If you encounter such compatibility problems, please let us know which script is conflicting with this one, and Marc will attempt to correct the issue. :)

Demo


Simple Shadows Demo
Includes the Simple Shadows script as well as Marc's Dynamic Lighting core script and module.

Author's Notes


This script was written entirely for our own purposes while creating an atmospheric adventure-style psychological horror game. This was the primary reason for such tight integration with Marc's Dynamic Lighting system. Honestly, he only added some other features to the script because he thought that they would be useful to anyone not using his previous script.

As such, this script may seem light on features, but we've found the effect of it to be pleasing to the eye and easy enough to use that we thought we would share the outcome. :)

Restrictions

:ccbysa:
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.
« Last Edit: April 13, 2012, 04:55:44 AM by Kevin O »

*
RMRK's dad
Rep:
Level 86
You know, I think its all gonna be okay.
For going the distance for a balanced breakfast.Project of the Month winner for June 2009For being a noted contributor to the RMRK Wiki2013 Best WriterSilver Writing ReviewerSecret Santa 2013 Participant
Hm. Nifty. Thanks for the effort and for sharing this with us!
:tinysmile:

**
Rep: +0/-0Level 62
RMRK Junior
This is another great script, and I really want to use it. I've encounter a minor issue tho. It has to do with YEM Core fixes and upgrades also. The ground in the enlarge part of the screen stays black, but you can still see trees, more or less any thing above the ground layer. I'm going to mess around, and see if I can figure something out chances are I won't, since I'm still a newb to all this stuff. I'll give it my best tho. Please if you find a solution post it, I wouldnt be the only one benifiting from it. Thanks.

***
Rep:
Level 60
This is another great script, and I really want to use it. I've encounter a minor issue tho. It has to do with YEM Core fixes and upgrades also. The ground in the enlarge part of the screen stays black, but you can still see trees, more or less any thing above the ground layer. I'm going to mess around, and see if I can figure something out chances are I won't, since I'm still a newb to all this stuff. I'll give it my best tho. Please if you find a solution post it, I wouldnt be the only one benifiting from it. Thanks.

Eden: This is... interesting, because I'm also using YEM Core Fixes and Upgrades with this script and I'm not encountering any problems. Marc believes it's likely to be a problem with another script that plays around with viewports (like this one does). That's just so the shadows are displayed only on the ground instead of on any other tiles, though, which means he could throw together a version that doesn't use viewports at all (or so he tells me). I can let him do that sometime soon and post that version if you're still having problems with it working correctly.

**
Rep: +0/-0Level 62
RMRK Junior
Did you try a game with only those two scripts added. Cause if you are using the dynamic lighting with the player vignette turned on then you can't see it. There for its not a problem. It's only when the vignette is turned off. But if the problem lies in the view portal, and he can write a script without those that would be awesome. For For now I guess I'll just have to shrink my resolution a bit.

***
Rep:
Level 60
Marc: I am not having any issues with this script and YEM Core Fixes and Upgrades. Could you please provide me with a demo that demonstrates the problem so that I may look into it for you? Since I cannot recreate the problem, I do not know what is causing it... and therefore cannot fix it. :)

Edit: The script has been updated to Version 1.1, which allows you to specify whether you want to show shadows only on floor tiles or not. Drawing shadows only on floors requires rewriting the way viewports and tilemaps are created, which may cause script incompatibilities. By disabling that feature, the script should be more compatible overall. :)
« Last Edit: March 23, 2012, 02:52:56 PM by Fall From Eden »

**
Rep: +0/-0Level 62
RMRK Junior
That's crazy I don't understand why I'd be the only one having this issue. I've started multiple new games in order to see if it were other scripts I was using and every time it's the same thing. Right now I'm unable to post any demos, cause I only have my IPhone for Internet. As soon as I'm able to I will. I'm certain it's nothing I did cause I got the script straight from your demo. Anyway thanks for taking the time to update the script.

Edit: Nice job Marc, that update worked perfect. Thanks again.
« Last Edit: March 23, 2012, 06:50:42 PM by d_m_b87 »

***
Rep:
Level 60
Marc: Glad to hear it. :)

I still suspect that the root problem is the drawing of the viewports, though. Are you still using a higher resolution than 544x416 for your game? If so, the viewports created by this script would be too small, which would cause the areas that are larger than 544x416 in size to be drawn incorrectly. If that's the problem, then a fix would be incredibly easy. In fact, I'll update the script with that in a moment (considering I should only have to change two or so lines). :)

Edit: To correct myself, one line. If you don't feel like downloading the demo or the script again, just find this line:

Code: [Select]
@viewport0 = Viewport.new(0, 0, 544, 416)

And change it to this:

Code: [Select]
@viewport0 = Viewport.new(0, 0, Graphics.width, Graphics.height)

Now you should be able to use the "shadows only on floor tiles" feature if you want to without any issues. Hopefully. ;)
« Last Edit: March 23, 2012, 08:48:48 PM by Fall From Eden »

**
Rep: +0/-0Level 62
RMRK Junior
When I first got the updated script I took a look at it, and noticed what you had change. So did a little experiment with it and change the resolution part to 640 x 480. Then change the core fix resolution to 640 x 480. Blam perfect ;D. You did a great job. Im really trying to learn ruby so I can script rgss2, it's been a slow process tho. I have no experience with programming unfortunately  :(

***
Rep:
Level 60
Marc: Ruby is a good place to start if you're new to programming, I believe. Many scripting languages are. :) I, of course, had to start with C... and proceed to pull my hair out in handfuls. ::)

But really, the greatest advantage Ruby has, to me, is the plethora of different ways to do things. It can accommodate a great many styles of programming with relative ease in comparison to some other languages (although I'm certainly no expert on such things; the only languages I know relatively well are Ruby, Python, and C).

Honestly, though, I'm still learning RGSS2 myself. Having a background in Ruby helps quite a bit, but scripting in RGSS2 can be quite different from writing pure Ruby... particularly considering RGSS2 uses an older version of Ruby than I have been using relatively recently. That was a relatively subtle warning, by the way, if you plan to learn Ruby for RGSS2 and want to use it for other purposes in the future. ;)

Good luck! :)

***
Rep:
Level 60
Just a bump for a minor bug-fix. If an event on the map had a shadow and there was a "sun" event present on the map, the sun shadows would not be erased if the shadow-casting event's graphic got changed to None, which would just leave a shadow sitting there. Not very pretty, so it's been fixed. ;)

**
Rep: +0/-0Level 62
RMRK Junior
Ey I've been awhile, and i'm just starting to get back into my project. I'd like to bring up a problem i've run into. I notice while using this simple shadow script, SwapXT doesn't work properly. And what i mean by that is after swapping the tiles, and then going into test it in the game they return to the default tiles. I know for a fact that im doing it correctly cause i went an tested it with a new project with without any other scripts, and it worked fine. I then tested it with every script individually, without problems till i tried it with this one. I have no idea what the conflict would be. Just thought i'd bring it, not even sure if its something that can be fixed.