1. May 2015

 

Yesterday Microsoft announced the released of Visual Studio Code, a cross platform code editor.  Today I have decided to take a closer look.  I certainly wouldn’t call this a review, I have barely used the application.  Instead this is more of a first impressions tour, just a quick heads up of what the Visual Studio Code experience is like.  Also keep in mind, this is only a preview release and is by no means a finished product.  Since the cross platform nature is the big selling point, I’ve run this entirely on Mac OS.  Getting started is simple… go to https://code.visualstudio.com/Download and download for your appropriate platform:

 

Ss1

 

In the case of OS X, the installer is simply a zip file.  Download and extract, then run the executable inside.  If you want to do additional configurations, such as making code run from the terminal read this.

 

Now a caveat, if you want debugging, and you probably will, you also need to have Mono or C# installed.  You can download it here.

 

Ss3

 

 

I suppose we should set the expectations properly right away.  Despite the branding, this is not a cross platform version of Visual Studio.  Instead it’s more of a lightweight code editor, along the lines of, um, the sublime Sublime Text.  Visual Studio Code is actually based off of Github’s open source extensible Atom code editor ( actually, based on Electron, which was used for Atom and rebranded at some point ).

Oh and C++ developers, at least right now, you are out of luck.  VSC currently supports C#, ASP.NET, and Node (JavaScript or TypeScript) only. 

 

Welcome to Visual Studio Code

 

When you first launch the application, you are greeted with this sparse Window:

Ss2

 

Wow, that is pretty minimal isn’t it?

 

Again like Sublime Text, there isn’t really a project file, VSC works at the folder level.  It does however recognize a couple different project formats including package.json, project.json, tsconfig.json and ASP.net projects files.  If there is one of these files in a folder that is opened, that project file is automatically parsed.

 

Let’s try VSC out with a trivial existing Javascript project.  Heroku’s minimal Node sample available here.

 

We need to clone the repository then install the express dependency if not already done.  The following commands should do the trick:

cd /path/to/directory/to/install/to

git clone https://github.com/heroku/node-js-sample.git

cd node-js-sample

npm install express


With those steps performed, you should be able to open the directory in VSC.  If you added code to your bashrc profile, you should simply be able to type code ./  otherwise load up Visual Studio Code and select the menu File->Open… and pick the folder.

 

The Interface

 

Now that you’ve got a project loaded, the interface is pretty minimal:

Ss4

Across the left and side you have tabs for dealing with files/folders, searching, git integration and finally debugging and that’s about it.

 

On the right hand side if the code editor, with line numbers, syntax highlighting and code completion, although it seems to do a fairly lousy job of parsing javascript classes so far.

Ss5

 

Editing HTML is slightly nicer:

Ss16

 

There is also a markdown preview option tucked away in there.

 

You can split code editing windows as many times as you wish, although you can only do it vertically.  A light bulb icon appears offering quick tips for fixing common errors when clicked:

Ss6

 

There are a couple interesting omissions, the most obvious of which is the lack of code folding.  There is also very little in the way of code refactoring tools, the closest you get is the replace all occurrences option, such as here with the app variable selected:

Ss7

 

It does have a basic code beautifier included and that’s about it.  For the most part its a pretty bare bones code editor.

 

Running and Debugging

 

One of the big sales features is the integrated debugger, so let’s take a look at the process.  As I mentioned earlier, you need to have Mono or C# installed to use the debugger, so heads up there. To debug your code go to the debug tab and hit play.

Ss8

 

Since this is the first time you’ve run it will create a Launch.json configuration file.  Modify it accordingly to match your project:

Ss9

 

Click run again and your application should launch:

Ss10

 

By the way, it’s CTRL +C to terminate a Node application.  Of course you can stop using the controls from VSC too

Ss11

 

You can set a breakpoint by clicking to the side of the line of code in the editor

Ss12

…. but… they don’t work.  Not sure if I am making a mistake, this is an unimplemented feature, or possibly a bug, but I couldn’t get server side breakpoints to fire.  On the other hand, you can step through code:

Ss13

Or you can use F10, F11, SHIFT + F11 to step over in and out of code.

 

Down the left hand side you’ve got your standard debug functionality, including local variables, the callstack, etc.

Ss14

 

Although inspection into Javascript objects is nowhere near where i’d like it to be yet ( unlike for example WebStorm ).

 

Command Palette

 

Another nice productivity feature of VSCode is the Command Palette, which if you’ve used Sublime Text will look instantly familiar.  Opened by pressing CMD + SHIFT + P, it brings up a quick menu of all commands available in VSC:

Ss15

 

As you can see there is also a list of shortcuts for each command.  For keyboard warriors such as myself, these quick filterable menus are a godsend for productivity.

 

Conclusion

 

Right now, Visual Studio Code is clean, simple, focused and incredibly immature.  Of course, it is also free, so you’ve got very little to use to check it out.  Some fairly essential functionality is currently missing, but going forward VSC could be a great environment for editing Node and C# applications, although frankly I will stick to WebStorm personally.  I will however probably keep using Code as a quick code editor.  As a straight up quick text editor, it is pleasant to use.

 

For the most part, this is a preview and it shows.  I will take another look in a couple months and see how useful it has become.  If you are a C++ developer looking for a cross platform Visual Studio, you certainly should look elsewhere.  I don’t think this will ever be the product you are looking for, it is focused at web and cloud developers.  For developers working on web apps, using git in JavaScript or TypeScript, this is certainly a tool to keep an eye on.

 

I can’t help but think Microsoft might have made a bit of an error with the branding on this product.  So many people are going to expect a cross platform Visual Studio, and they are going to be disappointed.  However if they came in looking for a light weight code focused cross platform editor, they will most likely be delighted… eventually.

Programming

29. April 2015

 

In the previous part we looked at we look in a bit more detail at working with Sprites, now we are going to get a bit more… animated.  In this tutorial we are going to look at using Spritesheets, named Flipbooks in Unreal Engine, to create sprite animations.

 

A bit of a warning before we jump in, as of writing this process is a bit buggy and needing improvement.  Hopefully by the time you read this, the Unreal team have ironed out some of the kinks.  If you want more details on creating the spritesheets and a bit more exposure to some of the Unreal Engine faults, be sure to check out the video version, it goes into much greater detail.

 

This tutorial is available in an HD video here.

 

Importing a Spritesheet

 

A Spritesheet is simply a texture with multiple sprites on it.  This is the one I am using for this example:

spritesheet

 

It is a power of 2 resolution PNG file containing 25 frames of a walk cycle animation.  A bit of a warning however, I HAVE HAD NO SUCCESS WITH PNGs in Unreal.  To get this to work I had to convert to tga format before importing.  Regardless to how the PNG is made, the results are almost always mangled once imported to UE4.

 

To get started, simply drag the texture in as normal.  The critical part of this equation is that your file must have an alpha channel, as the alpha channel is used to calculate each sprites location in the next portion.

 

Now that we’ve added our spritesheet to our textures, simply right click and select Extract Sprites:

image

 

Using the alpha channel, it will automatically create a sprite for each image in the spritesheet, like so:

image

 

With all of the generated sprites selected, I now moved them into their own folder in the Sprites folder.  This step is of course strictly optional.

 

Now a bit of a bug/problem with Unreal Engine…  Each of the generated sprites is automatically named, but the names themselves make no sense.  First off, they are named FILENAME_Sprite###.  However, the Content Browser doesn’t sort properly for alpha numeric, meaning that Sprite11 and Sprite12 come before Sprite2 and Sprite3, which makes things particularly painful to work with.

 

Even worse, the order they are created in makes absolutely no sense right now… so the process of creating a flipbook is needlessly complicated.  You’ll see what I mean in a moment.

 

First lets look at a generated sprite and suddenly Edit Source Region will make a ton more sense.  Simply double click a sprite to bring it up in the Sprite Editor.  Here is the very first sprite in the sequence opened in the editor. 

image

 

Now click Edit Source Region and you will see how multiple sprites can be stored in a single texture:

image

 

As you can see, our sprite is actually just a very small portion of the over all texture.  We would expect the next sprite to be Sprite2, 3, 4, etc…  but sadly, they aren’t.  I honestly cant make rhyme or reason of the naming convention Unreal used for automatically parsed sprites.  Sadly you will need to figure them out in order to deal with the next part of the process.  Hopefully this all gets fixed soon, as it’s extremely irritating.   For now select each sprite and figure out where it is in the order…  mine basically went

 

Row1: sprite, 2,3,4,5,6,7

Row2: 12,13,14,11,10,8,9

Row3: 15,16,17,18,19,20

Row4: 24,25,23,22

 

 

… if you see the logic there, good on you!  Ultimately once you figure the order out, the names really don’t matter, but you can rename them to make sense if you want.  Or you could change the UV values of each so the existing names actually make sense.  Me, I’ll just wait for Unreal to fix this mess.

 

Creating a Flipbook Animation

 

Anyways, once you’ve figured out your sprite frame orders, it’s time to create a new Flipbook.  Simply select New->Animation->Sprite Flipbook, like so:

image

 

A new flipbook will be created, feel free to rename it.  Then double click it to bring up the Flipbook Editor:

image

 

Now what you want to do is drag each Sprite over to the bottom of the page, in the order of the animation frames ( that’s the list I made above.  Basically if your spritesheet is like mine you want the top row, left to right, then the next, and the next, etc ).  The order they are dragged is the order they are played in the sequence:

image

 

You will see a real-time preview of your animation as you drag sprites in:

g2

 

You can change the over all speed of your animation here:

image

 

That is the number of frames that will be shown each second.  So a 26 frame animation would take 2 seconds to complete.  You can also set the duration of each frame, here:

image

Frame Run is how many frames this animation frame will be shown for.  For example, if you had Frames Per Second set to 10 and Frame 1 set to a Frame Run of 5, that particular frame would be shown for 1/2 a second.

 

Now your animated sprite can be added to the scene just as easily as a normal sprite, simply drag the flipbook in to your scene:

g3

 

Truth is however, you will rarely use a Flipbook this way, instead they will generally be owned by an Actor, which we will cover in the next portion.

 

The Video

 

Programming , ,

28. April 2015

 

In this tutorial we are going to explore the tilemap functionality built into the Godot game engine.  A tile map is a 2D game map composed of layers of “tiles”, which are essentially just a fixed size sprite with some additional properties.  It allows you to quickly paint a level and reuse art assets, greatly decreasing storage and memory requirements for levels.  In addition to supporting tile maps, Godot also includes a handy editor, although there certainly are some warts.

 

There is an HD video version of this tutorial available here or embedded below.

 

We are going to require two scenes for this example, one to create our tileset and one to actually use it.

 

Creating a Tileset

 

Before we continue though, I need a tileset to use.  Instead of creating one, I am going to use this one from OpenGameArt.org.  Of course, you can use whatever image you want, just be sure the tiles are the same size and have no spacing between them (if you want to keep the math easy).

 

Here is the tileset I chose:

PathAndObjects

 

This version however is shrunk down, use the link above if you want to use the exact same tiles.  Each tile in this image is 32x32 pixels in size.  This will be important shortly.

 

Now let’s create a tileset in Godot.  Create a new scene.  This process is really labor intensive unfortunately, but very powerful too.  Create a root Node, then a Sprite for your first tile.  Each tile needs to have a unique name.  I am only going to use a subset of what is available on that spritesheet, but you simply repeat the process to add more.

 

Create a hierarchy like this:

image

 

Now for Sprite Tile1.  Now configure the sprite’s Texture to your spritesheet.  Importantly, set Region to on and set the Region Rect to 0,0,32,32, like so:

image

 

This sets the image source of this tile to a 32x32 region at the top left corner of the texture.  Now you should see:

image

 

Now let’s setup snapping, so we can arrange our tiles in a nice grid.  Select Edit->Configure Snap

image

 

Set Grid step to the same dimensions as your tiles, in my case 32x32:

image

 

Now select “Use Snap” as seen in the menu above.

 

The next part is optional, if you want to use physics or collisions or not.  If you do, we now need to set up StaticBody and hit detection boundaries.  This process is the same as we went through in the previous tutorial so I am not going to go into details on how.  You do want the end result like this however:

image

 

Then define the areas of your CollisionsPolygon2D that are collide-able or not, like so:

image

 

Turning snap on and off is critical here.  Snap makes it easy to create the initial bounding box, as it will automatically snap to each corner.  However, when you start adding fine detail, be sure to turn it off.

 

Now repeat this process for each tile you wish to include from your spritesheet.  You can make the process a great deal quicker using the Duplicate option ( or Ctrl +D ).  Simply select your first tile then duplicate.  Then you just need to reposition it on the map, redefine the CollisionPolygon2D bounds and of course, update the region to the next tile, like so:

image

 

This will select the next tile from the top left of the image.  Repeat until you have all of your tiles defined.  Yes, it would be nice if this was an automated process!

 

Because I’m lazy, im only going to define three tiles, like so:

image

 

Which look like this with collision polygons defined:

image

 

Please note, there was no need to put space between each tile like I have here.  Now that we’ve defined our tiles, first save your scene, I called mine tilemap.scn.  Now we are going to export a tilemap.  Simply choose Scene->Convert To…->TileSet…

 

image

 

I called mine tileset.xml.  Be aware of the option Merge With Existing.  When you make changes to your tileset in the future, you probably want to turn this off if you want your changes to be completely overwritten.

image

 

I personally found the Collision polygon exporting to be extremely buggy.  You may want to open up the generated XML file and make sure collision information was properly exported:

image

 

Using a Tilemap

 

Now that we’ve got our tileset created, our collision polygons configured and all things ready to go, it’s time to create a new scene then create a Tilemap.

 

The Node you want to add is a TileMap, like so:

image

 

Configure your tilemap like so:

image

 

If you are using Physics, set Use Kinematic on, otherwise don’t.  Set the Cell Size to the size of your tiles and tileset to your newly exported tileset.

 

You will notice now, with the TileMap node selected, your tiles will appear down the left hand side of the 2D editor window:

image

 

You can now use these to “paint” your level, like so:

image

 

You can create multiple TileMap objects if you need to have different layers of tiles (like foreground props for example).  Today though, we are going to stick to this simple example.

 

Finally I created a RigidBody sprite to interact with our tilemap, so our final scene looks like this:

image

 

Now when we run it, it should look like:

g1

 

You can make some edits to your tilemap from within Godot without re-exporting the tileset.  With your Tilemap selected, select your Tileset property, then Edit:

image

 

You will notice a new Theme menu appears, allowing you to edit your Tileset, such as adding new items:

image

 

You can also see the tiles that make up the tileset in the Inspector:

image

 

The Video

 

Programming , ,

24. April 2015

 

As you may have guessed from the title, it today’s tutorial we are going to look at working with Sprites using Unreal Engine.  We already looked briefly at creating a sprite in the previous tutorial, but today we are going to get much more in-depth.

 

Before you can create a sprite, you need to have a texture to work with.  Unreal Engine supports textures in the following formats:

  • .bmp
  • .float
  • .pcx
  • .png
  • .psd
  • .tga
  • .jpg
  • .dds and .hdr ( cubemaps only, not applicable to 2D )

 

That said, not all textures are created equal.  Some formats such as bmp, jpg and pcx do not support an alpha channel.  This means if you texture requires any transparency at all, you cannot use these formats.  Other formats, such as PSD ( Photoshop’s native format ) are absolutely huge.  Others such as BMP have very poor compression rates and should generally be avoid.  At the end of the day, this generally means that your 2D textures should probably be in png or tga formats.  Unreal also wants your textures to be in Power of Two resolutions.  Meaning that width/height should be 2,4,8,16,32 … 512, 1024, 2048, etc…  pixels in size.  It will work with other sized textures, but MIP maps will not be generated (not a big deal in 2D) and performance could suffer(a big deal).  Keep in mind, your sprite doesn’t need to use all of the texture, as you will see shortly.  So it’s better to have empty wasted space then a non Power of Two size.

 

* Personally I’ve experienced all kinds of problems using PNG, such as distorted backgrounds, while TGA has always worked flawlessly. 

 

Adding a Texture to your game

 

Adding a Texture is simple as selecting a destination folder on the left, then dragging and dropping the appropriate file type (from the list above) from Finder/Exporter to the Content Browser window, shown below:

image

 

Alternately, you can click New –> Import

image

 

Then navigate to the file you wish to use and select it. 

 

You texture should now appear in the Content Browser.

 

Texture Editor

 

Now that you have a texture loaded, you can bring it up in the Texture Editor by either double clicking or right clicking and selecting Edit.  Here is the texture editor in action.  It is a modeless window that can be left open indepently of the primary Unreal Engine window.

 

image

 

The Texture Editor enables you to make changes to your image, such as altering it’s brightness, saturation, etc…  you can also change compression amounts here.  However, for our 2D game, we have one very critical task…  turning off MIP maps.

What's a MIP Map?

History lesson time! MIP stands for multum in parvo, Latin for "much in little". Doesn't exactly answer the question does it? Ok, lets try again. Essentially a MIP map is an optimiziation trick. As things in the 3D scene get further and further from the camera, they need less and less detail. So while right up close to an object you may see enough detail to justify a 2048x2048 resolution texture. However, as the rendered object gets farther away in the scene, the texture resolution doesn't need to be nearly as high. Therefore game engines often use MIPMaps, multiple resolution versions of the same texture. So, as the required detail gets lower and lower, it can use a smaller texture and thus less resources.
You know when you are playing a game and as you move rapidly, often textures in the background "pop" in or out? This is the mipmapping system screwing up! Instead of seamlessly transitioning between versions, you as the user are watching the transition occur.


Support for MIP maps is pretty much automatic in Unreal Engine.  However in the case of a 2D game, you don’t want mipmaps!  The depth never changes, there should never be different resolution versions of each texture.  Therefore, we want to turn them off, and the Texture Editor is the place to do it.  Simply select Mip Gen Setting and select NoMipmaps.

image

 

Before you close the Texture Editor, be sure to hit the Save button.

image

 

Creating A Sprite

 

Now that we have a Texture, we can create a sprite.  This is important, as you can’t otherwise position or display a Texture on it’s own.  So, then, what is a Sprite?  Well the nutshell version is, it’s a graphic that can be positioned and transformed.  The name goes back to the olden days of computer hardware, where there was dedicated hardware for drawing images that could move.  Think back to PacMan…  Sprites would be things like PacMan himself and the Ghosts in the scene.

 

In practical Unreal Engine terms, a Sprite has a texture ( or a portion of a texture, as we will see shortly ) and positional information.  You can have multiple sprites using the same texture, you can have multiple sprites within a texture, and the sprites source within a texture can also change.  Don’t worry, this will make sense shortly. In the meantime, you can think of it this way… if you draw it in 2D in Unreal Engine… it’s probably a Sprite!

 

Once you have a Texture in your project, you can easily create a sprite using the entire texture by right clicking the Texture and selecting Create Sprite, like so:

image

 

You can also create a new sprite using New->Miscellaneous->Sprite

image

 

This will then open up the Sprite Editor.  If you created the Sprite using an existing texture, the texture will already be assigned.  Otherwise you have to do it manually.  Simply click the Texture in the Content Browser.  Then click the arrow icon in the Details panel of the Sprite Editor on the field named Source Texture:

image

 

Your texture should now appear like so:

image

 

You can pan and zoom the texture in the view window using the right mouse button and the scroll wheel.

 

Now remember earlier when I said “all or part of the texture”?  Well a Sprite can easily use a portion of a texture, and that’s set using the Edit Source Region mode:

image

 

This changes the view panel so you can now select a sub rectangle of the image to use as your sprite source.  For example, if you only wanted to use Megatrons head, you could change it like:

image

 

Then when you flip back to View, your texture will be:

image

 

When dealing with sprite sheets, this becomes a great deal more useful, as you will see shortly. 

 

There are a couple other critical functions in the Sprite Editor that we will cover later.  Most importantly, you can define collision polygons and control the physics type used.  We will look at these functions later on when we discuss physics. 

 

Two very important settings available here are:

image

 

Pixels Per Unit and Pivot Mode.

 

Pixels per unit is exactly what it says… a mapping from pixels to Unreal units, which default as mm.  So right now, each pixel is 2.56mm in size.  Pivot Mode on the other hand determines where a sprite is transformed relative to.  So when you say rotate 90 degrees, you are rotating 90 degrees around the sprites center by default.  Sometimes top left or bottom left can be easier to work with, this is where you would change it.

 

The final important point here is the Default Material, seen here:

image

 

This part is about to look a lot scarier than it is!  Just know up front, if you prefer, you can ignore this part of Unreal Engine completely!

 

Materials

 

Every mesh in Unreal Engine has a material attached, and when you peel back all of the layers, a Sprite is still ultimately a mesh… granted, a very simple one.  There are two default options available to you included in the engine, although depending on how you created your project, you may have to change your view settings to access them:

image

 

Then you will find the two provided materials for sprites:

image

 

The name kind of gives away the difference… DefaultLitSpriteMaterial takes into account lighting used in the scene.  DefaultSpriteMaterial ignores lighting completely.  Unless you are using dynamic lighting, generally you will most likely want the DefaultSpriteMaterial.  You can edit the Material by double clicking:

image

 

This is the Material Editor and it is used to create node based materials.  Basically it’s a visual shader programming language, behind the scenes it ultimately is generating a GLSL or HLSL shader in the end.  Truth is the process is way beyond the scope of what I can cover here and in most cases you will be fine with the default shader.  If you do want to get in to advanced graphic effects, you will have to dive deeper into the Material Editor.

 

Creating a Sprite

 

Now that we have our texture and made a Sprite from it, it’s time to instance a Sprite.  That is, add one to our scene.  This is about as simple as it gets, simply drag a Sprite from the Content Browser to the Scene, like so:

 

g1

 

Now that you’ve created a Sprite, you will notice that there area  number of details you can set in the Details panel:

image

 

All sprites by default share the same source sprite and material, but you can override it on an instance by instance basis.  For example, if you wanted a single sprite to be lit and all the others to be unlit, you can change the Material Override on that single sprite.  Obviously using Details you can also set the sprites positioning information and some other settings we probably wont need for now.

 

 

Next up, we will look at sprite animation using a flipbook.

Programming , ,

19. April 2015

 

Today we are going to take a look at the PlayCanvas HTML5 3D Game engine.  While not strictly a tutorial, this guide should give you a pretty good idea of what the PlayCanvas Engine includes,if it is right for you and give you enough information to get you started.

 

There is also a video version of this tutorial available here.

 

First off, what exactly is the PlayCanvas Engine?  Well, let’s let them describe it in their own words:

 

PlayCanvas is the world’s easiest to use WebGL Game Engine. It’s free, it’s open source and it’s backed by amazing developer tools.



The amazing developer tools part isn’t hyperbole either, PlayCanvas ships with an impressive amount of polished and high quality tools.  Where it does get a bit confusing is where the open source part stops, and the pay to use it part starts.  

 

Getting Started

 

There are three ways to develop with PlayCanvas.  Download and run the tools locally, use the online tools and code using a Github or Bitbucket repository or, as I am going to do in this example, work entirely in their online hosted IDE.  It’s not a bad way to work but sadly is missing a few features, like code autocompletion. I would probably work in WebStorm using a Github repository if working on a production project instead of just playing around.

 

To get started with the online hosted tools, you need to create an account then log in to PlayCanvas.  You actually have to create two accounts, first is your over all account, the second is a developer account.  This is because PlayCanvas supports multiple concurrent developers working on and editing the same project.  It is however a premium feature.

 

Let’s talk about that for a second… what is premium and what is not?  PlayCanvas want to make money obviously, so let’s look at the tiers.  First off, the game engine is open source and available on Github.  However, not all of the tools like the content importer are.  I haven’t downloaded the engine locally, so I am unsure how much of an impact this has.  What is clear is the different tiers available.  As of today, the pricing looks like the following:

Pc2

 

There is a second tier entirely for organizations as well.

 

In a nutshell, the number one biggest drawback is going to be 0 private projects in the free version.  If you are developing a free and open source game, this is a non issue, but obviously if you are creating a private commercial game, you will need to create a private project.  Basically this means anyone can see your project, source, resources, etc with the free version.  The remaining differences boil down to disk space availability, number of team member accounts you can create and being able to export an iOS ready project.  Prices range from 15 - 60$ a month.

 

Everything you see today is from the free edition.  Other than iOS functionality, all versions contain the same feature set.

 

The Editor

 So once you’ve logged in and created a developer account, you should see a screen like this one:

Pc3

 

You can either create a new project from scratch, or start with one of the starter kits.  We are going to use a starter kit.  This is a pre-configured mini project to get you going. There are currently two starter projects available, a 3D model viewer and a platformer.  Let’s go with the later kit.  Since this is a free account, we have no options but to make the project Public.

 

Pc4

 

You will now be brought to the project management page.  

Pc5

 

Click the editor button and you will be brought to the guts of PlayCanvas, where you will be doing the majority of your work.  Click this button:

Pc5 5

 

The Editor

 

There are actually two editors currently available, the classic editor and a new beta editor.  You can toggle between them by selecting the Settings gear icon and choosing Use New Editor:

Pc6

 

Here are the two different editors.

 

New Beta Editor

Pc7

 

Classic Editor

Pc8

 

For this post I am going to stick with the standard production editor.

 

The layout has your scene graph/tree on the left hand side, your palette of assets across the bottom, and your properties/components across the right.  In the middle of course is your 3D Scene view.  If you prefer, you can switch to a traditional quad view mode:

Pc9

Obviously in the 3D view you can zoom, orbit and pan the camera, select and edit objects, etc.  You compose a scene by dragging it in from the Pack Explorer.   In addition to the Packs Explorer you see here, there is also an assets and a scripts one as well.

 

Press the Play icon and your game should start.  Below is an embed of the project ( after Publish from the Dashboard ):

 

 

Click the mouse to focus, used arrow keys to navigate and spacebar to jump.

 

So that’s creating an initial project… now let’s take a look at the developer experience.

 

Importing a 3D Model

 

This is always one of the most challenging aspects of working with a 3D engine… getting your content in it.  PlayCanvas makes it pretty simple, but I did run into some small hiccups.

 

First author your 3D object in your modelling app of choice.  Personally I am using Blender.  They supports FBX, COLLADA and 3DS formats, although FBX is highly recommended.  There are a few limits as well.  You need to embed textures in with your model ( or manually add them later, as we will see ), you have a 256 bone and 64K vertices limit per mesh.

 

I am going to create a very simple textured cube in Blender, like so:

Pc10

 

And then export as an FBX using the following settings, the important ones highlighted:

Pc11

 

Now the we have an FBX, we need to import it to PlayCanvas.  Next in the dashboard, go to the assets section and click New Asset:

Pc12

 

Then simply drag the FBX file from finder/explorer to the appropriate spot.

Pc13

 

Now if you look at the palette portion of the editor ( hit the refresh button top right corner of panel ) you should now see your object.  Simply drag one into the scene:

Pc14

 

And tada:

Pc15

 

In my case however, the texture is always missing.  I’ve tried different formatting options, going through FBX exporter and never had any luck.  It is however easily fixed.  Instead import your texture as an asset.  Then in 3D view, click your object so it is selected, click again so Material is selected in the Material Editor, select diffuse and assign your texture:

Pc16

 

I have to assume this is a bug, either in Blender’s FBX import, or the PlayCanvas Import, but it’s extremely simply fixed by manually assigning the material so no big deal.

 

Now you will see your object renders properly in the scene:

Pc17

 

Components

Like most modern popular engines, PlayCanvas is component based.  Basically you add functionality to game entities by attaching components.  Let’s take a look at the main character and how it’s composed.  This can be seen by selecting the Player in the Pack Explorer then looking at the Attribute editor:

Pc18

 

As you can see out Player is composed of a rigidbody, collision and script component.  Additionally you can see it’s got a child entity named model.  Model in turn has a animation and model component attached.  It is through this parenting and composition you make the objects that composed your game.

 

Adding a component to an entity is as simple as right clicking it and choosing Add Component:

Pc20a

 

You can similarly add a New Entity the same way, but instead choosing New Entity.

 

Pc20

 

You can of course create your own components and entities as well, but that goes way beyond what I intend to cover here.  You may have noticed the script component attached to the Player…  that segues nicely to...

 

Coding

As you probably expected, the coding language behind PlayCanvas is JavaScript.  Scripts are attached to entities as a component.  Here for example is code for input in the Player from the platform example:

// Player Input
// Handle input from a keyboard
// Requires:
// - The entity must also have the platform_character_controller script attached

pc.script.create('player_input', function (context) {
    var PlayerInput = function (entity) {
        this.entity = entity;
    };
    
    PlayerInput.LEFT = "left";
    PlayerInput.RIGHT = "right";
    PlayerInput.JUMP = "jump";
    
    PlayerInput.prototype = {
        initialize: function () {
            // Create a pc.input.Controller instance to handle input
            context.controller = new pc.input.Controller(document);
                    
            // Register all keyboard input
            context.controller.registerKeys(PlayerInput.LEFT, [pc.input.KEY_A, pc.input.KEY_Q, pc.input.KEY_LEFT])
            context.controller.registerKeys(PlayerInput.RIGHT, [pc.input.KEY_D, pc.input.KEY_RIGHT])
            context.controller.registerKeys(PlayerInput.JUMP, [pc.input.KEY_W, pc.input.KEY_SPACE, pc.input.KEY_UP])
    
            // Retrieve and store the script instance for the character controller
            this.playerScript = this.entity.script.platform_character_controller;
        },
        
        // Check for left, right or jump and send move commands to the controller script 
        update: function (dt) {
            if ( context.controller.isPressed(PlayerInput.LEFT) ) {
                this.playerScript.moveLeft();
            } else if ( context.controller.isPressed(PlayerInput.RIGHT) ) {
                this.playerScript.moveRight();
            }
            
            if (context.controller.wasPressed(PlayerInput.JUMP)) {
                this.playerScript.jump();
            }
        }
    };

   return PlayerInput;
});

 

As you can see, the code is also very modular in nature as well.  It’s clean and fairly well documented, we will get to that shortly.

 

As I mentioned earlier, there are a couple of approaches to code editing.  You can host your code in a Bitbucket or Github respiratory, edit using your editor of choice then sync it back.  Otherwise you can use the built-in code editor.  Let’s take a look at it:

Pc21

 

It has some of the features you would expect.  There is syntax highlighting, code folding and warning hints.  What however there is not is code completion… that’s a glaring missing feature IMHO.  It’s been requested and hopefully will be added soon.

 

The API is clean enough, the editor works, although for a large scale project you will most certainly want to use your own editor, I would certainly.  Although if they added intellisense/code competition, I would spend a lot more time in the web based editor instead of my own IDE.

 

Documentation

This is an area that can make or break a project.  I will say that PlayCanvas has very solid documentation.  As you saw above, there are two starter projects to get you going, a Platformer and 3D model viewer.

 

The documentation is entirely online including a User Manual, Reference and Tutorials:

Pc22

 

The documentation is clean, professional and for the most part as shown what I needed when I needed it.  The User Manual covers common concepts like importing models, etc…  but could certainly use a bit more depth.  There is a pretty solid collection of tutorials available:

Pc23

 

All told, documentation is a definite plus of this project.  Some quick links if you want to check it out:

User Guide

API Reference

Tutorials

 

The Video Version

 

 

Conclusion

 

PlayCanvas is an impressive 3D engine for those looking to work in HTML5.  The tools are comprehensive, the documentation is quite good, the pricing structure is reasonable and the code seems clean.  Let me know if this is an engine you want to see additional coverage of here on gamefromscratch.com.

Programming

Month List

DisqusCommentsSummary