How to cast shadows

0 favourites
  • 9 posts
  • Dear community,

    I'm not sure if this is the done thing... May I humbly present my Shadow Casting Tutorial link. I hope you enjoy it and that you might find it useful.


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Great!

  • hahahahahaha, what the hell <img src="smileys/smiley1.gif" border="0" align="middle" />,

    Don't get angry I am laughing on myself, because you know what , when I read you topic "How to cast shadows" I was thinking to reply that for now it's not supported fully in C2 and we have to like make it fake or something like that. But when I get into that link of yours, I was like WOW and got shocked, and then I start laughing on myself , hahahaha.

    Thanks for sharing and making such a great tutorial.

  • Thank you very much for the kind comments! I got a bit bored this morning (jet lag playing havoc) and I needed a break from tinkering with one of my projects.

  • Shadows add on top of each other, should fix that.

    Still not a bad idea, even though objects are not affected by shadows. If your object doesn't have a C(infinity) rotational axis along their vertical middle axis, shadows will be deformed. Simple shadows should be doable without problems though, as you show.

    In the end I think if someone wants dynamic lightning, they should just stick with a 3D solution.

  • Yeah, of course shadows with < 100 opacity will always add to each other if they overlap. I can't think of an easy way to improve on the current simple demo/tutorial without creating other problems or failings (with my limited skills, of course). Is there an easy fix you can think of or that you are hinting at when you say "should fix that" mindfaQ - any suggestions would be appreciated?

    Before writing the tutorial I had a good look at Pode's 2D Dynamic Lighting: but it doesn't produce shadows as far as I understand (and I'm happy to be corrected) and it requires the use of a 3rd party plugin (unsupported by Scirra in the event of an update causing a crash) and it requires the use of additional software that, as a hobbyist, I'm not familiar with nor inclined to learn how to use (I?m still learning how to use C2 when I?m not distracted by my day job).

    Thinking as I type - I suppose if the ground had a uniform fill colour with no texture effect then each shadow could be made from a darker shade of the ground's colour. Then shadow overlaps would not affect each other. However, that solution would obliterate any ground texture and, therefore, would be a viable alternative but with a huge trade off. Also, in situations with diffuse lighting in the real world, shadows can overlap and 'add' together - they are rarely exactly the same shape as the casting object unless you are very low to the ground... The same applies to situations with multiple light sources.

    When you mention that this only strictly applies to objects with a rotational symmetry about the z axis - I agree, the tutorial only demonstrates shadows cast by such objects. If you want to create complex shadow casting objects then I can?t think of an easy way to do it in C2, the only (and long) way I can think of would be to create a LOT of differently shaped shadow sprites and then select the appropriate one according to sun position and object angle. However, although I haven?t tried it, I imagine that you?d be on a hiding to nothing because it would be very hard to implement and still wouldn?t be as good as anything Unity could produce.

    I agree with your last comment: if you want a realistic 3D shading solution for your game, don?t use C2! But we?ve got to struggle on with the tools available...

  • Shadows add on top of each other, should fix that./QUOTE]

    Easy fix.

    In the events, it's set up to change the transparency to 40%. Remove that.

    Go to the Shadow layer, and change the layer transparency to 40%.

    Problem solved.

    Unfortunately, with this it makes it harder to allow the shadows to appear on top of objects, otherwise you could also add in an event that detects if the robot is lower than the object, and have that shadow move to a higher layer.

  • AnD4D,

    Every day is a school day - and thank you for the help. I'll have a look at the easy fix now and update the tutorial - it didn't occur to me to manage the transparency that way (clever - I like it). The multi-layer option for shadow casting over other objects will require some thought on my part but it sounds good...


  • OK, I've updated the capx and tutorial. Now you can select one of 2 groups in the capx. The first puts the shadows onto a separate and lower layer that has its opacity set as suggested by AnD4D (no darkening of shadows on overlap, but the shadows don't cast onto other objects). The second option group (enabled on capx download) puts all shadows and objects onto the same layer and order their z position according to y position so that the shadows do cast onto objects that are apparently underneath them. It's not perfect but much better, I think - thanks for the ideas.

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