How to cast shadows that change with time

2
  • 28 favourites

Index

Attached Files

The following files have been attached to this tutorial:

.capx

shadow-cast-2.capx

Download now 209.83 KB

Stats

4,998 visits, 9,453 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Introduction

Ok.... Events have moved on since I first wrote this tutorial. Since r170, Construct 2 has included a shadow casting behavior... Rather than delete this tutorial, however, I'll leave it here for posterity. It is possible that you might wish to investigate using the techniques included here - at the time of this revision the new shadow cast behavior cannot cast shadows over other objects on the layout. This tutorial will permit that although it is rather work intensive.

The aim of this tutorial is to show you one method of creating shadows that move and change according to the time of day and the sun's elevation. I was recently asked a question about shadow casting and, as I started to write my answer I quickly realized that the solution was quite complicated! Rather that give a quick 2-line hack of an answer I thought it more productive to write a quick tutorial (which is also my first) - I’ve enjoyed plenty of help from the community over the last few months and I think it’s time for some payback. This solution might not meet everyone's needs but I hope that the principles contained here and in the attached capx will at least provide you some useful ideas so you can go on to build a visually impressive master-piece of your own.

Download the example capx

In the example capx there's a robot you control with 8-direction movement and a few obstacles scattered about. Apart from casting shadows, not much else happens.... Once you've downloaded and opened the example capx, the rest of this tutorial will make more sense.

Assumptions

In making this shadow casting system I've had to make quite a few assumptions about how the game world functions:

1. The sun rises at 0600 and sets at 1800 (and the day is 24 hours long).

2. To avoid very long shadows at low sun elevations, there won't be any shadows until the sun is up a few degrees.

3. The arc of the sun's travel in the sky subtends 180 degrees from sunrise to sunset and the sun will not be directly overhead at noon.

4. We are in the northern hemisphere looking north, so the sun moves from right to left behind our viewpoint.

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!