HTML5 & JavaScript Games


Published on

During this intimate lunchtime session, Rob Hawkes will bring you up to speed with the HTML5 and JavaScript game development scene. He'll show off some of the best games that are already out there, highlight the key lessons that he's learnt, and highlight the technologies and game engines that you need to be looking at. Interested in making games on the Web? Definitely don't miss this talk.

Published in: Technology, Design
1 Comment
  • Given that the spec is far from being fully implemented, It is pretty amazing what people have been doing with HTML5 when it comes to games. I am working on creating an HTML5 only game portal ( ) where you can see what indie developers have been coming up with.
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

HTML5 & JavaScript Games

  1. 1. Introductions…Hi, I’m Rob Hawkes and I’m here today so we can explore gaming with HTML5 and JavaScript.
  2. 2. For those who don’t know much about about me…I’m a Technical Evangelist at Mozilla, which means that it’s my job to engage with developersabout cool new technologies on the Web.
  3. 3. 1ST-CLASS HONOURS Interactive Media ProductionAnd as of 4am this morning (midday in the UK) I found out that I achieved a First-classHonours in the university degree that I’ve been studying for the past three years.Which has certainly helped make all the time and effort feel a little more worth while!But I digress…
  4. 4. All of this means that I have a slight addiction to experimentation and mucking about withcode, particularly if it involves anything visual, or HTML5…And for those of you who doubt my dedication to HTML5…A while ago my girlfriend made me this chicken and leek pie with the HTML5 logo on top(which was delicious).It’s HTML… Pive… get it?
  5. 5. I don’t actually remember when I first started playing games, although I know that I startedwith consoles… ZX Spectrum…
  6. 6. …SNES…
  7. 7. Megadrive, etc.
  8. 8. And spread throughout that time I dabbled in PC gaming, starting with games like Sim City…
  9. 9. …Megarace…
  10. 10. And playing Doom at my Dad’s Internet cafe.What I’m getting at here is that gaming has been a big part of my life growing up, as it hasbeen with a lot of other people as well.They’re fun to play, and they’re surprisingly fun to make.
  11. 11. THE TIME IS NOW Threshold of something coolAnd we’re now on the threshold of something cool, being able to create awesome andaddictive games with nothing more than the technologies that we normally used to makewebsites with.
  12. 12. NOTABLE EVENTS Recent events in HTML5 gamingFunding for HTML5 games companies.Acquisition of HTML5 gaming engines, like Aves by Zynga, and Rocket Engine by Disney.First large-scale HTML5 gaming conference this September, onGameStart in Poland.Another large gaming conference announced in the last few days for the San Francisco areathis November, it’s called New Game and it looks promising.Facebook getting involved in HTML5 gaming performance.
  13. 13. * made by Phil Banks (@emirpprime)So why is HTML5 gaming so cool?Because we can now use the technologies within the browser to make fast and enjoyablegames.And just to clarify, by HTML5 Im referring to HTML5 and JavaScript.
  14. 14. WRITE ONCE Use anywhereAny device with a browser that supports HTML5 will run your game code, after all it’s justJavaScript and HTML.You may have to implement little differences for variations in controls, like touch on mobiledevices, but the majority of the code will remain the same.
  15. 15. NO COMPILATION Save time with development and testingDoesnt require compiling, so development and testing can be extremely rapid.These technologies encourage a culture of hacking stuff together quickly to experiment, thentidying things up later – or perhaps thats just me.Either way, I like the rapid nature that JavaScript and HTML brings.
  16. 16. LIGHTWEIGHT Text and image files take up little roomJavaScript and HTML are just text files and images, which dont take up much room.
  17. 17. OPEN DEVELOPMENT Gives you a warm fuzzy feelingIt gives you a warm fuzzy feeling inside to be using open technologies
  18. 18. But it’s not all rosy with HTML5, why would you not want to use it?Here are just two of the major issues that are floating around right now.
  19. 19. FULL COMPATIBILITY Not all browsers support everythingNot every browser supports every part of HTML5.For example, canvas isn’t supported out of the box by any IE below 9. Although, you can useExplorerCanvas to replicate canvas functionality, but it’s not ideal and as doesn’t perform aswell.WebSockets still isn’t supported by IE yet, nor is it supported in Android. But again, you canfake this by using Flash for the sockets, like with Socket.IO.WebGL also has patchy support, with absolutely no support in current versions of IE, Safari,and Opera.
  20. 20. NO DRM These technologies aren’t made for itIf you need DRM or have a burning desire to hide absolutely everything about your code.Remember, the code isn’t compiled, so where would the DRM go? The beauty of Webtechnologies is that they can be read as plain text by simply viewing the page source.However, DRM isnt bulletproof in itself – you can still crack into Flash.You can still obfuscate and minify your code if you think it will help.
  21. 21. TECHNOLOGY Some of the tech involved in Web gamingSo there are a variety of technologies that are involved in HTML5 game development.In case I haven’t made it obvious by now, all of these technologies are related to HTML orJavaScript.
  22. 22. CANVAS & WEBGL 2D and 3D graphicsCanvas for 2D graphics.WebGL, which uses the canvas, for 3D graphics.
  23. 23. HTML5 AUDIO Sound effects and background musicHTML5 audio for game sound effects and background music.
  24. 24. WEBSOCKETS Multiplayer communicationWebSockets are used for bi-directional communication between a client (the player) and aserver.By managing communication on the server you can create multiplayer games with relativeease.
  25. 25. NODE.JS JavaScript on the serverNode is only really applicable if you’re making multiplayer games, as you’ll need a server tocommunicate with.JavaScript on the server.Asynchronous, event-based.Great third-party modules, like Socket.IO for WebSockets.
  26. 26. LOCAL STORAGE Storing data on the player deviceLocal Storage is great for storing data locally on the player device.This way you can cache game data and allow the game to pick up where the player left off.
  27. 27. MONGODB & REDIS Storing data on the serverMongoDB and Redis are two examples of ways to store data remotely on the game server.MongoDB is a document-oriented database, what’s often referred to as NoSQL.Redis is a key-value data store and is much less structured than MongoDB, but it stores datain memory which makes it super fast.
  28. 28. EXISTING GAMES Some of my favourite and best examplesThere aren’t a huge amount of HTML5 games just yet, but I thought I’d show you a selectionof my favourites.
  29. 29. QUAKE II Google port using Web technologiesMultiplayer Quake II remake with Google GWT (Google Web Toolkit)Canvas & WebGLHTML5 audioWebSocketsLocal Storage
  30. 30. MINECRAFT We’ll see this fully working in JavaScript soonMinecraft map viewer, using WebGL.This isn’t really a game, but it’s not a long way from becoming a JavaScript port of Minecraft.
  31. 31. WORD² Massively multiplayer ScrabbleWord², massively multiplayer Scrabble.Uses WebSockets for real-time communication.
  32. 32. I love the map view.Every single pixel on this view is a Scrabble tile.
  33. 33. FREECIV Open source clone of CivilisationFreeciv, an open source clone of Civilisation that uses canvas and WebSockets.3D WebGL version currently being worked on.
  34. 34. RAWKETS Because I made it and it’s addictiveRawkets is a multiplayer space shooter that I created while at university to explore canvasand WebSockets.I’m now developing it a lot further as a proper game, and plan to use it to teach others howto make multiplayer HTML5 games.Still not even at a beta release level yet, hence the bugs you can see in this video.
  35. 35. LOADS MORE Games directories are everywhereGame directories specifically focused on HTML5 are popping up all over the place.Also, Kongregate now accept HTML5 games so long as they run in an
  36. 36. FUNDAMENTALS Making games with HTML5Here are a few fundamental aspects of a HTML5 game. It’s all pretty basic, but they’re usefulto cover.Not all of these are required, it depends what kind of game youre working on…
  37. 37. GAME LOOP The heart of the gameMost games will have a loop of some kind to manage all the logic and animation that needsto happen.This is the heart of the game and is where things happen on each frame.
  38. 38. PHYSICS UPDATE Updating positionsThe physics update is part of the game loop that deals with any kind of physics, or even justsimple movement.
  39. 39. GRAPHICS UPDATES Making things visibleGraphics updates are another part of the game loop, but they deal with drawing all the gameassets onto the screen.
  40. 40. NETWORKING Breaking out of single playerNetwork infrastructure will allow you to take your game multiplayer, perhaps even real-timeby using WebSockets.
  41. 41. CONTROLS AND UI So important to get rightControls and UI, so massively important to get right.For Rawkets I hired a designer to do the UI for me so it was as good as possible.
  42. 42. Seb Lee-Delisle implemented some awesome JavaScript controls for iOS devices based onsome previous iOS games.
  43. 43. PERFORMANCE Keeping things running smoothlyPerformance isn’t really a fundamental feature, but it’s definitely something that you need tobe keeping on top off through the development of a game with HTML5.I’ll run through a couple of tips for performance in a moment.
  44. 44. GAME ENGINES Making game development easyYou dont have to create an entire game infrastructure from scratch…
  45. 45. Impact.I used this recently, and it’s really well made.The documentation is great and the author is active and very helpful.Will support WebSockets with a plugin, although you’ll still need to code the network logicfrom scratch.
  46. 46. CraftyNot my favourite engine, but it’s free and is doing much better than other free engines outthere.
  47. 47. IsongenicEngine.One of the most promising engines out there today.Massively multiplayer networking built inUses Node and MongoDBCanvas or DOM-based graphics
  48. 48. ISOGENICENGINE Iso City demoRob Evan’s, the creator of Isogenic, is putting together a little demo called Iso City to showoff the engine.
  49. 49. LIBRARIES & SERVICES Saving you time in the long runIf you do want to build your own engine, then there are some libraries and external servicesout there which might help you from having to create everything from scratch…
  50. 50. BOX2DWEB JavaScript port of the Box2D physics engineBox2DWeb allows you to add a physics engine into your game with little hassle.It’s a port of the Box2D physics engine, which is the same one that Angry Birds uses.
  51. 51. MOTION.JS Solving client-side prediction issuesMotion.js is a new library that attempts to solve the client-side prediction issues withmultiplayer gaming, some of the most difficult issues to overcome.The library doesn’t do much yet, but it’s a great idea and something to keep an eye on.
  52. 52. Joyent’s Node cloud serversProvides a remotely hosted Node server that allows you to quickly get a multiplayer game upand running.It supports WebSockets, which a lot of other hosted Node services doesn’t allow.
  53. 53. Pusher is for real-time communication and uses WebSockets.Remotely hosted.This is the service that Word² uses, the game that I highlighted earlier.
  54. 54. Kaazing.Self-hosted WebSockets communication platform.
  55. 55. There’s also Electroserver5.Self-hosted communication platform (not WebSockets) and game server for logic.
  56. 56. KEY LESSONS What I’ve learnt so farOver the last few years I’ve learnt a lot of lessons about game development.Here are just a few of the most important ones.
  57. 57. CUT DOWN LOOPS Less is moreThe less loops you can get away with the faster your game will be.Do as little as possible, no more.
  58. 58. NO TIMEOUTS Use requestAnimationFrame insteadAnother simple lesson is to stop using JavaScript timeouts and to use requestAnimationFrameinstead.requestAnimationFrame puts the browser in control of when an animation should happen andgenerally increases performance. It also doesn’t run in an inactive browser tab, saving youmore precious resources.Paul Irish has made a shim that allows you to use the requestAnimationFrame API in browsersthat don’t support it. It won’t have the cool browser-controlled animations, but it means thatyou don’t need to change your code.
  59. 59. NETWORK TRICKS Cutting down on communicationBe very aware about how much data you’re sending back and forth when creating amultiplayer game.
  60. 60. MESSAGES IN MESSAGES OUT 1 1 1 1Having only one player in the game is easy, you have one message coming in to the server,saying the player has moved, for example, and one message coming back out, updating theplayer with details from the server.
  61. 61. MESSAGES IN MESSAGES OUT 2 4 1 2 2 1So say we now have two players, there is still only 1 message in from each player, but noweach player receives 2 messages back from the server; one for them, and one for the otherplayer.This isn’t too bad, but notice how the server is having to send 4 messages – 2 for eachplayer.
  62. 62. MESSAGES IN MESSAGES OUT 4 16 1 4 4 1 1 4 4 14 players now, look how the server is having to send 16 messages, yet it only receives 4.If you haven’t already noticed, the messages out from the server are the square of thenumber of players.But 16 messages out is alright, it’s hardly going to tax the server.
  63. 63. MESSAGES IN MESSAGES OUT 30 900 1 30 30 1 1 30 30 1So imagine if we now move into properly multiplayer territory.30 players in the game would mean 30 messages coming in to the server, and 900 – NINEHUNDRED – messages going out, every update. That’s a silly amount of data for just 30people.But let’s go further still…
  64. 64. MESSAGES IN MESSAGES OUT 100 10000 1 100 100 1 1 100 100 1Say we go massively multiplayer and have 100 players in the game at one time.It’s not so bad for each individual player, they send one message in and get 100 back – that’sbearable.But check out the server, it’s getting 100 messages in and is having to send out 10,000 back,every update. That’s just a mentally stupid number that’s going to cause a lot of grief.Fortunately there is a way around this that cuts down the amount of messages sent from theserver; you just need to send data only for players visible to another player, in essencefiltering out game data that doesnt affect the current player. It’s such a simple solution, butit’s one that I never even considered at first.
  65. 65. CHEATERS You can’t avoid them completelyYour code is going to be visible to anyone who wants to look at the source.It’s mainly an issue with multiplayer gaming, as cheating in a single player game would onlyaffect one player.I experienced this early on in the development of Rawkets. The solution is to make the serverauthoritative, which means that you prevent manipulation of the player’s code from doingany damage.
  66. 66. DOM OR CANVAS Which one should you use?How do you decide whether you go with the DOM or canvas for rendering?This is something that I’ve been thinking about a lot lately.In my opinion DOM has some performance benefits, but canvas is the right tool and is goingin a better direction.The situations reminds me a little of the way tables were used for layout before CSS wasadopted. Using DOM content elements for animation feels hacky, in a bad way.I don’t have an easy solution that will make canvas perform as well, but I think it’s importantthat we try and make and use canvas better rather than turning our backs on it and clingingonto the DOM.Now Im being a bit dramatic, but I really think developers need to think long and hard beforeturning away from the ideal technologies like JavaScript, canvas and SVG.This is something that I hope to look into a lot more in the near future.
  67. 67. THE FUTURE What HTML5 gaming still needsHTML5 gaming is still at an early stage and there are still plenty of things that can beimproved.
  68. 68. DOCUMENTATION Specific to HTML5 game developmentMore documentation and teaching materials on the complex areas of game development inJavaScript.We need something like Glen Fiedler’s Gaffer on Games website, but dedicated to HTML5instead.
  69. 69. WEBGL SUPPORT Support is shocking right nowWider support for WebGL.
  70. 70. MORE ENGINES Not many decent ones around right nowBetter game engines that really solve all the major issues, particularly with multiplayergames.
  71. 71. IMPROVED AUDIO More reliable loopingImproved HTML5 audio support, with proper looping.
  72. 72. POWERFUL MOBILE Better hardware accelerationMore powerful mobile devices, with better hardware acceleration for canvas.
  73. 73. BETTER CONTROLS Break away from the keyboard and mouseBetter more console-like systems for control, like Seb Lee-Delisles iOS controller.
  74. 74. Brass Monkey turns a smart phone into a controller, which I had the luxury of seeing demoedrecently and I must say that it’s pretty damn cool.
  75. 75. MONETISATION Making profit from gamesBetter monetisation options for developers.Right now there arent (m)any games making a profit out of these new technologies.How do you monetise a game where the code is open for all to see?
  76. 76. ROB HAWKES @robhawkes Personal website and blog RECENT PROJECTS MORE COOL STUFF Twitter sentiment analysis Mozilla Technical Evangelist Delving into your soul. My job HTML5 & WebSockets game. Web development podcast.Twitter - @robhawkesRawkes -
  77. 77. FOUNDATION HTML5 CANVAS My amazing book on canvas, animation, and making games. Out now Paperback and digital formats Become a canvas master Learn how to animate Make two cool space games RAWKES.COM/FOUNDATIONCANVASBook - available on Amazon right now
  78. 78. COFFEE FWD Mozilla Web FWD get together Friday July 15th Red Rock Cafe, Mountain View Innovation acceleration Meet some great people Show off your stuff FRI JULY 15TH @ RED ROCK CAFE, MVJust a quick one to let you know about an event Mozilla are putting on this Friday in MountainView.It’s called Coffee FWD and it’s a get together related to the Web FWD Innovation Acceleratorfor the open Web.It’s a chance for us to work with you to help push the Web forward, so if you’re working onsomething cool then you should definitely come down and say hi.
  79. 79. DEV DERBY Experimenting with the latest Web technologies Every month This month is HTML5 video Manipulate video with canvas Win prizes (like an Android) Next month is all about touch DEVELOPER.MOZILLA.ORG/EN-US/DEMOS/DEVDERBYAlso, you definitely take part in the Dev Derby, which is a monthly competition run by theMozilla Developer Network to see what can be done with the latest Web technologies.This month the focus is on HTML5 video, which is pretty interesting considering that you canmanipulate it using the canvas.The winners get cool prizes, like an Android phone. It’s a great excuse to play around withthese technologies.
  80. 80. Thanks for listening, and I hope you enjoy the rest of your day.I believe we have some time set aside for questions…