Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

22. June 2015


Export to web has been a popular bullet point on most game engine feature lists as of late.  Both Unreal Engine and Unity recently offered native HTML5 export (Unity has had a plugin option for years, but plugins have gone the way of the Dodo).  LibGDX has offered a HTML5 target for ages, Haxe based game engines can all cross compile to HTML or Flash.  GameMaker, Construct, Stencyl and more have HTML5 exporters.   Of course, there are a number of HTML5 native engines (I suppose Construct should be on that list actually…), but they aren’t really what this conversation is about.


At the end of the day though… is anyone actually doing it?  Is there a “shipped” title from any of these engines that people are playing in any quantity?  It is my understanding that the vast majority of commercial web and Facebook games are still Flash based, with HTML5 representing perhaps 10-20% of titles.  More importantly, most of these titles are relatively simple, nothing harnessing a fraction of the power of an Unreal or Unity type engine.


It leads me to question, is HTML5 a feature everybody wants but nobody uses?


What inspired this thought was this interesting article on Godot’s efforts to target the web.  I have been actively monitoring the game development world during the entire timespan Juan described and I witnessed all of these “next big thing” technologies that came and went.  Summarized from the article, they were:

  • Native Plugins
  • Google Native Client
  • Flash
  • ASM.js
  • WebAssembly


This is by no means a comprehensive list, LibGDX compiles from Java to JavaScript using Google’s GWT for example, and some of these technologies were certainly successful for a time such as Flash.  Of course too, games written and targeted for HTML5 exist.  It’s this whole HTML5 as an additional target approach that I am beginning to think is just a gimmick.  The funny part is, I love the idea too… I evaluate a lot of game engines and I always see “HTML5 export” and think “ooooh, that’s good”.


Games in the browser certainly seemed to have a brilliant future at one point.  The Unity web plugin really did bring Unity to the web.  I used a couple of Unity powered 3D tools, such as Mixamo, and it was very near to native in experience (they have since ported to HTML5 since the Unity plugin was end of life-d).  Google’s Native Client (NaCL) had some promise, with shipped titles such as AirMech leading the way, but a single browser solution was never going to fly.  Ultimately Flash, especially with it’s promising (at the time) 3D API had the most promise, but a combination of Apple’s malevolence and Adobe’s incompetence brought that to an inglorious end.


Perhaps it’s just ignorance on my end.  Can anyone out there point me at an HTML5 game (not a tech demo, an actual game) created in either Unity or Unreal Engine?  I realize both are fairly new, so I would also settle for examples that are under development but show promise.  Keep in mind here, I’m not talking about HTML5 game engines, there certainly is a future in HTML5 games and of course they can be wrapped and deployed to a variety of platforms.  No, it’s “HTML5 as an additional target platform” support that seems to be pure gimmick at this point.

Totally Off Topic

29. March 2015


The popular HTML5 library Phaser have just released 2.3.  It’s not a huge new functionality release, but it’s got some major architecture changes that will affect you greatly if you are a Phaser user.  First off, they went down a more modular approach leading to fewer god classes.  This is aPhaser 2.3.0 good thing™.  Then thanks to this redesign, they also made the Phaser build process different, allow you to disuse unneeded portions.


From the release notes:


Significant Updates



All of the core Game Objects have received an important internal restructuring. We have moved all of the common functions to a new set of Component classes. They cover functionality such as 'Crop', 'Physics Body', 'InCamera' and more. You can find the source code to each component in the src/gameobjects/components folder of the repo.

All of the Game Object classes have been restructured to use the new component approach. This puts an end to the "God classes" structure we had before and removes literally hundreds of lines of duplicate code. It also allowed us to add features to Game Objects; for example Bitmap Text objects are now full-class citizens with regard to physics capabilities.

Although this was a big internal shift from an API point of view not much changed - you still access the same methods and properties in the same way as before. Phaser is just a lot leaner under the hood now.

It's worth mentioning that from a JavaScript perspective components are mixins applied to the core game objects when Phaser is instantiated. They are not added at run-time or are dynamic (they never get removed from an object once added for example). Please understand that this is by design.

You can create your own custom Phaser classes, with your own set of active components by copying any of the pre-existing Game Objects and modifying them.



As a result of the shift to components we went through the entire source base and optimised everything we could. Redundant paths were removed, debug flags removed and new stub classes and hooks were created. What this means is that it's now easier than ever to "disable" parts of Phaser and build your own custom version.

We have always included a couple of extra custom builds with Phaser. For example a build without P2 Physics included. But now you can strip out lots of additional features you may not require, saving hundreds of KB from your build file in the process. Don't use any Sound in your game? Then you can now exclude the entire sound system. Don't need Keyboard support? That can be stripped out too.

As a result of this work the minimum build size of Phaser is now just 83KB (minified and gzipped).

Please see this tutorial on how to create custom builds.



We've updated the core of Arcade Physics in a number of significant ways.

First we've dropped lots of internal private vars and moved to using non-cached local vars. Array lengths are no longer cached and we've implemented physicsType properties on Game Objects to speed-up the core World collideHandler. All of these small changes have lead to a nice improvement in speed as a result, and also allows us to now offer things like physics enabled BitmapText objects.

More importantly we're now using a spacial pre-sort for all Sprite vs. Group and Group vs. Group collisions. You can define the direction the sort will prioritize via the new sortDirection property. By default it is set to Phaser.Physics.Arcade.LEFT_RIGHT. For example if you are making a horizontally scrolling game, where the player starts on the left of the world and moves to the right, then this sort order will allow the physics system to quickly eliminate any objects to the right of the player bounds. This cuts down on the sheer volume of actual collision checks needing to be made. In a densely populated level it can improve the fps rate dramatically.

There are 3 other directions available (RIGHT_LEFT, TOP_BOTTOM and BOTTOM_TOP) and which one you need will depend on your game type. If you were making a vertically scrolling shoot-em-up then you'd pick BOTTOM_TOP so it sorts all objects above and can bail out quickly. There is also SORT_NONE if you would like to pre-sort the Groups yourself or disable this feature.

Another handy feature is that you can switch the sortDirection at run-time with no loss of performance. Just make sure you do it before running any collision checks. So if you had a large 8-way scrolling world you could set the sortDirection to match the direction the player was moving in and adjust it in real-time, getting the benefits as you go. My thanks to Aaron Lahman for inspiring this update.



The Phaser.Loader has been updated to support parallel downloads which is now enabled by default (you can toggle it via the Loader.enableParallel flag) as well as adding future extensibility points with a pack/file unified filelist and an inflight queue.

There are no known incompatibilities with the previous Loader. Be aware that with parallel downloading enabled the order of the Loader events may vary (as can be seen in the "Load Events" example).

The parallel file concurrency limit is available in Loader.maxParallelDownloads and is set to 4 by default. Under simulated slower network connections parallel loading was a good bit faster than sequential loading. Even under a direct localhost connection parallel loading was never slower, but benefited most when loading many small assets (large assets are more limited by bandwidth); both results are fairly expected.

The Loader now supports synchronization points. An asset marked as a synchronization point must be loaded (or fail to load) before any subsequent assets can be loaded. This is enabled by using the withSyncPoint and addSyncPoint methods. Packs ('packfile' files) and Scripts ('script' files) are treated as synchronization points by default. This allows parallel downloads in general while allowing synchronization of select resources if required (packs, and potentially other assets in the future, can load-around synchronization points if they are written to delay final 'loading').

Additional error handling / guards have been added, and the reported error message has been made more consistent. Invalid XML (when loading) no longer throws an exception but fails the particular file/asset that was being loaded.

Some public methods/properties have been marked as protected, but no (except in case of a should-have-been-private-method) public-facing interfaces have been removed. Some private methods have been renamed and/or removed.

A new XHR object is created for each relevant asset (as there must be a different XHR for each asset loaded in parallel). Online searches indicated that there was no relevant benefit of XHR (as a particular use-case) re-use; and time will be dominated with the resource fetch. With the new flight queue an XHR cache could be re-added, at the cost of some complexity.

The URL is always transformed through transformUrl, which can make adding some one-off special cases like #1355 easier to deal with.

This also incorporates the fast-cache path for Images tags that can greatly speed up the responsiveness of image loading.

Loader.resetLocked is a boolean that allows you to control what happens when the loader is reset, which happens automatically on a State change. If you set resetLocked to true it allows you to populate the loader queue in one State, then swap to another State without having the queue erased, and start the load going from there. After the load has completed you could then disable the lock again as needed.

Thanks to @pnstickne for vast majority of this update.



We are now using our own custom build of Pixi v2. The Pixi project has moved all development resources over to Pixi v3, but it wasn't ready in time for the release of Phaser 2.3 so we've started applying our own fixes to the version of Pixi that Phaser uses.

As a result we have removed all files from the src/pixi folder that Phaser doesn't use, in order to make this distinction clearer. This includes EventTarget, so if you were relying on that in your game you'll need to add it back in to your local build.

We've also removed functions and properties from Pixi classes that Phaser doesn't require: such as the Interaction Manager, Stage.dirty, etc. This has helped us cut down the source code size and make the docs less confusing, as they no longer show properties for things that weren't even enabled.

We've rolled our own fixes into our version of Pixi, ensuring we keep it as bug-free as possible.

You can read the entire release notes here.

Programming, News ,

12. March 2015


I’ve long been a fan of the Phaser HTML5 game library, as my ongoing tutorial series might indicate.  Somewhat recently Phaser started adding premium commercial plugins.  The most recently added plugin adds support for Box2D, the popular 2D physics based library.  This is a commercial plugin (aka, you’ve got to pay for it.  $65 for premium $45 for standard – only difference is number of samples ), but don’t fret, Phaser still has a number of physics systems built-in that are completely free.


Box2D is a feature-rich 2D physics system used by thousands of hit games.

This plugin opens-up the power of Box2D directly within Phaser. It has the same user-friendly approach to its API that the rest of Phaser does, making integration and game development a beeze.


It uses the excellent box2d-html5 JavaScript port by Isaac Burns. We found that this library had the best performance of those tested, even on mobile.

Development of the plugin was lead by Box2D experts iForce2D - the company responsible for the excellent Box2D visual editor R.U.B.E


See the Box2D Plugin Page for More Details


The Download includes

  • Getting Started Guide - You'll be coding in next to no time.
  • 90 Code Examples - From games to core mechanics.
  • API Documentation and Box2D User Manual
  • Free Upgrades
  • License free - Use it in commercial games
  • Ready built and minified source files + grunt scripts
  • Delivered via download from

Try it out

We've added 40 of the Box2D examples to this site.

Run them, play with them and edit the code to get a feel for how it all works.


The full release details are available here.


I actually like to see this form of monetization.  Developers need to eat and we want  them working to make better and better products.  Keeping the core free while adding premium but optional features as a premium plug-in seems like a good middle line to me.  The key is to keep developing the core free product at the same rate that commercial plugins are added.

News , ,

11. March 2015


Copperlicht, a somewhat recently open sourced WebGL game engine has just released version 1.9.


Release notes are, shall we say…  terse.  Here they are in the entirity from the Copperlicht forums.


CopperLicht 1.9 is now available for download. Get it here:

Added support for realtime reflecting water surfaces, rendering to textures, inverting the depth test, shader callbacks, pointer lock, and more clearly rendered 2D Overlays.

Have fun with it!


Although the archive itself has slightly more detailed release notes:


CopperLicht 1.9

- Added realtime reflecting water surfaces.
  There is now a special scene node which renders water surfaces, which can be used to create rivers,
  lakes, and oceans. It is highly configurable, so it can be used to create various,
  realistic looking water surfaces.
- Added support for rendering to textures.
  See CL3D.Renderer.setRenderTarget() and CL3D.Renderer.addRenderTargetTexture() for this.

- Added support for inverting the depth test.
  See CL3D.Renderer.setInvertedDepthTest() for this.
- Introduced the option to use callbacks for shader settings constants when creating your own materials.

- Full screen with pointer lock now works again on Chrome. Previously, this stopped working
  after Google changed their implementation.

- Fixed 3D sound node to play sound looped even if set to 'play once'


Copperlicht is from (one of the?) creator of the popular IrrLicht game engine.  They also have a number of other tools available, such as the CopperCube world editor and irrKlang a cross platform audio library.  It’s one of those products I’ve intended to take a closer look at for some time.

News , ,

15. January 2015


I’ve been doing a long running Phaser with TypeScript tutorial series that illustrates basically everything you need to know to create a complete game using the Phaser HTML5 game engine.  I decided to put together a video tutorial showing how to put it all together to make a complete game.


Now, keep in mind, the game is incredibly simple… I wanted to keep the entire thing to under an hour after all ( I failed, it’s an hour and a half ), so I had to keep the scope reasonable in size.  So as a result I’ve created Extreme Walking Simulator!  Yeah, you walk… and that’s it actually.  You walk forever and ever in front of the same looping background.  However, you are left with a complete but simple game but most importantly, a framework of code that can be expanded upon to build much more complex games.  It also illustrates program flow, drawing sprites, playing music, changing states, handling input and all the other things a “full” game has to do.


In addition to the code, all of the assets used are available on GitHub.  This includes my incredible title music, the Blend files used for the main character and the level scene.  Everything you need to create this game is there in the Assets folder.  Feel free to play around and use it however you want.  That said, the textures just came from Google Image Search, so no clue if there is a copyright on any of them, so don’t use them in a commercial project! I believe all of my Github stuff is set to Creative Commons license…  if it’s not, assume you can do anything you want with it and that you have absolutely no warranty.


Ok, enough preamble, let’s jump right in!  The tutorial is available in two parts on YouTube in 1080p ( or embedded below):



Following are the game itself, then the source listings, finally the two videos in an embedded player.




EDIT: Removed to prevent music auto playing, to play the game click here instead. Warning, loud


  • Click the title screen to get started
  • Tap right arrow to start walking/speed up
  • Tap left arrow to slow down/stop
  • Press ESC to stop the torture!



The Source Code



<!DOCTYPE html>

<html lang="en">
    <meta charset="utf-8" />
    <title>Hello Phaser</title>
    <link rel="stylesheet" href="app.css" type="text/css" />
    <script src="phaser.js"></script>
    <script src="GameObjects/MyScene.js"></script>
    <script src="GameObjects/Player.js"></script>
    <script src="States/TitleScreenState.js"></script>
    <script src="States/GamePlayState.js"></script>
    <script src="States/GameOverState.js"></script>
    <script src="app.js"></script>
    <div id="content"></div>



module Game {
    export class ExtremeWalkingSimulator {
        game: Phaser.Game;

        constructor() {
   = new Phaser.Game(1280, 720, Phaser.AUTO, 'content', {
                create: this.create, preload: this.preload

        preload() {
            // Graphics
  "title", "Graphics/TitleScreen.png");
  "scene", "Graphics/scene720p.png");
  "gameover", "Graphics/GameOver.png");

  "HERO_WALKING", "Graphics/Hero_Walking.png", "Graphics/Hero_Walking.xml");
  "HERO_IDLE", "Graphics/Hero_Idle.png", "Graphics/Hero_Idle.xml");

            // Audio
  "TitleSong", ["Sounds/TitleSong.mp3", "Sounds/TitleSong.ogg",
"Sounds/TitleSong.wav"]); } create() {"TitleScreenState", GameFromScratch.TitleScreenState, true);"GamePlayState", GameFromScratch.GamePlayState, false);"GameOverState", GameFromScratch.GameOverState, false); = Phaser.ScaleManager.SHOW_ALL; } } } window.onload = () => { var game = new Game.ExtremeWalkingSimulator(); };



module GameFromScratch {
    export enum PlayerState { IDLE, WALKING }

    export class Player extends Phaser.Sprite {
        game: Phaser.Game;
        playerState: PlayerState;
        RIGHT_ARROW: Phaser.Key;
        LEFT_ARROW: Phaser.Key;
        ESCAPE: Phaser.Key;
        walkingSpeed: number;

        public static MAX_SPEED: number = 30;

        constructor(game: Phaser.Game, x: number, y: number) {
   = game;

            this.walkingSpeed = 0;

            //Wire up input handlers
            this.RIGHT_ARROW =;
            this.RIGHT_ARROW.onDown.add(Player.prototype.MoveRight, this);

            this.LEFT_ARROW =;
            this.LEFT_ARROW.onDown.add(Player.prototype.MoveLessRight, this);

            this.ESCAPE =;
            this.ESCAPE.onDown.add(Player.prototype.GameOver, this);
            super(game, x, y, "HERO_WALKING", 0);

            this.anchor.set(0.0, 1.0);

        update() {
            if (this.playerState == PlayerState.WALKING) {
                this.x += (this.walkingSpeed / Player.MAX_SPEED) * (60 /;

                // This logic depends on scene being added first.
                var stageWidth =;
                if (this.x > stageWidth * .75)
                    this.x = stageWidth * .25;

        // Worse function name ever!
        MoveLessRight() {
            if (this.playerState != PlayerState.IDLE) {
                if (this.walkingSpeed > 0)
                    this.animations.currentAnim.speed = this.walkingSpeed;

        MoveRight() {
            if (this.playerState == PlayerState.IDLE) {
            else {
            if (this.walkingSpeed < Player.MAX_SPEED)
                this.animations.currentAnim.speed = this.walkingSpeed;

        StartWalking() {
            this.playerState = PlayerState.WALKING;
            this.walkingSpeed = 5;
            this.loadTexture("HERO_WALKING", 0);
  "walk", this.walkingSpeed, true);

        StartIdle() {
            this.loadTexture("HERO_IDLE", 0);
            this.playerState = PlayerState.IDLE;

        GameOver() {




module GameFromScratch {

    export class MyScene extends Phaser.Sprite {
        game: Phaser.Game;
        nextFrame: Phaser.Sprite;

        constructor(game: Phaser.Game, x: number, y: number) {
            super(game, x, y, "scene", 0);
            this.nextFrame = new Phaser.Sprite(, this.width, 0, "scene", 0);



module GameFromScratch {
    export class TitleScreenState extends Phaser.State {
        game: Phaser.Game;
        music: Phaser.Sound;

        constructor() {

        titleScreenImage: Phaser.Sprite;

        preload() {

        create() {
            this.titleScreenImage = this.add.sprite(0, 0, "title");
this.titleScreenImage.height); ="TitleSong"); = 100; = true;; this.input.onTap.addOnce(this.titleClicked, this); } titleClicked() {;"GamePlayState"); } } }



module GameFromScratch {
    export class GamePlayState extends Phaser.State {
        game: Phaser.Game;
        player: GameFromScratch.Player;
        myScene: GameFromScratch.MyScene;

        constructor() {

        preload() {
        create() {
            this.myScene = new MyScene(, 0, 0);
            this.player = new Player(, 0, - 50);


  ,0,this.myScene.width * 2, this.myScene.height);



module GameFromScratch {
    export class GameOverState extends Phaser.State {
        game: Phaser.Game;
        gameOverSprite: Phaser.Sprite;

        constructor() {

        preload() {
        create() {
            this.gameOverSprite = this.add.sprite(0, 0, "gameover", 0);
            this.gameOverSprite.scale.setTo( / this.gameOverSprite.width, /
this.gameOverSprite.height); this.input.onDown.add(() => {"TitleScreenState", true); }, this);; } } }




The Videos


Part One:


Part Two:

Programming , , , , ,

Month List

Popular Comments