1 of 38

Modern HTML5 Game Development With

Phaser.JS & TypeScript

Phaser.JS is a robust mobile and desktop game framework, distributed under the MIT open source licence, based on HTML5 Canvas and WebGL technologies that allow you to build once and deploy across all modern web enabled devices. This presentation goes over the basic workflow of getting up and running with Phaser.JS by presenting a simple game designed for this presentation. Even if you are not interested in making games, this platform is great for any applications that require complex user interactions.

Presented By: Andrew Ribeiro | Git: Andrewnetwork

2 of 38

3 of 38

PROLOGUE

ADOBE FLASH KILLED THE INTERNET

  • Introduced several vulnerabilities
  • Decreased performance
  • Acceptance of plugins
  • Proprietary
  • A terror for early smartphones

Savior: HTML5

  • No plugins!
  • All application functionality is provided by the browser.
  • Complete web applications platform.
  • Phaser brings out the power of the HTML5 stack for applications previously done not natively in the browser ( through plugins ).

Flash is a mess, Flash is a waste, Flash is a big fat mistake.

WANTED

DEAD

4 of 38

What you need to know-------------Prerequisites

  • Like any subject, you can tackle anything if you have the passion for it.
  • Essential To Know:
    • JavaScript or TypeScript( If you wish to use it )
    • Object Oriented Design
  • Good to Know:
    • Basics of Game Development
    • HTML5 Features.
    • A server side language/platform for data processing. ( PHP, ASP.NET, Node.js )

5 of 38

What we’re covering ----------------- overview

  • Prologue
  • Prerequisites
  • The HTML5 Game Landscape
  • TypeScript and JavaScript
  • About Phaser
    • Examples
    • Features
    • Pixi.js
    • Physics
  • Phaser Phases
    • preload,create,update, & render
  • Simple Example: Castlevania Loader
  • Advanced Example: TankGame
  • OpenGl
  • Deployment
    • Intel XDK
    • Cordova
    • Servers & Platforms
  • Resources
    • TypeScript
    • 3D Game Development
    • Phaser Examples
    • Misc
  • Questions & Comments

6 of 38

The HTML5 Game Framework/Engine Landscape

https://html5gameengine.com/

7 of 38

The HTML5 Game Framework/Engine Landscape

  • Easiest Game Engines($_$)
    • ImpactJS $99
    • Construct 2 $120
  • Open Source
    • Phaser
    • Babylon
    • Three.js
    • EaselJS ( Suite of tools. Mostly for ads )
  • Why Phaser though?
    • One of the largest and most passionate communities.
    • Great financing model ( Opinion ).
    • Great examples and documentation.
    • Rich toolset.
    • Cool name.
    • Company that is committed to innovation and community.
    • and...................................

8 of 38

The HTML5 Game Framework/Engine Landscape

It’s free.

It’s open source.

I know you’re cheap.

MIT not GPL... chill.

9 of 38

JavaScript &

  • Open source strict superset of JavaScript developed and maintained by Microsoft.
    • Adds optional static typing and class-based object-oriented programming to the language.
    • ( First version: October 1, 2012, Current: 1.8 / January 2016 )
  • TypeScript supports definition files.
    • This enables other programs to use the values defined in the files as if they were statically typed TypeScript entities
    • There are definition files for Phaser and Pixi.js
  • TypeScript is transcompiled to JavaScript.
  • Nice compile time type checking.
  • Free IDE: http://typecsdev.com/

10 of 38

What is PhaserJS?

Open source HTML5 game framework useful for developing cross platform 2D games or complex user interfaces for the web.

  • What phaser is not:
    • Not a 3D game engine.
      • Use BabylonJS
    • Does not support VR.
    • Not a standalone application.
  • Open Source Licence: MIT.

11 of 38

Phaser Features......................................1

  • Cross Platform WebGL and Canvas Rendering ( Pixi.js )
  • Simple Asset Preloading
  • Built in Physics Support
  • Sprites: tweens, movement, translation, collision, textures, responsive input, pixel perfect click detection.
  • Groups: grouping of sprites for pooling, recycling, and collision with custom callbacks.
  • Animation: sprite sheets, texture packing, JSON data.
  • Particles: easily create particle effects like explosions, constant streams like rain or fire.

12 of 38

Phaser Features......................................2

  • Camera: pan around and follow sprites in the built in game world easily.
  • Input: Multi-touch, mouse, keyboard support. Robust input management system.
  • Sound: Web Audio and legacy HTML Audio support. Simplifies dealing with mobile audio.
  • Tile Maps: CSV and Tiled-map data formats. Powerful tile manipulation: swap tiles, replace, delete, and update maps in realtime.
  • Device Scaling: allows you to scale your game to fit any size screen. Control aspect ratios, minimum and maximum scales and full-screen support.

13 of 38

Useful HTML5 Features

  • Connectivity
    • Web Sockets
    • Sever-sent events ( server can push events to client without request)
    • WebRTC
  • Offline & Storage
    • Application Cache
    • Web Storage
    • Indexed Database API
    • File API
    • Offline and Online Events
  • Performance & Misc
    • Web Workers
    • Fullscreen API
    • Pointer Lock API
    • Orientation Detection

14 of 38

Phaser Examples...........................Be creative!

Bubble Burst Bernie

15 of 38

Phaser Examples...........................Be creative!

Ramp Lab 1.3

Physics Simulation

16 of 38

Phaser Examples...........................Be creative!

Bridge Color Race

Mobile Game

17 of 38

Phaser Examples...........................Be creative!

Rival Command

18 of 38

Pixi.js............................PhaserJS Rendering

  • Multi-Platform 2D webGL renderer with canvas fallback.
    • Seamless canvas fallback means that you really can author once, and then deploy everywhere – in browser.
  • Multi-touch support.
  • WebGL filters.
  • Tinting and Blend Modes
  • Sprite Sheets
  • Scene Graph
    • Hierarchical arrangement of items.
  • The backed of PhaserJS.
  • https://pixijs.github.io/examples/

19 of 38

Physics Engines

  • Arcade Physics
    • An extremely light-weight AABB(collision detection) library perfect for low-powered devices.
  • Ninja Physics
    • Ninja Physics. The Ninja Physics system was created in Flash by Metanet Software and ported to JavaScript by Richard Davey. It allows for AABB and Circle to Tile collision. Tiles can be any of 34 different types, including slopes, convex and concave shapes.
  • P2.js
    • A full-body system with springs, constraints and advanced polygon support.
  • Box2D
    • Available as a premium plug-in, but there are free sources.

20 of 38

Phaser Phases..................................preload

  • preload() is called first. Normally you'd use this to load your game assets (or those needed for the current State) You shouldn't create any objects in this method that require assets that you're also loading in this method, as they won't yet be available.

21 of 38

Phaser Phases...................................CREATE

  • The constructor for the game state.
  • create() is called once preload has completed, this includes the loading of any assets from the Loader. If you don't have a preload method then create is the first method called in your State.

22 of 38

Phaser Phases........................UPDATE & Render

  • State.render()
    • Called once per requestAnimationFrame.
    • Nearly all display objects in Phaser render automatically, you don't need to tell them to render. However the render method is called AFTER the game renderer and plugins have rendered, so you're able to do any final post-processing style effects here. Note that this happens before plugins postRender takes place.
  • State.update()
    • Called game.time.desiredFps times per second (desiredFps is 60 by default).
    • Called during the core game loop AFTER debug, physics, plugins and the Stage have had their preUpdate methods called. Called BEFORE Stage, Tweens, Sounds, Input, Physics, Particles and Plugins have had their postUpdate methods called.
  • You can typically put all your update code in the update() function, but you will want to investigate if you can place it in render() as your game grows larger.

23 of 38

Simple Example: Castlevania Loader.............States

  • We can create modular game elements by using states.
  • Castlevania Loader States
    • Boot
    • Preloader
    • Main Menu
    • Level1
  • We start the game by starting the

  • Each state has its own phases.

Boot state.

Code: Basics/AdvancedPhaserSetup

24 of 38

TankGame...............................in typescript

Look at the Code

  • Uses arcade physics
  • Port of the JS EX

Code: TankGame

25 of 38

WebGl Filters

  • Phaser’s rendering engine, Pixi.JS, supports OpenGl shaders.
    • Phaser an Pixi calls shaders “filters.”
  • See the built-in filters here: http://www.goodboydigital.com/pixijs-webgl-filters/
  • WebGL support is the reason I’ve labeled this talk “Modern.”
  • They are also stackable and nestable so a sprite can have multiple webGL filters attached to it with another sprite inside it with multiple webGL filters on that.
  • See example: WebGL/Shaders_Filters/WebGL_PlaneDeformation/

26 of 38

PHASER

Deployment

27 of 38

Cordova

  • Cordova wraps your HTML/JavaScript app into a native container which can access the device functions of several platforms. These functions are exposed via a unified JavaScript API, allowing you to easily write one set of code to target nearly every phone or tablet on the market today and publish to their app stores.

28 of 38

Intel XDK..........................................................................1

  • All-in-one development environment to easily simulate, test, tune, and deploy games to many app stores using one code base.
  • Game engine support for Construct2, Cocos2D, Phaser, Pixi.js*, and Easel.JS to easily import assets and code.
  • The Intel XDK Game Asset Manager provides a central place to view game assets, including viewing animation (if any) and details. The Game Asset Manager also generates a code snippet for each selected asset that you can use to help you develop your HTML5/JavaScript/CSS game sources.

29 of 38

Intel XDK...........................................2

  • Google Play Game Services and Apple Game Center services support to drive engagement, socialize, and reward players.
  • W3C Gamepad API support enables high-impact game interaction using gamepad or joystick devices
  • Apache Cordova plugins and APIs to monetize and market action-packed multi-OS games
  • Works with Cordova
  • “Easy Path to HTML5 App Development, Fast Path to Multi-OS App Stores”

30 of 38

Aws,Heroku,Web Servers.......Where to put your stuff

What do you use to host your web applications?

31 of 38

RESOURCE

Really awesome categorized source code examples.

32 of 38

RESOURCE

An online sandbox for running phaser code.

33 of 38

Phaser TypeScript Tutorials

RESOURCE

http://phaser.io/tutorials/how-to-use-phaser-with-typescript

Part 1

http://www.photonstorm.com/phaser/advanced-phaser-and-typescript-projects

Part 2

34 of 38

Misc Resources (1)

RESOURCE

Name

URL

Note

AABB

Collision Detection

p2.js

Advanced Physics 2D Lib

Physics Sys Compared

Which physics system should I use?

Arcade Physics

Basic Physics

Particles

Particle Examples

BabylonJS

HTML5 3D Game Dev

35 of 38

Misc Resources (2)

RESOURCE

Name

URL

Note

ThreeJS

3D WebGL Renderer

OpenGL Sandbox

Different OpenGL shaders you can repurpose for use in your game.

ShaderToy

More code for OpenGL shaders.

TLDR Legal

Understand the licence this software is distributed under.

Udacity HTML5

A free HTML5 game development course taught by google.

36 of 38

Misc Resources (3)

RESOURCE

Name

URL

Note

ZebraJS

http://www.zebkit.com/

Canvas UI

Box2D JS

http://box2d-js.sourceforge.net/index2.html

JS version of Box2D.

TypeScript

https://en.wikipedia.org/wiki/TypeScript

A history of TypeScript

EZGUI

https://github.com/Ezelia/EZGUI

A UI framework that’s made for phaser.

HTML5 Game Dev Forums

http://www.html5gamedevs.com/

Great forum for different html5 frameworks.

Phaser Mobile

https://hacks.mozilla.org/2015/12/from-game-jam-to-mobile-and-firefox-os/

Notes on how to make a Phaser game across multiple platforms.

37 of 38

Misc Resources (4)

RESOURCE

Name

URL

Note

Cordova + Phaser Tutorial

https://software.intel.com/en-us/html5/hub/blogs/how-to-make-a-mobile-virtual-pet-game-with-html5-and-cordova/

How to use the cordova api with phaser to make mobile apps.

Cordova

https://cordova.apache.org/

Formerly phonegap.

38 of 38

QUESTIONS& COMMMENTS

Presented By: Andrew Ribeiro

AndrewRIB.com

AndrewNetwork@gmail.com

FIND THIS PRESENTATION ONLINE:

https://github.com/Andrewnetwork/PhaserPresentation2016