In this course, you will learn various expression methods using ACTION GAME MAKER.
In the second session, we will create light and shadow.
Pre-course Preparation
Continue using the project from the first session.
Please open the project and prepare accordingly.
STEP 1 Let’s Set Up PointLight2D
- Open the
game_scene tab and select ObjectRoot.
- Add a new node:
PointLight2D. Nothing will happen yet because there is no texture.
- Drag and drop
2d_lights_and_shadows_neutral_point_light.webp from the templates > other folder in the FileSystem onto the Texture property of PointLight2D in the Inspector window.
- A white light should appear. That’s basically all there is to it, but let’s go over some commonly used properties so you can experiment freely.
- Texture Scale: Allows you to change the scale of the texture.
- Color: Allows you to change the color of the light.
- Energy: Allows you to change the brightness of the light. The higher the value, the stronger the light.
- Next, let’s set up shadows. Enable the
Enabled property under Shadow. This alone activates shadow processing. Since the sample tiles and characters are already configured to cast shadows by default, moving the PointLight2D closer should cause shadows to appear.
- In the next STEP, we will explain how to create shadows.
Explanation
About Texture
In this tutorial, we created a normal circular light, but you can create any shape you like. For example, using a fan-shaped texture will produce a flashlight-like beam.
Textures must be in black and white, with black areas becoming transparent, so feel free to create your own.
Using AnimationPlayer
The properties introduced here, such as Color, Scale, and Energy, can be used as keyframes in the AnimationPlayer, allowing you to create animations like flickering lights. The AnimationPlayer is covered in the Graphics course.
STEP2: Create a Collision for Shadows (LightOccluder2D).
- To generate shadows, you need to separately configure a Collision for Shadows (LightOccluder2D). Let’s add a LightOccluder2D to the sample object.
- Open Decoration_Statue.tscn for sampleobject.
- Add a LightOccluder2D node.
- Create a new OccluderPolygon2D in the Inspector.
- Select the Point Creation Tool in the toolbar at the top of the editor window and create a polygon inside the statue. While you can create complex shapes, they increase processing load, so we recommend starting with a simple shape.
- Try placing Decoration_Statue.tscn within the light range created in STEP1. A shadow should be generated along the polygon’s shape.
Explanation
Unnatural Shadow Appearance
The issue might be resolved by changing the CullMode of OccluderPolygon2D to Clockwise or Counter-Clockwise. If you placed the points clockwise, try Clockwise; if counter-clockwise, try Counter-Clockwise.
Want More Detailed Shadows
You can make shadows finer by adjusting settings on the PointLight2D side. Try changing the Filter property of Shadow from None (Fast) to PCF5 or PCF13. This will make the shadows softer and more detailed, but note that it increases processing load.
Adding Shadows to Tiles
If you want to add shadows to tiles, you can select them in the TileSet settings and configure the tile polygons under Rendering > Occlusion Layer.
Note that in ACTION GAME MAKER, Occlusion Layer is automatically configured when loading in AutoTile format, so no additional settings are required for AutoTiles.