Download and use Chrome or Firefox to view this presentation.

From Flash To HTML5

by James Florentino

@jamesflorentino

I'm here to talk about my little personal project


A turn-based game built in HTML5


screenshot

But before anything else, let me tell a bit about myself...

I do front-end design and development as a profession and I develop games as a hobby.


Spent 8 years doing Flash Development.

But has now fully migrated to HTML5 and JavaScript.


Wings of Lemuria is a small personal project I started way back in 2009 as something to do in my spare time.

Initially made the prototype in Flash using ActionScript 3.0.

First problems encountered

Improving performance


Blitting is a traditional technique used in game development, where you copy pixels and paint it over a bitmap canvas.

Pre-rendered sprites

Copy the pixel data and store them to a vector array.

Bitmap Canvas

Paint it over to the main canvas

Made another prototype using the blitting technique.


Initial results

However... (uh-oh)

Blitting in Flash doesn't allow you to do bitmap data manipulation like scaling or rotation using bitmapData.copyPixels.

First look at HTML5

Features in HTML5 that attracted me as a Flash Developer

Decided to write a quick prototypewith the Canvas 2D API. Using the same game assets that I had before.

Initial results

JavaScript is a scripted language which means the code doesn't need to compile.

Which sometimes is a double-edged sword.

I decided to build my game in HTML5.

Because Flash was becoming irrelevant to the modern web

Tools of the trade

The CreateJS Suite

Preparing Game Asssets

I still prefer making the animations in the Flash IDE because of familiarity. Thankfully, CreateJS's Zoe can read SWF files and export them as JSON and PNG which can be used in EaselJS's SpriteSheet class as frame data.

Animating in Flash


Sprite Sheet Output


Writing the game client in JavaScript

Basic AMD usage


define(
  moduleId,
  dependencies,
  definition
);

AMD example


define(
  'game',
  ['my-class'],
  function(MyClass) {
    var myClass = new MyClass();
  }
});

Entity Component System


This allows me to create a more de-coupled game architecture without the need of complex OOP.

var entity = factory.create([components]);

Example usage


Entities are objects that interact with the game.

/** entity magic training **/
var wizard = entity.create('Magic');
/** entity with swordsmanship training **/
var swordsman = entity.create('Sword');
/** entity with both magic and sword training **/
var jedi = entity.create('Sword', 'Magic');
/** a jedi entity that succumbed to the dark side **/
var sith = entity.create('Sword', 'Magic', 'DarkSide');

Defining components


Attaching components to entities exposes new sets of APIs.

components.register('Magic', function(entity) {
    entity.firaga = function(enemy) {
      enemy.hp--;
      enemy.burning = true;
    }
    entity.thundaga = function(enemy) {
      enemy.hp--;
      enemy.paralyzed = true;
    }
  });
var toon = factory.create();
var mage = factory.create('Magic');
/** toon takes a damage and is in burning state! **/
mage.firaga(toon);
/** toon takes a damage and is paralyzed! **/
mage.thundaga(toon);

Build the user-interface outside of Canvas

About CSS pre-processors

Stylus and Nib

Final thoughts

Thank you for listening!

Follow me on Twitter @jamesflorentino

or read my blog for random front-end dev tips blog.jamesflorentino.com

If you're looking for a link to my game, it's still a work in progress. You can however subscribe to its Facebook page to get updated once it's out.

Use a spacebar or arrow keys to navigate