Game Development With HTML5


Published on

Game development using HTML5 technologies presentation, May 2010.

This lecture was given by Gil Megidish at AlphaGeeks #6 meetup in Tel Aviv, Israel.

The talk begins with some review of the game graphics techniques, and how you can achieve these with today's browsers and client side code.

4 demos were presented: sprites with canvas (luigi), framebuffer access (apple2 emulator), primitives and polygons (another world js) and image modifiers (droste effect.)

The lecture was given in Hebrew, ppt is English.

Published in: Technology
  • Njce! Thanks for sharing.
    Are you sure you want to  Yes  No
    Your message goes here
  • Introduction to Game Design, Prototyping, and Development: From Concept to Playable Game with Unity and C# ---
    Are you sure you want to  Yes  No
    Your message goes here
  • Game Development Essentials: An Introduction ---
    Are you sure you want to  Yes  No
    Your message goes here
  • Game Programming Patterns ---
    Are you sure you want to  Yes  No
    Your message goes here
  • no more need for flash? an understandable first impression but please, by all means, if you'd prefer to indulge the tyranny of javascript over the orders of magnitude more pleasant to program in Actionscript 3... be my guest :) In all seriousness though, I think flash is going to remain around, particularly in games development for years to come. Just check out the flash portals. They're thriving. More new content than ever. Adobe has released Molehill. Unity3D compiles to Flash swf format now. The Epic UDK produces flash. Some of the bets as3 books have only recently been released. There has been very substantial flash as3 publishing activity actually lately. I think that the fundamental confusion here is that Adobe has handed off the Flex SDK to Apache to do with as they will. This by no means whatsoever constitutes a plan to abandon the flash as3 platform. In fact, it's oly just peaked. With Starling and Stage3D and Molehill, 3rd party tools like Aweay3d 4Gold... sky is the limit!
    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

Game Development With HTML5

  1. 1. <games /> Gil Megidish [email_address]
  2. 2. And I love writing / rewriting / reverse engineering games
  3. 4. What The Heck is HTML5 Canvas Video Audio Web Sockets Web Storage Web Worker Web Database Selectors Validation File API Semantic Elements
  4. 5. Man will make it to Mars before HTML5 is on my Firefox! W3C’s ETA: Year 2022
  5. 6. Games + Javascript? = wtf
  6. 7. Why Bother With Javascript? <ul><li>Fun to develop </li></ul><ul><ul><li>Hacker’s spielplatz! </li></ul></ul><ul><li>Fast deployment </li></ul><ul><ul><li>Serve static files </li></ul></ul><ul><li>Easy to debug </li></ul><ul><ul><li>alert(), firebug.. Still better than the alternative! </li></ul></ul><ul><li>Open source and free tools </li></ul><ul><ul><li>Notepad, vi, emacs </li></ul></ul><ul><li>B.Y.O. framework </li></ul><ul><ul><li>jQuery? </li></ul></ul>spielplatz
  7. 8. But Why REALLY? <ul><li>Has been around for ages </li></ul><ul><li>Won’t go away any time soon </li></ul><ul><li>Wide support: </li></ul><ul><ul><li>Web browsers </li></ul></ul><ul><ul><li>Mobile devices </li></ul></ul><ul><ul><li>Facebook applications </li></ul></ul><ul><ul><li>On a rocket near you </li></ul></ul>
  9. 10. Anatomy of a Game LOGIC GRAPHICS INPUT SOUND MUSIC MULTIPLAYER GAME ASSETS javascript code <canvas> onkeydown, onmousedown <audio> <audio> ajax, WebSocket Images, Audio, Video and Binary supported by browsers
  10. 11. Graphics
  11. 12. Framebuffer (raw) 0,0 0,1 0,2 0,3 0,4 0,5 0,6 0,7 0,x 1,0 1,1 1,2 1,3 1,4 1,5 1,6 1,7 1,x y,0 y,1 y,2 y,3 y,4 y,5 y,6 y,7 y,x x y … … … . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  12. 14. Tile + Sprite Memory
  13. 16. Scene Graph Placeholder For Future Presentation
  14. 18. Canvas is King
  15. 19. DEMO TIME!
  16. 20. Three Demos To Rule Them All Framebuffer demo Sprites demo Vector graphics demo
  17. 21. Catch me a canvas <ul><li><canvas id=“graphics” width=“640” height=“480”> </li></ul><ul><li>Guru Meditation: No canvas supported! </li></ul><ul><li></canvas> </li></ul><ul><li>var canvas = document.getElementById(“graphics”); </li></ul><ul><li>var context = canvas.getContext(“2d”); </li></ul>
  18. 23. Drawing Primitives <ul><li>ctx.fillStyle = “#c80000&quot;; </li></ul><ul><li>ctx.fillRect (10, 10, 55, 50); </li></ul><ul><li>ctx.fillStyle = &quot;rgba(0, 0, 200, 0.5)&quot;; </li></ul><ul><li>ctx.fillRect (30, 30, 55, 50); </li></ul>Other drawing methods: arc, bezierCurve, lineTo, quadraticCurve, rect, stroke, fillText, strokeText, beginPath/closePath and fill
  19. 24. (but who needs that ?)
  20. 25. Drawing Images <ul><li>var sprite = new Image(); </li></ul><ul><li>sprite.src = “luigi.png”; </li></ul><ul><li>var x = 0, y = 0; </li></ul><ul><li>ctx.drawImage(sprite, x, y); </li></ul>
  21. 26. Drawing Images 2 <ul><li>var spritemap = new Image(); </li></ul><ul><li>spritemap.src = “sprite-map.png”; </li></ul><ul><li>ctx.drawImage( </li></ul><ul><li>spritemap, </li></ul><ul><li>sx, sy, </li></ul><ul><li>sw, sh, </li></ul><ul><li>dx, dy, </li></ul><ul><li>dw, dh </li></ul><ul><li>); </li></ul>Sprite maps save loading time by fewer requests and better compression. drawImage() also provides scaling and cropping.
  22. 27. Going Crazy With Images // context state checkpoint; ctx.translate(0, 80); ctx.rotate(-45 * Math.PI / 180.0); ctx.scale(3.0, 1.0); ctx.drawImage(luigi, 0, 0); // revert all context changes ctx.restore();
  23. 28. Accessing Pixels <ul><li>var block = ctx.getImageData(sx, sy, sw, sh); </li></ul><ul><li>block = { </li></ul><ul><li>width: width in pixels, </li></ul><ul><li>height: height in pixels, </li></ul><ul><li>data: array of 4*width*height bytes </li></ul><ul><li>}; </li></ul><ul><li>Alternatively: ctx.createImageData(w, h); </li></ul>
  24. 29. Accessing Pixels <ul><li>var block = ctx.getImageData(0, 0, canvas.width/2, canvas.height); </li></ul><ul><li>for (var y=0; y<block.height; y++) </li></ul><ul><li>{ </li></ul><ul><li>for (var x=0; x<block.width; x++) </li></ul><ul><li>{ </li></ul><ul><li>[(y*block.width+x)*4+0] ^= 0xff; </li></ul><ul><li>[(y*block.width+x)*4+1] ^= 0xff; </li></ul><ul><li>[(y*block.width+x)*4+2] ^= 0xff; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>ctx.putImageData(block, 0, 0); </li></ul>
  25. 30. Why Access Pixels ? Complicated things impossible without putImageData() Read image pixels getImageData combined with primitive drawing = save image to disk! These examples are available to
  26. 31. The Jazz Singer
  27. 32. Let There Be Sound! <ul><li><audio id=“sfx001” src=“/mp3/boom.mp3”></audio> </li></ul><ul><li>$(“sfx001”).play(); </li></ul>
  28. 33. Let There Be Sound! <ul><li><audio id=“sfx001” src=“/mp3/boom.mp3”></audio> </li></ul><ul><li>$(“sfx001”).play(); </li></ul><ul><li>Other methods: </li></ul><ul><li>$(“sfx001”).pause(); </li></ul><ul><li>Other attributes: </li></ul><ul><li>$(“sfx001”).currentTime = 35.0; </li></ul><ul><li>$(“sfx001”).volume = 0.5; </li></ul><ul><li>$(“sfx001”).duration (read only) </li></ul>
  29. 34. Putting It All Together
  30. 35. Typical Game Loop <ul><li>function gameTick() </li></ul><ul><li>{ </li></ul><ul><li>processKeyboard(); </li></ul><ul><li>moveEnemies(); </li></ul><ul><li>drawGraphics(); </li></ul><ul><li>updateAudio(); </li></ul><ul><li>} </li></ul><ul><li>var fps = 60; </li></ul><ul><li>setInterval(gameTick, 1000 / fps); </li></ul>
  31. 36. The Future is Upon Us!
  32. 37. Quake2 HTML5
  33. 38. What’s Coming Up Next <ul><li>WebGL </li></ul><ul><ul><li>OpenGL interface for Javascript </li></ul></ul><ul><ul><li>As of May, 2010: good luck finding a stable browser! </li></ul></ul><ul><li>WebSocket </li></ul><ul><ul><li>UDP and nonblocking transport layer </li></ul></ul><ul><ul><li>Not there yet! (KAAZING?) </li></ul></ul><ul><li>WebStorage </li></ul><ul><ul><li>Save games? </li></ul></ul>
  34. 39. Code Like It’s 2020! ftw! ‘ s Blackberry coming June 1 st !
  35. 40. Q&A
  36. 41. Q&A <ul><li>Yes! You can use <canvas> in Internet Explorer 6? </li></ul><ul><li><!--[if IE]> </li></ul><ul><li><script type=&quot;text/javascript“ src=&quot;/js/excanvas.js&quot;> </li></ul><ul><li></script> </li></ul><ul><li><![endif]--> </li></ul><ul><li>PS. Remember to upgrade your mother’s IE! </li></ul>
  37. 42. Links! <ul><li>Chrome Experiments: Not Your Momma’s JS </li></ul><ul><ul><li> </li></ul></ul><ul><li>Appcelerator’s Titanium </li></ul><ul><ul><li> </li></ul></ul><ul><li>Box 2D: real time physics for JS games </li></ul><ul><ul><li> </li></ul></ul><ul><li>Mozilla’s Canvas tutorial </li></ul><ul><ul><li>https:// </li></ul></ul>
  38. 44. GO MAKE GAMES!