How to cast shadows that change with time

Index

Attached Files

The following files have been attached to this tutorial:

.capx

shadow-cast-2.capx

Download now 209.83 KB

Stats

2,019 visits, 4,729 views

Translations

This tutorial hasn't been translated.

Tools

What if the sprite can jump?

If your sprite can jump or fly then you have to do a little bit more maths to make the shadows convincing - height above ground, sun azimuth and sun elevation all have to be carefully considered. Luckily some close approximations will produce effects good enough for most 2D or 2.5D games.

The 8-direction movement has no jump behavior so I made a very simple one using custom movement. Each tick the robot’s height above ground is calculated with reference to a dynamic ‘jump_startY’ variable that is factored for the changes in position caused by 8-direction movement as the robot jumps. Without this, moving and jumping up the screen would cause the apparent jump height of the robot to increase and moving quickly down the screen would put the robot below its starting jump Y value - all of which would cause the shadow to be positioned incorrectly.

Conclusion

That’s it! Have a look in the capx, it contains more comments to help you understand my thought processes. I hope that you found that these ideas useful and if you have any feedback then please let me know how to make this tutorial better and I'll get on it! All I have to do now is think of a game where I can put all of this to work! Now, what about multiple light sources...

.CAPX

shadow-cast-2.capx

Download now 209.83 KB
  • 0 Comments

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