SlideShare a Scribd company logo
..to boldly go where no web developer has
                              gone before.




Building a game engine
with jQuery
Why build a game engine?
Aren‘t there enough already?
Game development
Browsergame development vs. game industry*
* PC/Console game publishers
Same basic questions
What kind of genre for my
game?
Singleplayer or multiplayer?
What platform(s) am I
targeting?
What tools do I need for
development?
How does the game scale?
The game industry
Convenience

Countless tools and
frameworks to choose from
Frameworks can be
extended with more genres
Modularity gives you flexible
combinations inbetween
The browser game industry
Browser games are often grown
hobby projects
Development often copied from app
dev paradigms rather than games
No real technical standard (i.e. C++)
a lot (no seriously, a lot!) of legacy,
custom code
Frameworks
 Few good commercial flash
 frameworks
 No commercial JavaScript
 alternatives
 A couple tiny projects
   most of them concepts
   most of them dead
Why no frameworks?
Browser game development is pretty young!

Game industry has an advantage of ~25 years
Only very recently, we got

  powerful enough hardware
  to run lots of crazy JS

  new advanced
  technologies: CSS3,
  HTML5

  highly optimized rendering
  engines: Nitro etc.
Additionally...

 Lots of knowledge needed to build sophisticated
 games
   ..but many started it as hobby
 Actual web devs are seldom good game devs – and
 vice versa
 Very few allrounders that know both worlds
Reality without frameworks:




Countless iterations of code!
Sweet!


I have no competition
There‘s high demand
Let‘s rock!
The open web stack
Picking the right technologies
Cross-browser?

 If your engine is platform specific, no need to care
 about cross-browser
   Example: Engine for mobile WebKit
 Pro‘s and con‘s
   Limited audience
   Extreme development speedup and advantage
Don‘t worry about today   Your game won‘t be
                          ready tomorrow!
Pick technologies from
the future                Predict wisely
Our pick

 Vanilla HTML (rendering)
 JavaScript (scripting, client + server!)
 Canvas (as tool, not for rendering)
   (mostly) cross-platform via ExCanvas

 CSS Transforms
   cross-platform via Transformie
..and of course
Architecture and API Design
What to keep in mind when building the web
Impossibilities

 Genres that can‘t be   Genres that can‘t be
 implemented now, but   implemented for many
 pretty soon:           years to come:
   Casual 3D games,     Next-gen 3D games
   simple shooters
                        WebGL is not
   Using WebGL          advanced enough (yet)
So what is left?
2D                 2.5D*
     Puzzles         RPG‘s

     Adventure       Strategy

     Board games       turn based

     Card games        real time

     Platformers     Simulation

     Jump & Runs     etc.

                                * isometry
We chose...
Building a game engine with jQuery
I want...
 Free mouse panning         Pathfinding
 Infinite real-time worlds   Walking into houses
 Non-rectangular objects    Mashups with normal
                            HTML content
 Animated characters
                            Sound effects
 Chat bubbles
                            Scalable viewports
 Collision detection
                            MMO-ready server
Awesome! Sounds
just like the Duke!
Errr...


 Yes, if we try to develop a
 classic game engine
 We‘re aiming for the web
 though, let‘s cheat!
Advanced Techniques
Two examples
Rendering
„How do I render 2000 objects in < 50ms?“
Uh uh, obviously I‘ll use
Canvas!
Oh noes! Canvas is a lot
slower!

            Canvas‘ image API is pretty
            inefficient, as it needs a DOM
            representation of the image first
            Which means if you‘re working
            with lots of graphics, Canvas is
            actually way slower than generic
            HTML
Block rendering
Block rendering?
 Directly replace innerHTML with a huge string instead of
 multiple DOM append operations
 Huge performance boost:
   Native parsing of HTML engine is really fast
   Reflow and Repaint occur only once
 Huge disadvantage:
   No reference to individual nodes!
Lazy node linking

 Fixes the main disadvantage of missing references
 After innerHTML has been set, run:
 var elements = $(‘ *‘, container);
 Now you have a collection of all elements!
 Since you know the order of the construction, you can
 reference back
Smart rendering
Conservative method
Build <div>‘s and style
them via JavaScript (on      <div
                             style="position:absolut
the style tag)               e; top:122px; left:
                             145px; z-index:102;
Render them out en           background-image:url
bloque through               (house_1.png); margin-
innerHTML                    top:-10px; margin-
                             left:-10px; background-
                             position:10px 33px;"></
Ugh, still kind of slow...   div>

I want more!
Dummy, forgot
how to build
websites?
Web method

Don‘t ignore the layout
layers
  expecially not external
  CSS
Keep the style tag of the
<div> Object minimal:
  z-index, top, left
Web method

 Everything else is
 rendered through a
 CSS rule
 i.e. model-134
 Includes background,
 margin, padding etc
Delegation
jQuery events and click-through maps
What is event delegation?
 A technique to „forward“ events to implicit listeners
 In web development, usually the following:
   Bind an event to the root node except for the actual
   child element
   When an event happens (i.e. click), find out if the
   target or an ancestor matches the child element
   Moves processing efforts to when the event
   happens, scales really well
One event to rule them all

 „mousemove“
  Handles position detection, dragging
 „mousedown“
  Handles drag start, clicking
 „mouseup“
  Handles drag stop, clicking
..and with jQuery?

 With jQuery, it‘s even easier
 jQuery has live/die methods that
   work like bind/unbind
   abstracts event delegation so..
   ..you don‘t need to worry about it
 Sweet!
live/die on objects


                      Yay, I can click on
                      houses!
                      Mh, I can click on
                      transparency, too..
                      This kind of sucks!
Be creative!
Click through maps

Build up a pixel map for each object that tells us where
the transparent pixels are
If transparent, check behind until you find a valid target
  Checking behind can be done, since you control the viewport, and you know
  where your elements are

W00t, this fixes our issue!
Building up those pixel maps is amazingly
              crappy work!
Let Canvas do it!
 Canvas can read pixel data from images
 Then, we can check if our pixel is in fact transparent
 ...and save this 0/1 value in a new optimized, smaller
 array


        var   clickMap = [];
        for   (var i = 0, n = imageData.length; i < n; i += 4) {
        	     var row = Math.floor((i / 4) / width);
        	     var col = (i/4) - (row * width);
        	     if(!clickMap[row]) clickMap[row] = [];
        	     clickMap[row][col] = imageData[i+3] == 0 ? 0 : 1;
        }
Server-side JavaScript
Bridging the gap
„JavaScript is painful enough already, now you
want me to work with it in the backend as well?“
Why JavaScript?

A single scripting language per project dramatically
speeds up development
Great portions of client side code (i.e. for calculations)
can be reused without costs
JavaScript is awesome!
Meet node.js
 „So sexy it hurts“
„The most revolutionary
technology for web developers
        since jQuery.“
                       Paul Bakaus
JavaScript in the Browser
JavaScript in node
Node‘s features

 Google‘s V8 engine running on server
 Server and scripting combined
 Comes with sugar (pretty modules for system, servers
 etc.)
 EcmaScript 5
The great innovation?
Node is completely event-
         driven.
  db.query(‘ select..‘, function(result) {});
Building a game engine with jQuery
?

Professional game engine for the web
Commercially licensable
Cross-platform (yes, works on iPhone!)
Comes with all mentioned features (and more)
Currently in alpha   Contact us for availability and pricing!
Show me the video!
http://tinyurl.com/dextrose-aves-engine-sneak
Thanks for your attention!
More at dextrose.com & paulbakaus.com
Rate this talk at http://spkr8.com/t/2986




                                     @pbakaus


We‘re looking for investors and
partners!

Contact us at contact@dextrose.com
for more information.

More Related Content

KEY
Rapid Prototyping With jQuery
PDF
Tools for Tabletop Game Design
PDF
iOS Game Development With UIKit
PPTX
Game Engine for Serious Games
PPTX
Responsive Design with Axure 7.0’s Adaptive Views
PPTX
Making HTML5 Games with Phaser
PDF
Advanced Web Graphics with Canvas
PDF
My 10 days with Phaser.js - WarsawJS Meetup #13
Rapid Prototyping With jQuery
Tools for Tabletop Game Design
iOS Game Development With UIKit
Game Engine for Serious Games
Responsive Design with Axure 7.0’s Adaptive Views
Making HTML5 Games with Phaser
Advanced Web Graphics with Canvas
My 10 days with Phaser.js - WarsawJS Meetup #13

What's hot (19)

PPTX
Advanced Power Point 1
PDF
Unty3D Awesome Assets - uTomate
PPT
Phaser Workshop Internet World 2014
PDF
3D Clearance Rack: Add Affordable 3D Content to eLearning Simulations, AR, an...
PPTX
Javascript Animation with Canvas - Gregory Starr 2015
PDF
Unity3D Tips and Tricks or "You are doing it wrong!"
ODP
HTML5 Mobile Game Development Workshop - Module 2 - HTML5 Developer Conferenc...
PDF
Prototyping Axure
PDF
Managing Visual Design in Axure
PDF
Intro to Axure 7 - User Vision Breakfast Briefing
PPTX
Practical Guide for Optimizing Unity on Mobiles
PDF
Mirror - Android UI development on steroids
PPTX
Phaser presentation
PDF
Unity: Unity Flash – ключ к созданию Flash 3D
PDF
Rapid Game Development with RUby and Gosu – Ruby Manor 4
PDF
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
KEY
Game Design 2: 2011 - Introduction to Game Interface Design
PDF
Game Engine Architecture
Advanced Power Point 1
Unty3D Awesome Assets - uTomate
Phaser Workshop Internet World 2014
3D Clearance Rack: Add Affordable 3D Content to eLearning Simulations, AR, an...
Javascript Animation with Canvas - Gregory Starr 2015
Unity3D Tips and Tricks or "You are doing it wrong!"
HTML5 Mobile Game Development Workshop - Module 2 - HTML5 Developer Conferenc...
Prototyping Axure
Managing Visual Design in Axure
Intro to Axure 7 - User Vision Breakfast Briefing
Practical Guide for Optimizing Unity on Mobiles
Mirror - Android UI development on steroids
Phaser presentation
Unity: Unity Flash – ключ к созданию Flash 3D
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Albion Online - A Cross-Platform MMO (Unite Europe 2016, Amsterdam)
Game Design 2: 2011 - Introduction to Game Interface Design
Game Engine Architecture
Ad

Viewers also liked (20)

PDF
Beyond the Standards
KEY
An in-depth look at jQuery
KEY
An in-depth look at jQuery UI
PPTX
EMC World 2015 - Why DevOps is Critical for Business
PPT
Activated Carbon Study
PPT
Z510 3D PRINTER
PPT
영양과 식이 파트1
PDF
마케팅 관점에서 IoT째려보기
PPT
Activated Carbon
PPTX
Rapid Prototyping (Mechanical)
PDF
Micro Electro Mechanical Systems (MEMS) Class Materials - Lecture 01
PPTX
Activated Carbon
PPT
Working of safety airbags and their manufacturing
PPTX
Rapid prototyping
PPTX
Rapid prototyping technology
PDF
What is UX and how can it help your organisation?
PDF
Chaos Driven Development (Bruce Wong)
DOCX
Pedal Powered Washing Machine
PDF
How to shout so your users will listen
PPT
Exhaust gas-recirculation-in-four-stroke-engine
Beyond the Standards
An in-depth look at jQuery
An in-depth look at jQuery UI
EMC World 2015 - Why DevOps is Critical for Business
Activated Carbon Study
Z510 3D PRINTER
영양과 식이 파트1
마케팅 관점에서 IoT째려보기
Activated Carbon
Rapid Prototyping (Mechanical)
Micro Electro Mechanical Systems (MEMS) Class Materials - Lecture 01
Activated Carbon
Working of safety airbags and their manufacturing
Rapid prototyping
Rapid prototyping technology
What is UX and how can it help your organisation?
Chaos Driven Development (Bruce Wong)
Pedal Powered Washing Machine
How to shout so your users will listen
Exhaust gas-recirculation-in-four-stroke-engine
Ad

Similar to Building a game engine with jQuery (20)

PPTX
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)
PDF
Browsers with Wings
KEY
Seattle javascript game development - Overview
KEY
Rockstar Graphics with HTML5
PDF
HTML5 & JavaScript Games
PDF
W3C HTML5 KIG-The complete guide to building html5 games
PDF
Leveling up your JavaScipt - DrupalJam 2017
PPTX
HTML5 for Rich User Experience
KEY
Pointer Events in Canvas
PDF
Intro to HTML5
PDF
Building a Better Web with HTML5 and CSS3
PDF
Google's HTML5 Work: what's next?
PPTX
Remix
KEY
Stupid Canvas Tricks
PDF
How to build a html5 websites.v1
PPTX
PDF
Alejandro Villanueva - Google Inc.
PDF
Google - Charla para CTOs
PDF
One codebase, multiple platforms; Using HTML5/js for game dev
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)
Browsers with Wings
Seattle javascript game development - Overview
Rockstar Graphics with HTML5
HTML5 & JavaScript Games
W3C HTML5 KIG-The complete guide to building html5 games
Leveling up your JavaScipt - DrupalJam 2017
HTML5 for Rich User Experience
Pointer Events in Canvas
Intro to HTML5
Building a Better Web with HTML5 and CSS3
Google's HTML5 Work: what's next?
Remix
Stupid Canvas Tricks
How to build a html5 websites.v1
Alejandro Villanueva - Google Inc.
Google - Charla para CTOs
One codebase, multiple platforms; Using HTML5/js for game dev

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Advanced IT Governance
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
KodekX | Application Modernization Development
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Machine learning based COVID-19 study performance prediction
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Modernizing your data center with Dell and AMD
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Electronic commerce courselecture one. Pdf
Advanced IT Governance
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
KodekX | Application Modernization Development
Spectral efficient network and resource selection model in 5G networks
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
NewMind AI Monthly Chronicles - July 2025
Machine learning based COVID-19 study performance prediction
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Modernizing your data center with Dell and AMD
The AUB Centre for AI in Media Proposal.docx
Per capita expenditure prediction using model stacking based on satellite ima...
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

Building a game engine with jQuery

  • 1. ..to boldly go where no web developer has gone before. Building a game engine with jQuery
  • 2. Why build a game engine? Aren‘t there enough already?
  • 3. Game development Browsergame development vs. game industry* * PC/Console game publishers
  • 4. Same basic questions What kind of genre for my game? Singleplayer or multiplayer? What platform(s) am I targeting? What tools do I need for development? How does the game scale?
  • 6. Convenience Countless tools and frameworks to choose from Frameworks can be extended with more genres Modularity gives you flexible combinations inbetween
  • 7. The browser game industry
  • 8. Browser games are often grown hobby projects Development often copied from app dev paradigms rather than games No real technical standard (i.e. C++) a lot (no seriously, a lot!) of legacy, custom code
  • 9. Frameworks Few good commercial flash frameworks No commercial JavaScript alternatives A couple tiny projects most of them concepts most of them dead
  • 11. Browser game development is pretty young! Game industry has an advantage of ~25 years
  • 12. Only very recently, we got powerful enough hardware to run lots of crazy JS new advanced technologies: CSS3, HTML5 highly optimized rendering engines: Nitro etc.
  • 13. Additionally... Lots of knowledge needed to build sophisticated games ..but many started it as hobby Actual web devs are seldom good game devs – and vice versa Very few allrounders that know both worlds
  • 15. Sweet! I have no competition There‘s high demand Let‘s rock!
  • 16. The open web stack Picking the right technologies
  • 17. Cross-browser? If your engine is platform specific, no need to care about cross-browser Example: Engine for mobile WebKit Pro‘s and con‘s Limited audience Extreme development speedup and advantage
  • 18. Don‘t worry about today Your game won‘t be ready tomorrow! Pick technologies from the future Predict wisely
  • 19. Our pick Vanilla HTML (rendering) JavaScript (scripting, client + server!) Canvas (as tool, not for rendering) (mostly) cross-platform via ExCanvas CSS Transforms cross-platform via Transformie
  • 21. Architecture and API Design What to keep in mind when building the web
  • 22. Impossibilities Genres that can‘t be Genres that can‘t be implemented now, but implemented for many pretty soon: years to come: Casual 3D games, Next-gen 3D games simple shooters WebGL is not Using WebGL advanced enough (yet)
  • 23. So what is left?
  • 24. 2D 2.5D* Puzzles RPG‘s Adventure Strategy Board games turn based Card games real time Platformers Simulation Jump & Runs etc. * isometry
  • 27. I want... Free mouse panning Pathfinding Infinite real-time worlds Walking into houses Non-rectangular objects Mashups with normal HTML content Animated characters Sound effects Chat bubbles Scalable viewports Collision detection MMO-ready server
  • 29. Errr... Yes, if we try to develop a classic game engine We‘re aiming for the web though, let‘s cheat!
  • 31. Rendering „How do I render 2000 objects in < 50ms?“
  • 32. Uh uh, obviously I‘ll use Canvas!
  • 33. Oh noes! Canvas is a lot slower! Canvas‘ image API is pretty inefficient, as it needs a DOM representation of the image first Which means if you‘re working with lots of graphics, Canvas is actually way slower than generic HTML
  • 35. Block rendering? Directly replace innerHTML with a huge string instead of multiple DOM append operations Huge performance boost: Native parsing of HTML engine is really fast Reflow and Repaint occur only once Huge disadvantage: No reference to individual nodes!
  • 36. Lazy node linking Fixes the main disadvantage of missing references After innerHTML has been set, run: var elements = $(‘ *‘, container); Now you have a collection of all elements! Since you know the order of the construction, you can reference back
  • 38. Conservative method Build <div>‘s and style them via JavaScript (on <div style="position:absolut the style tag) e; top:122px; left: 145px; z-index:102; Render them out en background-image:url bloque through (house_1.png); margin- innerHTML top:-10px; margin- left:-10px; background- position:10px 33px;"></ Ugh, still kind of slow... div> I want more!
  • 39. Dummy, forgot how to build websites?
  • 40. Web method Don‘t ignore the layout layers expecially not external CSS Keep the style tag of the <div> Object minimal: z-index, top, left
  • 41. Web method Everything else is rendered through a CSS rule i.e. model-134 Includes background, margin, padding etc
  • 42. Delegation jQuery events and click-through maps
  • 43. What is event delegation? A technique to „forward“ events to implicit listeners In web development, usually the following: Bind an event to the root node except for the actual child element When an event happens (i.e. click), find out if the target or an ancestor matches the child element Moves processing efforts to when the event happens, scales really well
  • 44. One event to rule them all „mousemove“ Handles position detection, dragging „mousedown“ Handles drag start, clicking „mouseup“ Handles drag stop, clicking
  • 45. ..and with jQuery? With jQuery, it‘s even easier jQuery has live/die methods that work like bind/unbind abstracts event delegation so.. ..you don‘t need to worry about it Sweet!
  • 46. live/die on objects Yay, I can click on houses! Mh, I can click on transparency, too.. This kind of sucks!
  • 48. Click through maps Build up a pixel map for each object that tells us where the transparent pixels are If transparent, check behind until you find a valid target Checking behind can be done, since you control the viewport, and you know where your elements are W00t, this fixes our issue!
  • 49. Building up those pixel maps is amazingly crappy work!
  • 50. Let Canvas do it! Canvas can read pixel data from images Then, we can check if our pixel is in fact transparent ...and save this 0/1 value in a new optimized, smaller array var clickMap = []; for (var i = 0, n = imageData.length; i < n; i += 4) { var row = Math.floor((i / 4) / width); var col = (i/4) - (row * width); if(!clickMap[row]) clickMap[row] = []; clickMap[row][col] = imageData[i+3] == 0 ? 0 : 1; }
  • 52. „JavaScript is painful enough already, now you want me to work with it in the backend as well?“
  • 53. Why JavaScript? A single scripting language per project dramatically speeds up development Great portions of client side code (i.e. for calculations) can be reused without costs JavaScript is awesome!
  • 54. Meet node.js „So sexy it hurts“
  • 55. „The most revolutionary technology for web developers since jQuery.“ Paul Bakaus
  • 56. JavaScript in the Browser
  • 58. Node‘s features Google‘s V8 engine running on server Server and scripting combined Comes with sugar (pretty modules for system, servers etc.) EcmaScript 5
  • 60. Node is completely event- driven. db.query(‘ select..‘, function(result) {});
  • 62. ? Professional game engine for the web Commercially licensable Cross-platform (yes, works on iPhone!) Comes with all mentioned features (and more) Currently in alpha Contact us for availability and pricing!
  • 63. Show me the video! http://tinyurl.com/dextrose-aves-engine-sneak
  • 64. Thanks for your attention! More at dextrose.com & paulbakaus.com Rate this talk at http://spkr8.com/t/2986 @pbakaus We‘re looking for investors and partners! Contact us at [email protected] for more information.