2d Game Engine For Beginners

Game Engine For Beginners

Defold is a multi-platform game engine that simplifies development of 2D games for all major platforms – HTML5, Android, iOS, Windows, Mac OS X and Linux. I'm switching from Java development to C++ and feel I've learned the basics of C++ and want to test my knowledge by creating a few basic 2d games.

Let us start another Godot Engine game tutorial for beginners. This will be a multipart tutorial series where we are going to create a simple top down 2D car racing game. The goal of this tutorial is to familiarise with the concepts and the workflow of Godot Engine. Once we understand these, it is very easy to make things with it. If you don’t know, all the tutorials published in this blog were focused primarily towards mobile devices and this tutorial is no different.

The game we are making is like a highway racer where the player needs to avoid other cars on the track. We can switch the lane by tapping on either side of the screen. Create The Project Create a Godot project somewhere on your computer. After creating the project we will be greeted with the Godot Editor window. As we need to setup some parameters in the project settings, go to the Menu >Scene >Project Settings and set the properties under the Display category like below: width – 540 height – 960 test_width – 320 test_height – 480 orientation – portrait stretch_mode – 2d stretch_aspect – keep_height The test_width and test_height can be changed as we prefer because this only affect the dimensions of the Godot play mode window while editing. Now we can create our folder structure inside the project directory like this.

Project_folder /assets /images /fonts /scenes /packed /scripts Download the assets required for this project from. Now copy all the image assets into ‘assets/images’ folder. Great, project setup is done and we can create our first scene – the game scene. Setup game scene Add a Node2D to the scene and add a Sprite as its child. Rename the Node2D as ‘main’ and the Sprite as ‘bg’.

Setup the road Select the ‘bg’ node and set the ‘road.png’ texture as its texture. We can do this by clicking the option for Texture property and click the Load option. Then choose the road.png image in the assets folder. For 2d games, it is desirable to disable texture mipmaps so that our texture will look better. To do that, after choosing the texture, click on the small arrow to the right of the texture. Under the flags property, uncheck mipmaps. We are going to scroll the road texture to make the illusion of car movement, we need to check the Repeat flag also.

We can also access this texture properties by double clicking the texture inside the Filesystem tab. After setting up the texture, we need to align the road to the center of our game world. Our game dimensions is 540×960, so set the road position to 270, 480. Creating the Player Car We can add a Sprite and set the texture to display the car object. But there are some things to consider before we setup the car. The car has to collide with opponent cars.

Godot Sprite node will not collide with anything and if we want something to follow physics we need to add nodes which exhibits some physics properties. Godot has built-in support for 2d and 3d physics and there are a bunch of nodes for physics. RigidBody RigidBody enables the object to follow physics behaviours. There are two RigidBody nodes in Godot, RigidBody and RigidBody2D – for 3d and 2d respectively. The Rigidbody2D also has to know the shape of the object so that the collisions are calculated based on that shape. Create the player car like this.

The Complete Turtletrader Rapidshare on this page. The Rigidbody2D(renamed to Player) node will be the parent node for the player car, the Sprite node will display the car texture and the CollisionShape2D node will define the shape of the car. When we change the position of the RigidBody2D via script, all of its children will change their positions relatively.

For this to work as expected, we need to make sure all the children under the parent node are positioned at 0,0. Position the Player node at 270, 775 by setting the pos property of the ‘Player’ node in the inspector. Don’t try to drag the node using mouse. I will explain the problem below.

For now just set the position in inspector by typing the values. Set the Sprite’s properties as shown, Make sure you disable the mipmapping for the car texture as we did for the road texture. CollisionShape2D A CollisionShape/CollisionShape2D defines the collision shape for the parent RigidBody/RigidBody2D. Nasm Essentials Corrective Exercise Training Ebook there. You may have noticed the warning sign on the CollisionShape2D node.

This is Godot’s way of telling that the CollisionShape2D object requires a collision shape definition which is not set. It doesn’t know what shape it is – square, rectangle or a circle shape. Click on the sign and it shows this popup To set the collision shape, select the CollisionShape2D in the hierarchy. Our car is in rectangle shape so set its shape property to New RectangleShape2D. Now we need to define the bounds of the RectangleShape2D.