Shadow Generator

by Kidpaddle45
A little system that generates shadows for selected objects in your game.
ID:1856900
 
For those who are wondering how shadow generator works and can't seem to understand the "Shadow Generator.dm" file. Here is a quick simple explanation.

I use an icon called "shadow.dmi". This icon is a black 32x32 square.
I use Scale()and Width() and Height() to resize it to be the same size as whatever object that needs a shadow. In this example we'll use the tree.

I use the Blend() proc to fuse the new resized rectangle shadow to with our tree.

I then, Rotate it and apply some pixel offsets.

Here is a small picture. For the visuals! ;)

Tuto

Alternatively, you can set the color of the shadow to "black" and give it the same exact icon as the object. No icon procs necessary here!
It's also kinda limited if you have underlays removed or icon states changed like a Player flying, you would have to generate the shadow again for that particular move.

But I really like it so far. xD
In response to Zasif
Kaiochao wrote:
Alternatively, you can set the color of the shadow to "black" and give it the same exact icon as the object. No icon procs necessary here!

You know how to make me feel stupid! :P
Thanks! :)

Zasif wrote:
It's also kinda limited if you have underlays removed or icon states changed like a Player flying, you would have to generate the shadow again for that particular move. But I really like it so far. xD

Thanks!! It was actually more meant for generating shadows for turfs and objects but I do plan on finding the best solution and way for it to update on players with overlays as well. Suggestions would be appreciated! ;)
All you need to do to obtain the same result is multiplying the icon by the black color code in HTML (#000000 or w.e.). No need to use any other icon.
You'll want to add an extra step.

Precache the generated shadows and save them and then instead of generating the shadows, check first to see if there's a pre-generated shadow. If there is, reference that. If there isn't, generate a new shadow and save the results.
In regards to making the mob shadows match player movements you could just duplicate the player's icon, current overlays and blend them into a single icon. Then make that icon solid black.

I don't make the icon solid black in my game but for players it does have the states and overlays attached.

It basically functions like any other overlay/underlay would in that instance.





Nice work btw.
To copy the appearance of the player, you can use image(icon = player) to get an image. Note that the player object is the initial icon in the image proc; check the DM Reference for details. Also, in the upcoming BYOND version there's a new appearance var that won't really make this thing any easier but who knows?
In response to Kaiochao
That makes things a bit simpler, I was unaware you could just sub the entire atom in and get a duplicate image of it.

Does that solve the issue of the states though? Using images and icon states sometimes causes visual errors, simply because images can't be flicked. That's why I ended up using the icon file instead of an image.
In response to Avidanimefan
I imagine that since you'd be adding the image as an underlay, it'd flick like any other overlay that has the same icon states as the base object. Or does that not happen? I haven't really checked recently.
In response to Kaiochao
I can't say for sure it's been some months since I've actually set up the shadows for my game.

I remember expressly thinking, I'll just use images,because other players don't "really" need to see one another's shadows.

I also aimed at using it because it would be more simple to get the visual effect.

After about 1-2 hours trying to get it to work, I realized it worked properly after just taking the base icon, blending the overlays and underlays onto the base icon, and then finally doing what I needed to make the shadow look the way I wanted.

I imagine somewhere in there I had an issue with images that made me change the way I approached it-but if it was that particular matter I can't remember.
In response to Avidanimefan
Yeah, I usually use image objects as overlays instead of as per-client images.
Ahh. I never really tried using them as overlays/ underlays as simple as it is. I always thought about the attachment feature *like attaching the image to an atom*

I may have to revisit that code and do it that way. Thanks.
Using it as a overlay/underlay its abit tricky if you have stuff that removes overlays/underlays. You would have to generate it again aftarwords.
This was mainly meant to generate shadows for the environment not for the mobs. From the comments I saw here, I got an idea on how I can achieve it. I'll see what I can do.
I may use this in Skirmish. (:
In response to Kumorii
Kumorii wrote:
I may use this in Skirmish. (:

Wohooo! Glad to hear. Keep me updated if you ever stumble uponn a glitch or a bug using it.
In response to Avidanimefan
Avidanimefan wrote:
That makes things a bit simpler, I was unaware you could just sub the entire atom in and get a duplicate image of it.

Does that solve the issue of the states though? Using images and icon states sometimes causes visual errors, simply because images can't be flicked. That's why I ended up using the icon file instead of an image.

Read my posts on appearances. Appearances are unique internal objects. You don't add objects to the overlays list, you add their appearances.
In response to Ter13
Not sure I read the post, I wrote this up almost 4 months ago though. I read something about an appearance var being added to DM soon, has that already happened or no? I was actually kind of waiting on it. It would make quite a few things easier for me with a few games.
It hasn't made it in a release yet. But appearances have always been a part of BYOND. They are an internal object that holds a unique visual look of an atom. When you add something to an overlays list, the game actually either creates an appearance for whatever data you threw at it, or it uses a reference to the appearance of the object you passed into the overlays list.

See my collected post history on the subject.
Page: 1 2