Skip to content

Commit

Permalink
Resolve #1. Document RenderTypes in the environment introduction.
Browse files Browse the repository at this point in the history
  • Loading branch information
nightm4re94 committed Nov 29, 2020
1 parent bde1b4d commit 1e93c32
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions game-api/game-world.md
Expand Up @@ -2,7 +2,7 @@

## Introduction to Environments

Every game engine needs a container that holds all the visual and non-visual things that will, in the end, make up the game world. This container is called `Environment` in the LITIENGINE. Only one Environment is loaded at a time and the Game holds the currently active Environment. Every time you want to position something within the two-dimensional space of your game, you can do so by adding it to the Environment. When the active Screen calls the `Environment.render(Graphics2D)` method, it’s internal rendering pipeline is executed which will render everything that was previously added/loaded to the environment. There are different render types (`BACKGROUND`, `OVERLAY`, …) that define in which order the objects will be rendered, but more on that topic in a later tutorial.
Every game engine needs a container that holds all the visual and non-visual things that will, in the end, make up the game world. This container is called `Environment` in the LITIENGINE. Only one Environment is loaded at a time and the Game holds the currently active Environment. Every time you want to position something within the two-dimensional space of your game, you can do so by adding it to the Environment.

It’s important to point out, that the Environment is related to exactly one Map and that the LITIENGINE provides an interface to load MapObjects to the environment. The implementations that take care of this task are called MapObjectLoaders. They basically translate the information form the *.tmx map* format to objects that can be managed by the engine.

Expand All @@ -29,4 +29,19 @@ Game.world().environment().addEntityListener(new EnvironmentEntityListener(){
// do sth when entities are added
}
});
```
```
### Layering
When the active Screen calls the `Environment.render(Graphics2D)` method, its internal rendering pipeline is executed which will render everything that was previously added/loaded to the environment. There are different `RenderType`s that define in which order the objects and tile layers will be rendered. Think of the `RenderType`s as layers that are painted on our canvas one after another.

The rendering order is as follows:

`BACKGROUND` -> `GROUND` -> `SURFACE` -> `NORMAL` -> (static shadows) -> `OVERLAY` -> (ambient light) -> `UI`

Internally, the Environment.render method does the following for every `RenderType` (besides `RenderType.NONE`, which can, for example, be used to make objects invisible temporarily):

1. Render all Map Layers of that type
2. Render all registered `IRenderable` implementations of that type
3. Render all added `IEntities` of that type
4. Call-back on the `EnvironmentRenderListener.rendered` listeners for that type
5. If `dbg_logDetailedRenderTimes = true`: track the time it took to execute the rendering

0 comments on commit 1e93c32

Please sign in to comment.