Now that we know some basics of the Godot engine, we are going to create a game which does not use any of that. It is simple but the techniques and workflows differ from most of the popular game engines out there so the learning curve is somewhat steep. The only way to familiarize it is to create a game in which the focus is not on the game logic.
So we are creating a simple 2d game in Godot engine which is called “Catch the egg”. There is a basket which we can move by moving the mouse. Eggs will be dropped from the top, we have to catch the egg in the basket. This will be a multipart tutorial series and in this part we will setup our game project.
I am using Godot version 2.0.2 for this. If you are using another version, the workflow should be similar. Before we begin, I’d like to declare that this tutorial assumes you are somewhat familiar with the Godot editor. Just things like the knowledge of where are the things located is enough.
I prepared some assets for this game, you can download it from here. These are the assets we are going to use:
We are not going to bother about the sounds for now. That will be another tutorial.
Project directory setup
Godot engine documentation recommends a directory structure for our game. It makes version control easy. The engine is built around the concept of scenes, all resources a scene uses is put under its own folder. I am also taking this time to tell you that there are no good or bad ways for a project structure, there are only easy and difficult ways. You can follow any folder structure as your project seem fit. For this simple game, we are going the easy way. Create our project folder somewhere and create folders like this,
- Catch The Egg
Copy all images into the assets/image folder. Then copy a ttf font from somewhere to the assets/fonts folder. Now the project structure looks like this.
After that we can create a new project in the editor.
Setting up the project
Open Godot engine and wait for the project selection window. Create a new project and browse into our project folder. After selecting the folder, change the project name to Catch The Egg. The window will look like this.
Click ok to create the project. Then double click on the newly created project to open it.
Setting the game scene
Godot engine editor opens up and everything is empty now. We cannot save a scene without a root node. So let us create a new root node. Click the ‘Create a New Node’ button and select the Node2D from the hierarchy list. Just start typing ‘Node2D’ on the search field and it will filter elements so that we can quickly find the desired element. Click ‘Create’ button and a Node2D is added to the Scene hierachy which is show on the left. Now go to Scene/Save Scene to save the scene. We should save the scene inside the folder scenes/main by the name game.tscn.
Adding the bg
First, rename the Node2D which is shown in the panel. Let’s change it to ‘main’. Now add a new sprite node as a child of this ‘main’ node. Rename the node to ‘bg’.
Click on the bg node to select it. Now its properties is shown on the properties tab. Click on the texture field and select Load. Choose bg.png image and you can see the image on the scene editor. Tick the ‘Centered’ option to center the offset of the sprite. If we click play now, Godot shows a warning saying, we did not select a main scene. This is because, Godot doesn’t know which scene is to be started when the game starts. So we have to set it on the project settings. We also need to set some more things.
Open Scene > Project Settings. This will open up the project settings window. The options are categorized so that we can browse them easily. On the left, select the Application Category if it is not selected. Then on the right side, we can see the options. You can see a folder icon on the right side of the ‘main_scene’ property. Click on that and choose ‘File’, then browse and select our game.tscn file. Now close this and save our scene. If we hit play, we can see that the resolution is all wrong. The game is designed to work on the resolution 640×960. So we need to set that too.
Open the Project Settings again and click on the Display category. Here, you can see width and height properties. Set the width to 640 and height to 960. Set the orientation to ‘portrait’. You can close the window now and hit the play button and see the game is shown on the 640×960 resolution. If you have a laptop resolution in which the height is less than 960 you cannot see the whole game window. For that, Godot has option for test window resolution. You can open the Project Settings again and look for test_width and test_height under the Display category. Set it to a lower resolution like 320×480. If you hit Play, you can see the game now shows correctly.
This has been a long post, so I am stopping here. The next part of this will cover the camera setup and multiple display resolutions.
Thanks for reading.