Creating shadows with layers
Layers are a feature of Flame that allow us to group things we want to draw together or draw a prerendered graphic that doesn't change much. In your game, you may have a background that you draw once from a combination of sprites or images, but then it is used as a static image that you use as a background and draw the other moving sprites on top.
It would be inefficient to keep creating this background if it isn't changing. So, you can create it once and store it as a layer, which you can draw before you render the other game graphics.
In Flame, there are two types of layers:
PreRenderedLayer
– For static imagesDynamicLayer
– For things that are moving
PreRenderedLayer
would be suitable for backgrounds due to its static nature.
You may also want to change something in the layer and regenerate the layer, and then cache the resulting image in the layer. For example, you may want to create a weather effect...