Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

9. November 2016

BabylonBannerSplattered_thumb[3]

Welcome to the GameFromScratch.com tutorial series covering the BabylonJS HTML5 game engine.  The home page of the series is available here.  For each tutorial in the series there is both a text and video version available.  In this post we are simply going to introduce the BabylonJS engine, the scope of this tutorial series and discuss why you might want to use the Babylon engine and also some of the alternatives available should you decide not to.  If you’ve already decided on using the BabylonJS game engine, jump forward to the next tutorial.

 

BabylonJS Overview

I’m not going to go into a great deal of detail on the functionality included in BabylonJS as I have already featured this game engine in the Closer Look game engine series.  Instead we are going to take a quick top level look at the engine features.

 

Why Choose BabylonJS

So, why is the BabylonJS game engine a good choice for you?

  • Open source (Apache 2 license) and free to use
  • Full featured 3D game library (scene graph, physics, particles, models, sprites, etc)
  • Compatible with most modern WebGL browsers
  • Excellent tooling, including level editor, Unity exporter, model converters
  • Good documentation, samples and other learning materials

You can read the full feature set here.

 

Why Not Choose BabylonJS?

So we mentioned a number of Babylon’s strengths, but why would you *not* choose to use BabylonJS?  Well, beyond the fact you may not like how they implement things the biggest reason all comes down to your priorities.  WebGL performance isn’t on par with desktop OpenGL or even OpenGL ES, so there is a bit of a performance penalty at work here.  While HTML5 applications can be wrapped to run as applications on various mobile devices, again there is a price to be paid, in both performance and labor.

At the end of the day, personally, I think a lot of it comes down to your primary target.  If you are creating a browser game first and foremost, I recommend working in a browser native library such as BabylonJS.  This has the most direct workflow, is easiest to debug, etc.  If on the other hand the browser is just another target for you you are probably better off working in a game engine that also targets HTML5, such as Unreal or Unity.

 

Alternatives to BabylonJS

Shockingly there aren’t actually a ton of HTML5 3D game engines or frameworks like BabylonJS.  The most direct alternatives are:

 

By no means is that an exclusive list, but it does represent some of the most common 3D engines with WebGL as their primary target.

In addition to these engines several 3D engines offer HTML5 as a target including Unreal, Unity, Godot and many more.  The primary challenge with these options is the generated code is often illegible, acting almost identically to a compiled binary.  So if things don’t work right you are dependent on the engine developer to fix things.  Or if you wish to use a native browser feature, you are again dependent on the engine developers to support it in some form.

 

Enough overview, lets jump into the technical details.  I am aiming to keep each tutorial somewhat short and concise, both text and video versions.  Stay tuned for the first tutorial covering getting BabylonJS up and running.

 

The Video

Programming , , , ,

8. October 2016

 

Welcome to the next chapter in the on-going Closer Look At game engine series.  The Closer Look series is aimed at informing you quickly if a given game engine is a good fit for you or not.  It’s a combination of overview, review and getting started tutorial that should give you a quick idea of a game engines strengths and weaknesses.  Today we are looking at Clickteam Fusion, a codeless game engine that has been around in one form or another for over 20 years.  I have to admit up front, this guide isn’t as in-depth as previous entries as I am rushing a bit to get it out to you.  This is because as ofctf25 publish date (Oct 6/2016) Clickteam Fusion 2.5 is heavily discounted in the Humble Bundle.

 

As always, there is an HD video version of this guide available here.

 

About Quickteam Fusion

 

Quickteam Fusion is a 2D cross platform game engine that takes a codeless approach in a similar vein as Construct2 or Stencyl.  First released as Klik and Play in 1995, it was later rebranded The Games Factory, then Multimedia Fusion then finally Clickteam Fusion.  Clickteam tools run on Windows, and via various add-ons and modules is capable of targeting Windows, iOS, Android, Flash, HTML5 and Mac OS.  Note that several of these modules have an additional price tag from the base package.  In terms of pricing, here is the current ( 10/6/2016 ) from Steam.

image

 

Please note however that those prices are in Canadian dollars.  Also Clickteam is frequently discounted up to 75% or more, so do not ever pay the full price.  The free version is mostly full functioning minus extensibility and the ability to generate a game that runs outside of Clickteam itself, along with a few in game resource limitations.  The Developer Upgrade removes the requirement to display that the game was authored in Clickstream ( via Splash screen, credits, etc ) as well as adding some more controls inside the engine, most of which aren’t game related.

 

There are some fairly successful games that have been authored using Clickteam Fusion, the most famous of which is the Five Nights at Freddy’s series.  Other games include The Escapists, Freedom Planet and a few dozen more games available on Steam, Google Play or the iOS App Store.  So this is a production ready game engine, although only suited for 2D games.

 

Inside Clickstream Fusion

 

The strength of Clickteam is certainly the tooling it comes with.  All work in Clickstream Studio is done in the editor:

image

 

One of the biggest faults against Clickstream has got to be it’s aging UI.  While not particularly attractive, it is for the most part effective.  On the left hand side you’ve got the Workspace Toolbar, which can be thought of as your scene graph.  “Scenes” in Clickstream are somewhat confusingly referred to as Frames.  You game is made up on one or more frames, and when you select a frame you see the level editor shown on the right.  This is used for placing and interacting the various items that compose your scene frame.  On the bottom left you see the Properties panel, this changes based on what object is currently selected.  Also shown here is the editor for Active objects.  Actives are very important to CTF as we will see shortly.  There are also windows for controlling layers, for selecting built in assets, etc.  Windows can be undocked, pinned and move about the interface easily.

 

CT1

 

The primary editing service can be used to easily create levels or maps via simple drag and drop.

CT2

 

You can also insert new items into the frame:

image

 

Then choose from the dozens of built-in object types available:

ctf3

 

Perhaps 90% of the time, what you are going to use is an Active object, which is essentially Clickteam’s version of Entity or Sprite.

image

 

Double click the newly created Active and you get the active editor:

image

 

This tool combines several different tools into one.  There is a full paint package in here with fairly advanced tooling.  There are tools for doing common tasks like setting the Active’s pivot point and direction of facing, and there are tools here for defining and previewing animations.

 

In addition to the built in objects, there are several other extensions that can be added using the Extensions manager:

image

 

Additionally Clickteam offer a store for additional extensions that are both freely available and for sale:

image

 

Confusingly there is no direct integration between the store and Clickteam.  Therefore you have to download and manually install extensions and assets purchased this way.  The Store’s contents are mostly free and also showcase games created using Clickteam, tutorials, game code and more.

 

“Coding” in Clickteam

At this point you should have a pretty good idea how you compose the assets of your game to create levels… how do you actually add some logic to it?  That is done using these four tools:

image

Left to right they are the Story Board editor, Frame Editor, Event Editor and Event List Editor.

 

Story Board Editor

image

This one is pretty simple.  It’s just a top level overview of the Frames that make up your game.  Remember your game is ultimately composed of multiple frames, like so:

image

 

Frame Editor

image

The Frame Editor is simple the level editor we’ve already taken a look at.

 

Event Editor

image

 

This is where the “coding” happens.  Essentially its a top down flow chart/graph of events that happen in your game and what those events happen to.  Here for example is the “code” to select a Flying Saucer Active in the game “Saucer Squad”:

image

On the left hand side are the events (38 and 39, 36 is a group heading and 37 is simply a comment).  That first event triggers when the user left clicks on the Saucer object.  The right handle side of the screen shows the action that occurs when that happens.

image

 

So for the event on Line 38, then the user clicks the left mouse button on Active type Saucer, it plays the sound sample Button_1, among other actions.  It’s essentially these events and actions you use to create your game.  Let’s create a very simple example… lets create an action that simple plays a sound effect when the frame (scene) is created.

First select Insert->Condition

image

 

This will bring up the conditions dialog:

image

 

In this case I clicked the Storyboard Controls (the chessboard/horse icon), then chose Start of Frame.  The creates a new action that will fire when the frame is started.  Now to the right hand side, select the space below the Speaker icon, like so:

image

 

Right click and all of the available options will be displayed:

image

 

Next the appropriate editor will be shown

image

 

Event List Editor

This editor performs the same functionality as the Event Editor, but instead of in a somewhat unwieldy grid view, it represents the events in a much more readable list form:

image

 

One last editor of note is the expression editor, for creating much more advanced logical conditions:

image

 

Individual entities within the frame can also have their own events, set in the properties panel of the selected item:

image

Clicking edit will bring you back to the exact same interface we just discussed.  Also in the properties panel you can define variables:

image

 

These values can then be interacted with in other event controllers.

 

Community and Documentation

Documentation in Clickteam is decent.  Built in there is an integrated CHM based help system, as well as 4 multipart tutorial games to get started.  There are also a wealth of tutorials available to download (mostly free) on the Clickteam store.  There are also a fair number of Clickteam tutorials on YouTube, although many of them are quite awful.  There is an active forum as well as a wiki.  All told, for every problem I faced, I found a solution quickly enough online.

 

Summary

So what ultimately do I think of Clickteam Fusion?  For the most part it is what it’s advertised to be, a code free 2D game creation kit able to target multiple platform.  There is of course a learning curve, but it’s a relatively short one.  As a code focused programmer, I don’t find the coding process extremely productive, but I can see how it would be so for a more visual oriented person and especially for a non-coder.  Clickteam tools are certainly getting a bit long in the tooth, a lot of the legacy cruft is showing it’s age and the UI could certainly use an update.  My biggest hesitation is wondering how well this development system would scale with system complexity.  If you’re game isn’t easily broken into scenes or is sprawling in complexity, I can see Clickteam becoming incredibly cumbersome.  That said, I think this is a successful all in one development tool that can take you a very far way in a very short period of time even with minimal to no development skill.

 

The Video

Programming, Design , ,

3. October 2016

 

Welcome to the next part in our ongoing Defold Game Engine tutorial series.  In this tutorial we are looking at working with the integrated Box2D physics engine built into the Defold engine.

 

As always there is an HD video version of this tutorial available here or embedded below.

 

The Defold engine makes it extremely easy to work with physics but is rather minimal in it’s implementation.  Let’s jump right in.

 

Creating a Collision Object

 

The heard of implementing physics in Defold is the Collision component.  This is composed of two part, the Collision Component that describes the physical attributes of a game object, and the Physics shape, which defines it’s dimensions.  I start off by creating this simple Gameobject, the image used in the sprite is 128x128 pixels:

image

 

Now we simple add a new physics component to the game object.  Right click the Game Object in the Outline, select Add Component, then select Collision Object:

image

 

Here are the default properties of a Collision Object:

image

 

Type is important and we will cover that shortly.  Mass is the weight of the object relative to dimensions, friction is how one surface reacts to another ( think traction ), restitution is the “bouncy-ness” of an object, linear damping and angular damping determine how motion of the object degrades over time, locked rotation determines if the physics simulation will rotate the attached game object or not.  Group and Mask are used to determine which collision objects interact with other collision objects.  Objects in the same group will collide, while objects not in the same group, or if that particular group isn’t added to the Group value ( comma separated ) will not interact.  So think of Group as the physics identity or type(s) this object belongs to, while Mask is the groups that object will interact with.

 

Next we need to define the shape of our physics object.  Simply right click the Collision Object and select Add Shape:

image

Next pick Box:

image

 

In the properties, set the Width and Height to match the size of our source image.  Depth is the value along the z-axis and can be left at the default value in most cases.

image

 

Now that we have our Collision object define, simply create a couple instances of our game object in the scene and the results are immediately demonstrated.

GIF

 

You probably didn’t want the boxes just dropping out of the world now do you?  So we need to create a physics body for the “floor”.  We can easily do this by creating a new Game Object in main and adding a physics body to it.  Like so:

image

image

 

The problem here is, our newly created floor will be effected by gravity, just like every other object in the scene!  This is where the Type of the Collision Object becomes important:

image

 

So far we have only used the default, Dynamic.  A dynamic object is a fully simulated physics object.  It will take part in the simulation, will be part of the simulation and will be affected by the simulation.  Static is what we want in this situation.  A static object will be part of the simulation, but will not be effected by it.  This is your proverbial unmovable force!  So other objects in the simulation will be able to hit the collision object and they will be affected by the collision, but the static object will not be changed in any way.  Kinematic objects are special objects that are generally moved directly by the character or code but also take part in the physics simulation and will be affected by it ( think that players sprite for example ).  Triggers on the other hand are simply shapes in the world that can detect a collision and can be hit, but wont have any affect on anything in the world.  They are often used to detect movement, for example the goal area in an air hockey game.

 

Now with our floor object set to static, our updated results!

gif2

 

So, how exactly do we control global physics properties, such as gravity?  These settings are available in the .project file:

image

 

Physics and Code

Now that we know how to set up a physics simulation, let’s look at how to deal with it in code.  For we are going to look at how you respond to a collision in code.  As you might be able to guess, messages are used.  Let’s look at a simple program that responds when a collision occurs.  Attach a script to your box object and add the following code:

 

function on_message(self, message_id, message, sender)
    if message_id == hash("contact_point_response") then
    	msg.post("@render:","draw_line", { 
    		start_point = vmath.vector3(message.position.x -40, message.position.y - 
    		40, 0),
    		end_point = vmath.vector3(message.position.x +40, message.position.y + 40, 
    		0), 
    		color = vmath.vector4(1,0,0,1) })
    	msg.post("@render:","draw_line", { 
    		start_point = vmath.vector3(message.position.x -40, message.position.y + 
    		40, 0),
    		end_point = vmath.vector3(message.position.x +40, message.position.y - 40, 
    		0), 
    		color = vmath.vector4(1,0,0,1) })	
    end
end

This code simply listens for the contact_point_response message which is sent when a collision occurs with the attached game object.  When such a collision occurs, this code draws an X centered about the collision point by sending the draw_line message to the render subsystem.

There is a great deal of information about the collision passed along in the message parameter:

image

As you can see, information on what object was collided with, how fast, groups, velocity, mass etc are all available in the contact_point_response message.

 

On final topic to cover is occasionally you are going to want to be able to apply force directly to a physics object using code.  This is also easily accomplished using the following code:

    	msg.post("#collisionobject", "apply_force", { 
    		force = vmath.vector3(0,5000,0),
    		position = go.get_world_position()})

Again using Defold’s messaging system, we send the apply_force message to our Collision Object component.  This applies 5000 newton of force along the Y axis.  Added inside our collision handler, it makes for some interesting results!

gif3

 

The Video

Programming ,

23. September 2016

 

Welcome back to our ongoing Godot tutorial series.  You may notice a pretty major change in the way Godot looks from previous tutorials.  This is because this tutorial jumps forward to Godot 2.1 which has an updated look and feel.  Don’t worry, the process is virtually identical regardless to which version of Godot you were running.  Today we are going to look at implementing 2D lights in your Godot game.  This will involve creating Godot light nodes, as well as occluders to prevent light.  We will also look at light masking, which is useful for implementing fog of war type effects. 

 

As always there is a video version of this tutorial available here.

 

First let’s set up a simple scene we can test our lighting on.  I simple create the following hierarchy using the default Godot icon sprite.

image

 

Then scale it up like so:

image

 

Now let’s add a Light2D as a Child to our Root node:

image

 

Notice the exclamation mark?

image

 

This is because we need to specify a texture to use as the light source.  I created the following image in Paint.net (process is shown in the video if you want to see how it was made):

LightMask

 

Notice that this image is a grayscale PNG file with an alpha channel.  Where there are no pixels at all, there will be no light shown.  Where it is whitest, the light will be most intense, while the darker it gets the less intense the light.  Save this image or create your own and add it to your project.  Now we set it as the texture source for our light.

image

 

Now if you move your Light2D node around the scene, you will see how it interacts with other objects in the scene:

GIF

 

There are a number of properties you can set for the light, such as the Energy (intensity) Color (tint) and Scale (size):

image

 

Notice also Mode.  We will come back to that in a minute.  Now sometimes you aren’t going to want all lights affecting all objects in the scene.  Thankfully there is a setting for that.  Notice in the range category there is a setting called Item Mask:

image

 

This controls what layer of items this light will interact with (there is also a setting for shadows as well).  Now if you switch over to your Sprite, under canvas item you will notice a Light Mask setting:

image

 

So long as the light and CanvasItem use the same masking channel, the light will apply to that node.  If they don’t use the same channel, the light will have no effect.  This can lower processing costs and enables you to exempt parts of your seen from being lit if so desired.

 

Now sometimes you want to have light actively blocked in your scene.  For example you might have a wall that should cast a shadow.  This is easy to implement in Godot using Occuluders.  This is simply a polygon area where the proverbial light don’t shine.  Let’s set one up around the nose of our Godot sprite.  Add a LightOccluder2D to your Sprite.

image

 

Your scene hierarchy should now look like:

image

 

With the LightOcculder2D node selected in the Scene the following icon should be available in the 2D view:

image

 

Click the pencil.  Now we want to draw our occlusion polygon, like so:

Gif2

 

Now notice the way the light interacts with the scene...

gif4

 

Now remember earlier on the Mode value of our Light2D node?

image

 

Now we are going to switch it over to “Mask” and show a powerful capability.  This can be used to create localized lights or to implement fog of war effects.  Just like before we need a texture to represent our light source, but this time we want the pixel values reversed, so I created the following image:

LightMask2

 

In this case the black area will receive no light, while the whitest area will contain the most light.  Here is the end result:

gif5

 

By scaling the light out to the full size of the screen, you can easily attach such a light to the character sprite to easily implement a fog of war type approach.

 

The Video

Programming ,

12. September 2016

 

Welcome to the next part in our ongoing Defold Game Engine tutorial series.  Today’s tutorial is going to show an area where the Defold engine really shines, creating 2D tile based levels.  This way of creating levels is to paint levels in a data structure called a tilemap, which itself is a collection of tiles.  A tile is simply a portion of an image that can be drawn over and over, much like you could use Lego blocks to create a castle.

 

As always there is an HD video version of this tutorial available here.

 

For this tutorial we need a tileset to work with.  This is simply an image composed of tiles, in this case with no spaces or padding between them.  I personally am using the tiles from opengameart.org in the Free Platformer Game tileset.  I have taken these individual tiles and merged them together into a single image you can download below.  (Be sure to click the image to get the full sized version.  In this example size does matter! ).

 

tilesThis is a 1024x512 pixel image composed of 64x64 pixel tiles.  Of course you can use whatever image you want, just be aware that if there is padding or different sized tiles your version is going to be different.

 

As always I assume you have gone through the prior tutorials in the series.  Alright, now that we are set up, let’s get going.

 

Creating a Tile Source

 

First things first, we need to create a directory for our level, tiles, images, etc.  I simply created a folder called level.  Inside this folder I created a directory called images and dragged the image above into that folder, like so:

image

 

Now we need to create a tile source.  You can think of this as the palette or selection of tiles we are going to paint with.  Don’t worry, it’s exceedingly easy.  Simply right click level, select New->Tile Source File

image

 

Called it tiles.tilesource like so:

image

 

Now in Outline make sure Tile Source is selected:

image

 

Now in the Properties panel, select the image file we added earlier for the Image property, then set Tile Height and Tile Width to 64.  Obviously if you used a different image you may have different settings here.

image

 

Now in your viewport you should see your tiles, with the grid drawn nicely around them like so:

image

 

All done creating our tilesource.  Make not of the collision property... we will come back for that in the next tutorial.  Make sure you save.

 

Creating a Tile Map

Now it’s time to actually create our tile map.  Once again right click the level folder and select New->Tile Map File.  Name this one map.tilemap:

image

 

Now in Outline make sure Grid is selected:

image

 

Now in the properties, pick out tilesource:

image

 

Now select layer1 in the outline window and we can begin painting!

 

In the viewport use the spacebar to bring up the tile source, then left click to select the active tile.  Now hit space again to hide the tile source and paint using the left mouse button.  You can also use the right mouse button to select multiple painted tiles to easily clone and reproduce compound tiles.

GIF2

 

If you need to paint tiles on top of other tiles, simply create another layer, right click Layers and select add:

image

 

The z order determines the draw order of tile layers:

image

 

Right click an empty space then left click to delete a tile if required.  Save before continuing on!

 

Using a Tile Map

Finally it’s time to put our newly created tilemap to use.  This is also simple.  Open your main.collection in the editor then add a new game object just like we did in the past.  Right click the game object and select Add Component From File:

image

 

Select your .tilemap file, and voila:

image

 

The Video

Design, Programming ,

Month List

Popular Comments