Creating a game with Godot Engine - Ep.6 - Floor and walls
In this sixth article we will talk about creating a floor and some walls. We will mostly talk about tile set and tile map. (source code)
Disclaimer: the following article represents one way to do it and, it may not be the best way. Please adapt this technique using your best judgement.
Tiles are the basis of many 2D games. They are small sprites which align on a grid of cells of equal size. The size unit for the tiles is the cell. While in many old school games tiles are always one cell in size. Nothing in Godot prevents you to spread a tile across multiple cells, both in a square or rectangle shapes.
Creating a tile set
When creating a tile set you should read first this tutorial from the official Godot documentation. Using our folder structure, the folder for each area, like floor and wall, contains a scene for the tile set, the tile set resources and the individual sprites, in addition of the element scene. If you have a large number of tiles it can be a good idea to use an AtlasTexture to have one texture for all sprites.
Creating a tile set scene is quite simple. We create a Node as root and then for each tiles, we add a Sprite2D. Then depending on the features we want for our tiles we can add:
- a StaticBody2D with a CollisionShape2D as a child for collision detection. We use this feature for the wall so the character cannot go though the tiles.
- a LightOccluder2D. We use this feature for the wall to bloc the light from the character flashlight. If your light does not appear to react to occluders, check if the shadow property of Light2D is enabled.
When you have finished setting up all the tiles, you can create the tile set resource using the Godot exporter in the Scene menu Convert to.. > TileSet... If you make a modification to the tile set scene later on, you can simply export it again and overwrite the resource.
Creating a tile map
Once the tile set is created, creating a tile map is trivial. We just have to assign the tile set resource to the tile map using the corresponding TileMap property. One thing not to forget is to set the cell size property to the correct value.
We will not talk about using the tile map now. It will be discussed when going through level creation.
What is next?
In the next article we will speak about balls, how to emit them, how to receive them and how to make them explode.
Written by Olivier on Thursday December 1, 2016comments powered by Disqus