Defold Free Course: Make Your First Game

Want more Defold content? Explore the Defold Game Development Academy where you can find a comprehensive, project-based learning pathway on it!

Ready to start building your old games? In this Defold free course, we’re diving into the setup and functionality of the Defold Engine, a powerful tool for creating 2D games.

Throughout this guide, we’ll cover everything from installing Defold to getting comfortable with its interface, creating your first project, and exploring the essential building blocks like collections, game objects, and components. By the end, you’ll have a solid foundation in Defold’s features and be ready to bring your game ideas to life.

You can also explore our full Defold course, Learn Game Development with Defold from Scratch, which covers Defold even more in-depth.

To follow along, it’s recommended that you have a basic understanding of game development and familiarity with 2D game design concepts. We’ll guide you step-by-step through each part, making sure you have all the resources you need.

Project Files

For convenience, we’ve included a set of asset project files used in this Defold free course. Feel free to download these resources to follow along and experiment as you learn the Defold Engine.

Download project files here: Defold free course assets

CTA Small Image - Defold Free Course: Make Your First Game
FREE COURSES AT ZENVA
LEARN GAME DEVELOPMENT, PYTHON AND MORE
ACCESS FOR FREE
AVAILABLE FOR A LIMITED TIME ONLY

Installing Defold

To start this Defold free course, we will guide you through the process of installing the Defold Engine on your computer. The Defold Engine is a crucial tool for game development. Regardless of the operating system you are using, the installation process is pretty straightforward and similar.

Downloading the Defold Engine

Firstly, you need to download the Defold Engine. Here is a step-by-step guide on how to do it:

  1. Go to the Defold Engine’s official website, which is defold.com.
  2. Once you’re on the website, navigate to the top right corner and click on the “Download” button.
  3. You will be redirected to the download page where you can select the version of the Defold Engine that suits your operating system.
  4. If you are using a Windows computer, click on the blue “Download for Windows” button. If you are using a Mac, click on the “Download for Mac” button. For Linux users, click on the “Download for Linux” button. The Defold Engine is also available on Steam for installation.

Installing the Defold Engine

After successfully downloading the Defold Engine, the next step is to install it. Here is how you can do it:

  1. You should find a zip file in your downloads folder. Extract this zip file to any location on your computer where you want to store the engine. This could be your desktop, your documents, or your program files.
  2. Once you’ve extracted the zip file, you should see a folder named “defold” which contains the engine.
  3. Inside the “defold” folder, you will find four different files: a folder, a file, an executable, and a logo file.
  4. To launch the engine, double click on the “defold” executable file. This will open up the Defold Engine and you can start using it for your game development projects.

And that’s it! You have successfully installed the Defold Engine on your computer.

Creating a New Project

For the next part of our Defold free course, we will be introducing you to the basics of setting up your first Defold project. This is an essential step to start your journey in game development. We will be using the Defold engine’s launcher or hub to manage and create our projects.

Understanding the Defold Launcher

The Defold launcher is a crucial tool in managing your game development projects. It provides a central place where you can preview, create, and manage all your existing projects. This is especially useful when you’re working on multiple projects simultaneously.

Creating a New Project

To create a new project, follow these steps:

  1. Open the Defold launcher.
  2. On the left-hand side, click on the ‘New Project’ button.
  3. This will take you to a new screen with three tabs: ‘From Template’, ‘From Tutorial’, and ‘From Sample’.

Understanding the Three Tabs

  • From Template: This tab provides various templates such as an empty project, mobile game, desktop game, etc. These templates serve as starting points for your new project.
  • From Tutorial: Here, you can find a range of tutorials created by the Defold team. These tutorials can guide you through specific aspects of game development.
  • From Sample: This tab contains a collection of sample projects. These projects can be helpful if you want to understand how certain features or mechanics are implemented in a game.

Starting with an Empty Project

For beginners, it’s recommended to start with an empty project. This will serve as a blank slate, and you can fill everything in as you progress (which is what we’ll be doing in this Defold free course).

Naming and Storing Your Project

After selecting your project type, you need to provide a name for your project and choose a location to store it on your computer. This can be done at the bottom of the screen. You can choose any name and location as per your preference.

Creating the Project

Once you have filled in the necessary details, click on the ‘Create New Project’ button. This will take you to the Defold editor where you can start working on your project.

Exploring the Defold Editor

The Defold editor is where you will be spending most of your time developing your game. It has various features and functionalities that we will cover in the next lesson. By the end of this Defold free course, you should be comfortable using the engine and have a good understanding of how to use it.

Feel like you need some extra guidance? Our Defold Game Development Academy is ready to help with more in-depth video content, interactive activities, and more!

Editor Overview

Welcome to the next part of our Defold free course. Now that we have everything installed, we’ll start taking a look into the Defold editor. In this way, we can understand the tools Defold offers us to make our games.

The Layout of Defold

Defold is broken up into several editor panes or panels. Below is a brief overview of each:

  • Assets Panel: Located on the left side, this panel lists all the different files in your project, similar to a file explorer. Here, you’ll store and access all your game’s assets such as sprites, scripts, audio effects and textures.
  • Changed Files: This panel shows the files you’ve modified. It’s mainly used if you’re using Git Source Control.
  • Editor Pane: This is the large panel in the middle that shows the current file you’re editing. You can switch between different files by clicking the tabs at the top of this pane.
  • Outline Panel: Located on the top right side, this panel shows the contents of the file you’re currently editing. As you add objects and components to your file, this panel will start to fill out.
  • Properties Panel: This panel displays the properties of your currently selected item. You can adjust properties such as position, rotation, texture, and direction here.
  • Tools Panel: Located at the bottom, this panel contains miscellaneous tools. The console tab is particularly useful for identifying error messages.

Using the Editor Pane

Let’s take a closer look at the Editor Pane. When you open a file in the Assets Panel, it will appear in the Editor Pane. For example, if you double-click on the main.collection file in the Assets Panel, you can start editing your game in the Editor Pane.

// To switch between files in the Editor Pane
// Click on the file tab at the top of the pane

Using the Outline and Properties Panels

The Outline Panel and Properties Panel work together to help you manage your game’s components. In the Outline Panel, you can see a list of all the items in your currently selected file. When you click on an item, its properties will appear in the Properties Panel, where you can modify them as needed.

Using the Tools Panel

The Tools Panel is a collection of miscellaneous tools. The console tab is particularly useful as it displays error messages, helping you identify and fix issues with your game. Other tabs like the curve editor, build areas, and search results can be explored as you become more familiar with Defold.

In conclusion, understanding the layout and functionality of Defold’s default editor is the first step towards creating your game.

Building Blocks – Part 1

In this next part of our Defold free course, we will explore the building blocks of Defold games. These include three primary elements: collections, game objects, and components. Understanding these elements is crucial before we begin to develop our games. Let’s break down each of these elements and understand their role in game development.

Collections

A collection is essentially a file that can contain objects and other collections. Think of collections as levels or scenes in your game. For instance, you might have a collection for the main menu, one for level one, and another for level two. The collection for the main menu might be loaded first, and when the player clicks the play button, the game would unload the menu collection and load in the level one collection. Each collection holds all game objects for that specific level or scene.

Game Objects

Game objects are the entities in your games. They are the elements that fill your levels and scenes. A game object has a position, rotation, and scale, which allows you to move them around, rotate them, and scale them in your game. Game objects also contain components which give them functionality and substance. Without components, game objects are merely floating points in space. Game objects can represent players, enemies, pickups like health packs or coins, and obstacles.

Components

Components are what give substance to our game objects. They provide logic to your game objects. Without components, a game object doesn’t really exist – it’s just there in memory without any substance, visuals, or logic. Components can be sprites, colliders, scripts, sound effects, particle effects, and more. They can be attached to game objects to give them specific purposes and mechanics in a game. A game object can have as many components as it needs to function.

Collection
  Game Object
    Component (Script)
    Component (Collider)
    Component (Sprite)

For instance, consider a ‘B’ game object. The ‘B’ game object on its own doesn’t mean much. It starts to make sense when we attach components to it. In this case, it has a script component that gives it logic to move around and collide, a collision component that allows it to physically exist in the game space, and a sprite that allows us to see it on the screen.

These are the fundamental building blocks of the Defold game engine.

Building Blocks – Part 2

In this section of our Defold free course, we will continue to explore the fundamental building blocks of Defold. We will delve further into the creation and usage of collections, game objects, and components within the game engine.

Collections

A collection in Defold is akin to a scene in other game engines. It is essentially a grouping of game objects. Collections can serve as levels in your game. For instance, you might have a collection for the menu, which contains your user interface (UI), and another collection for level one, which houses your player, enemies, and level geometry. The process continues for subsequent levels.

When you create a new empty Defold project, a main.collection collection is available by Defold. You can locate this by navigating to the assets and opening the main folder. Inside the main folder, you will find the main.collection. Double-clicking on it opens up the collection.

Game Objects

Game objects are the basic building blocks of your game. To create a game object, right-click on the collection in the outline pane and select ‘add game object’. The newly created game object is added to the outline list and assigned a Defold name of ‘Go’. The properties pane provides details such as the ID, the URL, and its position, rotation, and scale inside the game space. Game objects can be moved, rotated, and scaled within the game space.

Components

A game object is essentially a container for components. Without components, a game object doesn’t really exist. Components add functionality and logic to game objects. Different game objects have different components. For instance, a player will have different components than an enemy.

To add components to a game object, right-click on it and navigate to ‘add component’. You will be presented with a list of different components that can be added to the game object, such as camera, collection factory, collisions, labels, meshes, models, sounds, sprites, and more. Selecting a component adds it to the game object.

Renaming Game Objects and Components

Game objects and components can be renamed by selecting them and changing the ID in the properties pane. The URL is similar to a web URL and serves as an address for a specific item within a collection.

Parent-Child Relationship in Game Objects

Game objects can have a parent-child relationship. A game object can be made a child of another game object by dragging it inside the parent game object. This means that wherever the parent game object goes, the child game object goes with it.

In the next part of our Defold free course, we will be importing some sprites and setting them up to use inside our game. This will give us a visual representation of our game objects and components.

Looking for more instruction on working with Defold? Try out the Defold Game Development Academy for more instruction on the fundamentals of Defold!

Sprite Setup

For this part of our Defold free course, we will learn about importing sprites and setting them up for use in our game using the Defold game engine. Before we dive deeper into the engine features and explore game objects and components, it is essential to have a visual element that we can add to our game. This is where sprites come into play.

Importing Sprites

In the downloadable zip file containing the assets for this Defold free course (featured above), you will find a sprites folder containing two sprites: a coin and a player.

Let’s start by creating a new folder in the assets pane of the Defold engine. This folder will contain our assets. Right-click on the root folder and create a new folder named ‘assets’. An asset can be anything added to the game, such as a texture, a sprite, a script, or a sound effect. Any file or piece of data that you want to add to your game files should go in this ‘assets’ folder.

To further categorize the assets, create another folder inside the ‘assets’ folder and name it ‘sprites’. You can then drag the coin and player sprites into this ‘sprites’ folder. Once again, you can find these Defold free course assets above.

Creating a Game Object with a Sprite Component

Now, let’s create a new game object with a sprite component. To do this, right-click on the ‘collection’ in the outline pane and add a new game object. Name this object ‘player’. You will then need to attach a sprite component to this player so that it can render a sprite. To do this, right-click on the player, add a component, and select ‘sprite’.

However, you might notice that you are unable to use the PNGs directly. This is because Defold needs to know what you intend to do with these files. For instance, you might want to use them as sprites or textures. To specify this, we need to create what is known as a ‘sprite atlas’.

Creating a Sprite Atlas

A sprite atlas is essentially a large image containing different sprites. Right-click on the ‘sprites’ folder in the assets pane, select ‘new’, and then choose ‘atlas’. Name this atlas ‘sprites_atlas’ and create it.

After creating the atlas, you need to add images to it. Right-click on the atlas in the outline and select ‘add images’. Choose the coin and player images to add them to the atlas. You can then save the atlas by pressing ‘Ctrl + S’ on your keyboard.

Using the Sprite Atlas

After saving the atlas, go back to the main collection and select the sprite component. In the properties, select the ‘image’ property and click on the three little dots to open the select resource window. Choose the sprite atlas you just created.

You then need to choose which sprites from this atlas you want to use. In the properties, find the ‘default animation’ property and choose either ‘coin’ or ‘player’. Here, we’ll select ‘player’.

Rendering Pixel Art

If you’re using pixel art, you might notice that it appears blurry. This is due to the default bilinear filtering in Defold, which makes the pixels smoothly transition between each other. This is great for HD sprites but not for pixel art.

To make pixel art look crisp, you need to change the project settings. Find the ‘game.project’ file in the assets pane and open it. In the project settings, find the ‘runtime’ category and go to ‘graphics’. Change the ‘default texture min filter’ from ‘linear’ to ‘nearest’. Save these settings and go back to the main collection. You should now see that your pixel art looks much better.

Move, Rotate, and Scale – Part 1

In this next part of our Defold free course, we will explore how to move, rotate, and scale objects in Defold. These are essential tools that you will use frequently when creating games in Defold. Let’s get started.

Selecting and Moving GameObjects

To begin, select your GameObject. This can be done by clicking on it in the outline or directly in the editor pane window. You’ll notice a tool appears over your selected GameObject. This is the Move Tool. You can find a list of tools in the top right corner of the Editor pane, including the Move Tool, Rotate Tool, and Scale Tool. These tools can also be accessed by keyboard shortcuts: W for Move, E for Rotate, and R for Scale.

The Move Tool has a green arrow pointing up and a red arrow pointing right. These arrows allow you to move the GameObject along the X and Y axes. In a 2D game, X is horizontal and Y is vertical. By clicking and dragging on the arrows, you can move your object left and right or up and down.

As you move your GameObject, you’ll see the position property (X, Y, and Z) in the properties pane change accordingly. For 2D games, Z is not used and can be ignored. You can manually set the position by changing the X and Y values in the properties pane.

Rotating GameObjects

Next, let’s look at the Rotate Tool. This can be accessed by clicking the rotate icon in the top right corner of the editor or by pressing E on your keyboard. The Rotate Tool allows you to rotate your object around the X, Y, and Z axes. However, in 2D games, you’ll usually only want to rotate along the Z axis. This can be done by clicking and dragging on the outer circle of the Rotate Tool. You can also manually set the rotation by entering a degree value in the properties pane.

Scaling GameObjects

Finally, let’s discuss the Scale Tool, which can be accessed by clicking the scale icon in the top right corner of the editor or by pressing R on your keyboard. The Scale Tool allows you to resize your GameObject along the X and Y axes. You can also uniformly scale your object by clicking and dragging on the central blue square. The scale is not measured in pixels or degrees, but in multiples of the object’s original size. For example, a scale of 2 would make the object twice its original size, while a scale of 0.5 would make it half its original size.

As a practice exercise, try copying and pasting your player GameObject several times and then move, rotate, and scale the copies. This will help you get comfortable with these tools and their functions.

Remember, mastering these tools is fundamental to creating games in Defold – so make sure to master these using this Defold free course.

Move, Rotate, and Scale – Part 2

In this final part of our Defold free course, we will be exploring additional tricks for how to manipulate game objects within the engine. This is a fundamental skill that you will use frequently throughout your game development journey even beyond this Defold free course.

Copying Game Objects

Firstly, let’s start with copying game objects. This is a handy tool when you want to create multiple instances of the same object. To do this, simply select the game object you wish to copy, press Control + C to copy it, and then Control + V to paste it. The engine will automatically create a new game object with the name “player1” to differentiate it from the original object.

Rotating Game Objects

Next, we’ll look at how to rotate game objects. In our example, we want to rotate our copied game object 180 degrees along the Z-axis. While you can manually rotate the object using the rotate tool, a more precise method is to modify the rotation property in the properties panel. For a 180-degree rotation, simply set the Z value under rotation to 180.

Scaling Game Objects

Scaling is another crucial tool that lets us adjust the size of our game objects. To do this, select the game object you wish to scale and press R to activate the scale tool. You can then adjust the size of the object to your liking.

Positioning Game Objects

Lastly, we’ll cover how to position game objects. After you’ve copied, rotated, and scaled your game object, you can move it to the desired location in your game scene. Simply select the game object and drag it to where you want it to be.

In summary, copying, rotating, scaling, and positioning game objects are fundamental skills that you’ll use frequently in game development. Practice using these tools to design your game levels and layouts exactly how you want them to be.

Defold First Game Wrap-Up

Congratulations on completing this Defold free course! You’ve now successfully set up the Defold Engine, explored its interface, and learned to create and organize game elements like collections, game objects, and components. With these fundamentals in place, you’re ready to start developing your own 2D games in Defold.

To continue building your skills, consider experimenting with additional features like sprite animations, collisions, and scripting to bring more depth to your projects. You can also check out Zenva’s Defold Game Development Academy for further guidance on making different kinds of projects with Defold.

Happy game developing, and best of luck with your future projects!

Get industry-ready with the Defold Game Development Academy! Perfectly suited to any skill level, you’ll get the tools you need to succeed while building a slew of projects!

Did you come across any errors in this tutorial? Please let us know by completing this form and we’ll look into it!

FREE COURSES
Python Blog Image - Defold Free Course: Make Your First Game

FINAL DAYS: Unlock coding courses in Unity, Godot, Unreal, Python and more.