Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

5. July 2016

 

In the previous tutorial we covered installing the Defold Engine and creating your first project.  Today we are going to be looking at the overall structure of a Defold game, as it varies slightly from previous game engines.  I assume at this point you’ve followed the previous tutorial, created an empty project and have it open in the Defold editor.

 

There is an HD video of this tutorial available here.

 

The default project should look something like:

image

 

The built-ins folder is exactly that.  It contains several resources and scripts usable in your game, but we will talk about that later.  The more important thing to be aware of here is the main folder and it’s contents.

Inside this folder we find main.collection, logo.atlas and a folder containing an image.  A collection is a very important concept in Defold.  In this particular usage, you can think of a collection as a level.  If we double click main.collection for example it will open up a scene editor, like so:

image

 

A collection isn’t simply a level however...  what it is is a container for game objects or other collections.  We will look at game objects in a second.  So yes, Collections can be used to compose game levels, but they have other purposes.  The also perform the role of “prefabs” in other engines.  For example you might have a prefab for an enemy, that contained the scripts controlling it, the graphics you used to draw it, the sounds it plays, etc.  This collection can then be used to “instance” a version of your prefab one or more times.

 

A moment ago I mentioned Game Objects.  This is another cornerstone to understanding Defold.  With main.collection open in the editor, you should see in the Outliner, the following:

image

 

You can see here that our collection (main.collection) contains a single Game Object named go, which in turn contains a single component sprite.  You’ll notice with sprite selected that the Properties show our sprite comes from /main/logo.atlas and uses the animation or image named logo and renders using the built in material sprite.material. 

If you’ve worked with a component based game engine, such as Unity or Unreal, should be immediately comfortable with this concept.  Basically Game Objects are the entities or items that make up your game.  You will notice with a game object selected, it has very few properties:

image

Basically a Game Object contains positioning information (location, rotation and scale) and an Id, which we will use later.

What makes a Game Object useful is it’s a container for Components.  If you right click a Game Object in the Outliner, you can Add Component (or press I)

image

 

You can then chose a component from the following list:

image

This is how you can attach a Sprite, Collision Object, Sound effect, etc... to your Game Object.

 

So in a nutshell, a Collection is just that, a collection of things.  Generally Game Objects and other Collections.  A Game Object is an entity within your game world.  It has a position and ID and is a container for several components.  Components are the things that make up your game object, sprites, sounds, etc.  Got it?

 

So then... what about code?

 

Well every game engine has a game loop somewhere.  A game loop is a pretty simple concept, it’s a loop that runs over and over again and looks something like this primitive psuedo code:

 

while(gameRunning()){
    updateWorld()
    updatePhysics()
    getInput()
    render()
}

 

The exact contents of the game loop change from engine to engine but if you look at enough engines you will notice they are all very similar in the end.  It’s a loop that runs, checks for input, updates the game world, updates the physics engine if one exists then renders the results.  The actual game loop itself is often hidden away in a game engine and Defold is no exception.  So how then do you program your game?

Well first off you create a script.  A script is just another type of asset that can be added to your project.  To do so, right click the folder you want the asset to be created in (main), then select New->Script File.

image

 

Next you want to name your script.  In Defold scripts have the .script extension. 

image

 

This will create a new script file.  Double click it to bring it up in the editor:

function init(self)
    -- Add initialization code here
    -- Remove this function if not needed
    print("Game Created")
end

function final(self)
    -- Add finalization code here
    -- Remove this function if not needed
end

function update(self, dt)
    -- Add update code here
    -- Remove this function if not needed
end

function on_message(self, message_id, message, sender)
    -- Add message-handling code here
    -- Remove this function if not needed
end

function on_input(self, action_id, action)
    -- Add input-handling code here
    -- Remove this function if not needed
end

function on_reload(self)
    -- Add reload-handling code here
    -- Remove this function if not needed
end

 

I added a simple print() function call in the init() method.  Remember what I was saying about game loops earlier?  Well in Defold, during it’s game loop it makes various callback function calls at different points in the loop.  In this case init() is called when the script is first created, final() is called when it is done.  All the other methods are called each pass through the loop. We will look at each of these methods in detail in the future.

 

So now that we have a script, we actually have to attach it to something to get it to run.  Thankfully we already have a game object in main.collection named go.  Let’s attach the script to it.  Make sure main.collection is being edited, then in the outliner, locate go, right click it and select Add Component From File.

image

 

Select main.script then click OK:

image

 

Now that script will be attached to that game object.

 

This leaves one last question... how does the Defold engine know to create our main.collection to start all of this off in the first place?  Well that’s where game.project comes in.  This file contains several global configuration settings for your game.

image

 

In this particular case however, it’s the bootstrap that we are interested in.

image

 

You can think of main_collection as the entry point of your game.

 

That’s it for this tutorial.  Now that we have a good understanding of what the pieces that go together to make a game, next we will jump in and start getting our fingers dirty.  This tutorial is not going to be covering Lua programming.  If you are new to the Lua language, be sure to check out this tutorial series and you will learn everything you need to know to get up to speed.

 

The Video

GameDev News

5. July 2016

 

While not exactly earth shattering news, Microsoft today slammed the door on the idea of XNA 5. 

 

The following request was posted to the Visual Studio feedback system

Please continue to work on XNA. It's a great way for indie game developers like myself to make games and give them to the world. XNA gave us the ability to put our games, easily, on the most popular platforms, and to just dump XNA would be therefor heartbreaking... I implore you to keep working on XNA so we C# developers can still make amazing games!

 

Now XNA has been dead and buried for a long time but I think a fair number of people held out hope that XNA would come back at some point.  Given their answer, there is no question of hope now:

Back in 2013, we announced that XNA 4.0 would be the last release of the XNA framework. We thank all of you who used XNA in your games, and we’re humbled by the number of you who want an XNA 5.0! However,XNA 5.0 is not something we’ll be developing.

We know that many of you want to use cross-platform engines to build your games and deploy them in all the places that gamers care about – Xbox, Windows, Sony PlayStation, Nintendo Wii, iOS, Android and more. Now, there is an amazing ecosystem of game frameworks and engines that support building games on Windows and across all platforms.

If you are looking to port your existing XNA game to Windows 10 UWP, please explore the MonoGame framework, which is an open-source, cross-platform implementation of XNA, supporting Windows 10 UWP and a variety of other platforms. If you are looking to build a cross-platform game using C#, .NET and Visual Studio, you can explore Unity, a powerful 3D and 2D game creation tool and ecosystem. Unreal Engine 4 and Cocos2d are also great options for building cross-platforms games using Visual Studio.

In addition, if your game was built with XNA and previously worked on Windows or Windows Phone, it will continue to work.

 

I have to admit this is somewhat depressing as I was always a fan of XNA.  Not surprising, but depressing.

GameDev News

4. July 2016

The following is a recap of major events in the world of game development for the week ending July 4th, 2016.  I do a weekly video recapping the news available here with this week’s video embedded below.  This post is a collection of links mentioned in the recap.

 

The Video

GameDev News

1. July 2016

 

Xenko Engine, formerly Paradox 3D, just released version 1.7.  I previously featured this engine as part of the Closer Look series if you are interested in learning more.  Majordragdrop_propertyview features of this release are:

 

  • Practical Clustered Shading ( forward + rendering ) added (Video here)
  • Re-written lighting code for improved performance
  • Vulkan support experimental on Linux and Windows
  • Simplified asset creation, import assets directly from file
  • Improved camera preview
  • Drag and Drop assets and scripts to the properties panel
  • Linux Platform support as target (Ubuntu)
  • Rewritten audio engine
  • Misc bug fixes and improvements

 

You can read the full release notes here.

GameDev News ,

1. July 2016

 

NeoAxis, a .NET powered 3D game engine with full editor, just released version 3.5.  The key features of this release are:terrain_editor

 

  • Graphic user interface of the tools has been updated.
  • A tool to easily import 3D models from a file has been added.
  • Example maps have been updated.
  • Freeze Objects Manager has been added. The object is indended to optimize maps with big amount of objects on them. With this object the developer can make some objects on the map freeze to save resources.
  • Streaming terrain has been improved. Better management of load/unload mechanism.
  • The ability to skip mip maps during loading textures.
  • Bug fix: Broken rendering with enabled SoftParticles parameter of the material.
  • Bug fix: Broken decals on terrain.
  • Bug fix: Broken export of 3D models from Map Editor to DAE.

 

You can read more about the release here.

GameDev News ,

Month List

Popular Comments

UV Mapping in Blender Quick Video Tutorial
Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon


Home > Art >

4. November 2015

 

Although I’ve done a couple previous tutorials covering texturing in Blender, including this text one and this video one, I’ve never really shown the entire process.   This video simply illustrates a quick UV Unwrap/Texture job in Blender.

 

The high def video is available here.

Art ,

blog comments powered by Disqus

Month List

Popular Comments