Godot: Level Design and Adding a Camera Object
This is Part 3 of the Godot series. Part 1 and Part 2 are here.
In this post, we will start designing our level. All the code is here, under Part 3.
To start off, go ahead and delete the temporary "ground" we created:
On Level1, press + and add a new scene for TileMap:
Now, select the Tilemap you created, and on the right, choose New Tileset:
And then click on the Tileset you just created:
Go ahead and save the tileset you created:
Now, drag the platformPack_tilset.png file to the tileset area you created:
Now we are going to create our tiles.
An aside: You might be wondering why we are creating a tileset, when we could just have dragged individual images? The advantage is: Once we define the tiles and collision area, we can reuse them multiple times, and for complicated designs, it's actually faster to do this first
Lets create our 1st tile. Click on New Single Tile
and click enable snap:
This will ensure we can select on tile boundaries.
We now need to do 2 things: Select the tile, and set collision region. The collision region is to show where the player can hit the tile, which for us is the whole tile.
You have to select the region 1st, and then the Collision tab shows up.
In the region, select the green tile.
In the collision tab, select rectangle, and then select the green tile again.
Let's do the same for the wavy white tile:
Remember to save.
How do we use these tiles?
Click on TileMap, and you will see the new tiles you created.
Now you can just left click a tile and select it, and lay it out. To remove a tile, right click.
Create a simple map using the 2 tiles we have:
And you can even click play and play with the new level we created:
Awesome. Go ahead and create a small level with the slides we have. Here's mine:
You will see the level is bigger than our screen (marked by the red arrows above).
I had to increase jump speed to 700 to jump high enough. Currently, when I go out of the screen, the player "vanishes"
Why is that? It's because the player goes off screen. We need to follow the player as it goes off the screen. We will do that with the camera.
Adding a Camera
Open the player scene, either by double clicking the player.tscn file, or clicking the open scene button:
On player, add a new code for Camera2d:
Make sure in the right window you select current to True:
Play the game and the camera should follow the player now:
One problem above: If we fall below the platform, we keep falling. Let's fix that in the next part.