Help with drop shadow without plugins

Not favoritedFavorited Favorited 0 favourites
  • 7 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I would like to find a way to recreate the Shadow Light/Shadow Caster effect without the shadow being drawn from the base of the object. Something like this:

    I was thinking of maybe duplicating all the objects on the object layer to the shadow layer (with layer effects), pinning the shadows to the original objects and offsetting the shadows 15 pixels opposite of the direction of the LightSource Sprite every tick, but I have no idea how to begin to do this. Can I even pin a copy of a sprite to itself? Maybe with UID, but then how would I know what that UID would be?

    Here's how I have the layers set up:

    DropShadowIdea.c3p

  • Here's one way to do it that's basically what you described:

    dropbox.com/scl/fi/lfmr9x6woehinwv3unnsf/dropshadow_idea.c3p

    The meat of it is the instances are duplicated and placed on the shadow layer. Then to position the shadow you need to access the position (xy) of the instance it was copied from and then you position the shadow with:

    set position to x+(x-light.x)*0.1, y+(y-light.y)*0.1

    The way I handled pairing the instance duplicates is by storing the uid of the shadow instance in the original instance then doing some picking juggling. There are probably other strategies with various pros and cons.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here's one way to do it that's basically what you described:

    https://www.dropbox.com/scl/fi/lfmr9x6woehinwv3unnsf/dropshadow_idea.c3p?rlkey=5dg9g6cl1u8qrd34f20rfwkfw&st=o9tf4aop

    The meat of it is the instances are duplicated and placed on the shadow layer. Then to position the shadow you need to access the position (xy) of the instance it was copied from and then you position the shadow with:

    set position to x+(x-light.x)*0.1, y+(y-light.y)*0.1

    The way I handled pairing the instance duplicates is by storing the uid of the shadow instance in the original instance then doing some picking juggling. There are probably other strategies with various pros and cons.

    This is great! There's a lot I can learn from this. Thank you for demonstrating how to do it. But why doesn't it work with Families? Isn't it still asking for the UID of the family member, except maybe it's not because it's assigning the shadows wrong. The Family as a whole doesn't have a UID, does it? How can I fix this to work with Families?

    FamilyDropShadow.c3p

  • When you create a family instance it just randomly chooses one of the object types in the family and creates an instance from that.

    So to actually duplicate objects in a family you’d probably need to just copy the first two events multiple times and handle each object type in the family specifically. That or just use different animations of one type instead of families.

  • Squibble

    That's a very interesting question.

    By using the same object for the shadow, we save a lot of space. But in doing so, we make our code a little more complicated.

    However, if we set up the shadow system once using functions, that allows us to reuse it in different parts of the game later on.

    I do this kind of thing using an array because Construct 3 works with them very quickly and they have very low overhead.

    Plus, debugging is very simple and straightforward, as shown in the screenshot.

    Here’s a simple example.

    fex.net/uk/s/0tmc2pt

  • When you create a family instance it just randomly chooses one of the object types in the family and creates an instance from that.

    I'm not really asking you this, just questioning it out loud, but why is it random? I'm asking C3 to create a duplicate "For Each" member of the family. The order it chooses the objects should be the order the duplicates are created. That way they would match up. If I wanted it to be random, then I would ask C3 to make it random.

    So to actually duplicate objects in a family you’d probably need to just copy the first two events multiple times and handle each object type in the family specifically. That or just use different animations of one type instead of families.

    But that's not very efficient if you have 30+ objects. Again, not your problem, but isn't the purpose of Families is to avoid repeating events?

    Maybe I missed it, but I didn't read in the manual about anything added to a family being random, and it kinda defeats the purpose. The event sheet reads from top to bottom in order. Why doesn't that same logic apply to objects in Families?

    igortyhon You are a genius! Very creative to use arrays. I love it when you reply to my questions, because you'll have a creative solution and an explanation of how it works. I don't know why you, R0J0hound, and others hang around these for forums to help noobs like me, but I'm very grateful. Thank you!

    Btw, do you have a YouTube channel where you walk viewers through your thought process?

  • ...

    igortyhon You are a genius! Very creative to use arrays. I love it when you reply to my questions, because you'll have a creative solution and an explanation of how it works. I don't know why you, R0J0hound, and others hang around these for forums to help noobs like me, but I'm very grateful. Thank you!

    Btw, do you have a YouTube channel where you walk viewers through your thought process?

    When I'm making a game and start by designing mechanics and testing prototypes, it's fun. But then I have to add content, and that can get boring- that's when I get distracted by drawing or the forum.

    People sometimes ask questions there that are interesting to answer.

    I agree with you- this guy R0J0hound gives really great mathematical answers. I’ve saved a lot of his formulas for myself!

    Thanks for your feedback.

    I’m not making video content right now.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)