SlideShare a Scribd company logo
1 of 38
Rockstar Graphics
  with HTML5
       Dave Balmer, Gobico Games
Developer of Wobble Words and Poker Drops
              April 24, 2010
A Clean Slate for Web Developers
Breaking your skills out of the browser
A Clean Slate for Web Developers
Breaking your skills out of the browser


• JavaScript is the focus instead of an addition
• HTML and the DOM provide basic structure;
  layered semantic markup is not a priority
• CSS is the presentation workhorse
• Browser compatibility is not an issue, so
  development
  is faster
• Most frameworks designed for browsers are not
  optimal for mobile devices because they’re firmly
  entrenched in browser-centric approaches (I’m
  looking at you, JQuery)
The Webkit Stack
The Webkit Stack
JavaScript is front and center


                          App Process

                          JavaScript

             Canvas                           CSS3

                             Webkit


                          Linux Kernel

             ARM CPU                     Hardware Graphics
Rockstar Graphics with HTML5
Getting the most out of native code (without coding native)
Rockstar Graphics with HTML5
Getting the most out of native code (without coding native)


• Canvas Element
• CSS3
• Layering techniques
• Efficient JavaScript
• Trickery
Canvas Element
Canvas Element
What it is and when to use it


• An empty box element where JavaScript directly
  draws lines, shapes, images, and other 2D
  primitives
  • Very similar concept to Java2D and Quartz 2D
  • Sophisticated path construction with strokes and fills
  • Image layering and transformation
  • Uses native code under the hood, so render time is fast


• Use it to break outside the DOM “box” model
  • Ad-hoc graphs and charts
  • Synchronized animation with multiple images
Sample Code: Line Graph
A simple Canvas example


• Basic stage

• Simple “Graph” class
  • Array goes in
  • Graph goes out
  • Auto-scales


                          Break away to
                          example before
                          clicking -- reveal
                          screen after code
                          walkthru
Sample Code: Line Graph
A simple Canvas example


• Basic stage

• Simple “Graph” class
  • Array goes in
  • Graph goes out
  • Auto-scales


• Boring!                               Break away to
                                        example before
  • Does illustrate the point           clicking -- reveal
                                        screen after code
  • Definitely not “Rockstar” material   walkthru
  • We’ll add some goodies later
Canvas: Other Uses
Drawing lines is fine, but you can do a lot more


• Image manipulation
  • Transformations (scale, rotate)
  • Compositing (think Photoshop layers)


• Animation
  • Sprites
  • Complex physics
  • The downside: your animation loop will be in JavaScript,
    which can be difficult to get great performance
Canvas Gotchas
Current limitations to keep in mind


• Today’s webOS Canvas element has limitations:
  • No pixel operations (getImageData, putImageData)
  • No shadows (shadowOffsetX/Y, shadowBlur, shadowColor)
  • Cannot save raster contents of canvas (toDataURL)
  • No “round” or “mitre” lineJoin or lineCap (“bevel” only)
Canvas Gotchas
Current limitations to keep in mind


• Today’s webOS Canvas element has limitations:
  • No pixel operations (getImageData, putImageData)
  • No shadows (shadowOffsetX/Y, shadowBlur, shadowColor)
  • Cannot save raster contents of canvas (toDataURL)
  • No “round” or “mitre” lineJoin or lineCap (“bevel” only)


• And Text? Forget it.
  • The W3 spec for Canvas text rendering is exciting,
    but largely unsupported anywhere
  • Layering with DOM/CSS3 is the practical approach
    for now
CSS3
CSS3                                            Mention the
                                                excitingg news
                                                about 3D and
What it is and when to use it                   hardware
                                                accelerated
                                                transitions
• Sophisticated declarative styling language
  • Pixel-perfect font, color, image properties
  • Scale, rotate, stretch, and move any DOM element
  • Animate property changes with simple physics


• Huge benefits for
  • Adding unique and consistent look and feel to your apps
  • Creating your own specialized widgets
  • Simple, unsynchronized animations
Sample Code: Screensaver
A contrived yet fun example of CSS3 animation


• CSS3 animation
• Minimal JavaScript
  • Timer loop
  • Setting properties
  • Letting CSS do the hard stuff




                           Break away to
                           example before
                           clicking -- reveal
                           screen after code
                           walkthru
Sample Code: Screensaver
A contrived yet fun example of CSS3 animation


• CSS3 animation
• Minimal JavaScript
  • Timer loop
  • Setting properties
  • Letting CSS do the hard stuff




                           Break away to
                           example before
                           clicking -- reveal
                           screen after code
                           walkthru
CSS3 Gotchas
Current webOS limitations to keep in mind
CSS3 Gotchas
Current webOS limitations to keep in mind


• No custom fonts
• No textShadow or boxShadow (bummer)
• No gradients
  • Have to use gradient background images today
• No transitionEnd event
  • Limits synchronized animation chaining
  • For now, have to use setTimeout to match transition
    interval
    and “hope for the best”
Layering
Layering
Using CSS3 and Canvas elements together can be powerful


• Both can be controlled with JavaScript
• A good example is a network diagram:
Layering
Using CSS3 and Canvas elements together can be powerful


• Both can be controlled with JavaScript
• A good example is a network diagram:

 CSS Styled Elements +               Canvas 2D Lines

                2                       5
    1                      4                       7
                3                       6
Sample Code: Line Graph +
Our first Canvas example was pretty boring


• Canvas still draws the
  graph

• CSS adds some spice
  • Activate/deactivate
    animation
  • More interesting styling
  • No additional JavaScript
Sample Code: Line Graph +
Our first Canvas example was pretty boring


• Canvas still draws the
  graph

• CSS adds some spice
  • Activate/deactivate
    animation
  • More interesting styling
  • No additional JavaScript
Mix and Match for the Win

Feature                            CSS   Canvas
Text Styling                       ✔
2D Drawing Primitives                      ✔
Sprite Animation                   ✔       ✔
Generated Gradients                        ✔
Image Transformations              ✔       ✔
“Set it and forget it” Animation   ✔
Synchronized Animation                     ✔
Layered transitions                ✔
Layered transformations            ✔
Mix and Match for the Win
Dipping into both Canvas and CSS techniques

 Feature                               CSS    Canvas
 Text Styling                           ✔
 2D Drawing Primitives                          ✔
 Sprite Animation                       ✔       ✔
 Generated Gradients                            ✔
 Image Transformations                  ✔       ✔
 “Set it and forget it” Animation       ✔
 Synchronized Animation                         ✔
 Layered transitions                    ✔
 Layered transformations                ✔
Layering Example: Poker Drops
A quick peek at this game currently in testing


• CSS3 Animations
  • Menu and UI transitions
  • Dealing cards
  • Rotating the game board to
    match device orientation
  • Custom scroller widget
    with basic physics


• Canvas
  • Drawing the path between
    poker cards
  • Game timer
Layering Example: Poker Drops
A quick peek at this game currently in testing


• CSS3 Animations
  • Menu and UI transitions
  • Dealing cards
  • Rotating the game board to
    match device orientation
  • Custom scroller widget
    with basic physics


• Canvas
  • Drawing the path between
    poker cards
  • Game timer
Trickery
JavaScript Performance Efficiencies
Boils down to taking all unnecessary computation out of
loops

• Pre-compute everything

• Make the native code do more work by using
  CSS3, built-in array operations and other goodies
  wherever possible

• Reduce garbage collection impact by re-using
  objects instead of tossing them
Trickery: Examples
Taking a second look at some of the goodness in the
examples

• Graph
  • Simple array-in, graph-out structure
  • Fancy transitions done with CSS3


• Screensaver                              Pull up graph example, walk
                                           thru use of CSS to offload the
  • CSS3 does all the heavy lifting        goodies, and simple array
                                           processing
  • Our timer loop does very little
  • Our “random” animation paths are built from pre-
    computed data
The Future
What We Can Look Forward To
Palm is on board—here’s hoping for speedy implementation


• More complete CSS3 implementation
• More complete Canvas implementation

• Hardware accelerated CSS!

• Canvas 3D
• WebGL
• 3D Transformations in CSS3
Q &A
More Information
Dave Balmer, Gobico Games
@balmer
dave@gobico.com
http://gobico.com

Good CSS and HTML5 Walkthroughs
http://css3.info
http://diveintohtml5.org

“Far Out Fowl” Canvas Game Development Tutorial
http://bit.ly/cdfuQb
Rockstar Graphics with HTML5

More Related Content

What's hot

Simply Responsive CSS3
Simply Responsive CSS3Simply Responsive CSS3
Simply Responsive CSS3Denise Jacobs
 
SVG - Scalable Vector Graphic
SVG - Scalable Vector GraphicSVG - Scalable Vector Graphic
SVG - Scalable Vector GraphicAkila Iroshan
 
Deliverance - a compelling way to theme Plone sites
Deliverance - a compelling way to theme Plone sitesDeliverance - a compelling way to theme Plone sites
Deliverance - a compelling way to theme Plone sitesJazkarta, Inc.
 
CSS3: Ripe and Ready
CSS3: Ripe and ReadyCSS3: Ripe and Ready
CSS3: Ripe and ReadyDenise Jacobs
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5Kunal Johar
 

What's hot (8)

Drupal Backbone.js in the Frontend
Drupal Backbone.js in the FrontendDrupal Backbone.js in the Frontend
Drupal Backbone.js in the Frontend
 
Simply Responsive CSS3
Simply Responsive CSS3Simply Responsive CSS3
Simply Responsive CSS3
 
Before Going Vector
Before Going VectorBefore Going Vector
Before Going Vector
 
SVG - Scalable Vector Graphic
SVG - Scalable Vector GraphicSVG - Scalable Vector Graphic
SVG - Scalable Vector Graphic
 
Deliverance - a compelling way to theme Plone sites
Deliverance - a compelling way to theme Plone sitesDeliverance - a compelling way to theme Plone sites
Deliverance - a compelling way to theme Plone sites
 
Svg
SvgSvg
Svg
 
CSS3: Ripe and Ready
CSS3: Ripe and ReadyCSS3: Ripe and Ready
CSS3: Ripe and Ready
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 

Similar to Rockstar Graphics with HTML5

Trendsetting: Web Design and Beyond
Trendsetting: Web Design and BeyondTrendsetting: Web Design and Beyond
Trendsetting: Web Design and BeyondAndy Stratton
 
CSS3: Ripe and Ready to Respond
CSS3: Ripe and Ready to RespondCSS3: Ripe and Ready to Respond
CSS3: Ripe and Ready to RespondDenise Jacobs
 
Talk Paris Infovis 091207132953 Phpapp01(2)
Talk Paris Infovis 091207132953 Phpapp01(2)Talk Paris Infovis 091207132953 Phpapp01(2)
Talk Paris Infovis 091207132953 Phpapp01(2)johnnybiz
 
Using Web Standards to create Interactive Data Visualizations for the Web
Using Web Standards to create Interactive Data Visualizations for the WebUsing Web Standards to create Interactive Data Visualizations for the Web
Using Web Standards to create Interactive Data Visualizations for the Webphilogb
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive GraphicsBlazing Cloud
 
Sugarcoating your frontend one ViewModel at a time
Sugarcoating your frontend one ViewModel at a timeSugarcoating your frontend one ViewModel at a time
Sugarcoating your frontend one ViewModel at a timeEinar Ingebrigtsen
 
Designing in the Browser - Mason Wendell, Drupaldelphia
Designing in the Browser - Mason Wendell, DrupaldelphiaDesigning in the Browser - Mason Wendell, Drupaldelphia
Designing in the Browser - Mason Wendell, Drupaldelphiacanarymason
 
Html5 Whats around the bend
Html5 Whats around the bendHtml5 Whats around the bend
Html5 Whats around the bendRaj Lal
 
The Coding Designer's Survival Kit - Capital Camp
The Coding Designer's Survival Kit - Capital CampThe Coding Designer's Survival Kit - Capital Camp
The Coding Designer's Survival Kit - Capital Campcanarymason
 
Html5 Canvas and Mobile Graphics
Html5 Canvas and Mobile GraphicsHtml5 Canvas and Mobile Graphics
Html5 Canvas and Mobile GraphicsEngin Hatay
 
Css3 transitions and animations + graceful degradation with jQuery
Css3 transitions and animations + graceful degradation with jQueryCss3 transitions and animations + graceful degradation with jQuery
Css3 transitions and animations + graceful degradation with jQueryAndrea Verlicchi
 
Modern Web Development
Modern Web DevelopmentModern Web Development
Modern Web DevelopmentRobert Dawson
 
Responsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and TechniquesResponsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and TechniquesVitaly Friedman
 
Vector Graphics on the Web: SVG, Canvas, CSS3
Vector Graphics on the Web: SVG, Canvas, CSS3Vector Graphics on the Web: SVG, Canvas, CSS3
Vector Graphics on the Web: SVG, Canvas, CSS3Pascal Rettig
 
10 Advanced CSS Techniques (You Wish You Knew More About)
10 Advanced CSS Techniques (You Wish You Knew More About)10 Advanced CSS Techniques (You Wish You Knew More About)
10 Advanced CSS Techniques (You Wish You Knew More About)Emily Lewis
 
The web standards gentleman: a matter of (evolving) standards)
The web standards gentleman: a matter of (evolving) standards)The web standards gentleman: a matter of (evolving) standards)
The web standards gentleman: a matter of (evolving) standards)Chris Mills
 

Similar to Rockstar Graphics with HTML5 (20)

Intro to CSS3
Intro to CSS3Intro to CSS3
Intro to CSS3
 
Psd 2 Drupal
Psd 2 DrupalPsd 2 Drupal
Psd 2 Drupal
 
Trendsetting: Web Design and Beyond
Trendsetting: Web Design and BeyondTrendsetting: Web Design and Beyond
Trendsetting: Web Design and Beyond
 
CSS3: Ripe and Ready to Respond
CSS3: Ripe and Ready to RespondCSS3: Ripe and Ready to Respond
CSS3: Ripe and Ready to Respond
 
Talk Paris Infovis 091207132953 Phpapp01(2)
Talk Paris Infovis 091207132953 Phpapp01(2)Talk Paris Infovis 091207132953 Phpapp01(2)
Talk Paris Infovis 091207132953 Phpapp01(2)
 
Using Web Standards to create Interactive Data Visualizations for the Web
Using Web Standards to create Interactive Data Visualizations for the WebUsing Web Standards to create Interactive Data Visualizations for the Web
Using Web Standards to create Interactive Data Visualizations for the Web
 
Iagc2
Iagc2Iagc2
Iagc2
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
 
Sugarcoating your frontend one ViewModel at a time
Sugarcoating your frontend one ViewModel at a timeSugarcoating your frontend one ViewModel at a time
Sugarcoating your frontend one ViewModel at a time
 
Designing in the Browser - Mason Wendell, Drupaldelphia
Designing in the Browser - Mason Wendell, DrupaldelphiaDesigning in the Browser - Mason Wendell, Drupaldelphia
Designing in the Browser - Mason Wendell, Drupaldelphia
 
Html5 Whats around the bend
Html5 Whats around the bendHtml5 Whats around the bend
Html5 Whats around the bend
 
The Coding Designer's Survival Kit - Capital Camp
The Coding Designer's Survival Kit - Capital CampThe Coding Designer's Survival Kit - Capital Camp
The Coding Designer's Survival Kit - Capital Camp
 
Html5 Canvas and Mobile Graphics
Html5 Canvas and Mobile GraphicsHtml5 Canvas and Mobile Graphics
Html5 Canvas and Mobile Graphics
 
Css3 transitions and animations + graceful degradation with jQuery
Css3 transitions and animations + graceful degradation with jQueryCss3 transitions and animations + graceful degradation with jQuery
Css3 transitions and animations + graceful degradation with jQuery
 
Modern Web Development
Modern Web DevelopmentModern Web Development
Modern Web Development
 
Responsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and TechniquesResponsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and Techniques
 
Vector Graphics on the Web: SVG, Canvas, CSS3
Vector Graphics on the Web: SVG, Canvas, CSS3Vector Graphics on the Web: SVG, Canvas, CSS3
Vector Graphics on the Web: SVG, Canvas, CSS3
 
10 Advanced CSS Techniques (You Wish You Knew More About)
10 Advanced CSS Techniques (You Wish You Knew More About)10 Advanced CSS Techniques (You Wish You Knew More About)
10 Advanced CSS Techniques (You Wish You Knew More About)
 
The web standards gentleman: a matter of (evolving) standards)
The web standards gentleman: a matter of (evolving) standards)The web standards gentleman: a matter of (evolving) standards)
The web standards gentleman: a matter of (evolving) standards)
 
Css3
Css3Css3
Css3
 

Recently uploaded

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 

Recently uploaded (20)

Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 

Rockstar Graphics with HTML5

  • 1.
  • 2. Rockstar Graphics with HTML5 Dave Balmer, Gobico Games Developer of Wobble Words and Poker Drops April 24, 2010
  • 3. A Clean Slate for Web Developers Breaking your skills out of the browser
  • 4. A Clean Slate for Web Developers Breaking your skills out of the browser • JavaScript is the focus instead of an addition • HTML and the DOM provide basic structure; layered semantic markup is not a priority • CSS is the presentation workhorse • Browser compatibility is not an issue, so development is faster • Most frameworks designed for browsers are not optimal for mobile devices because they’re firmly entrenched in browser-centric approaches (I’m looking at you, JQuery)
  • 6. The Webkit Stack JavaScript is front and center App Process JavaScript Canvas CSS3 Webkit Linux Kernel ARM CPU Hardware Graphics
  • 7. Rockstar Graphics with HTML5 Getting the most out of native code (without coding native)
  • 8. Rockstar Graphics with HTML5 Getting the most out of native code (without coding native) • Canvas Element • CSS3 • Layering techniques • Efficient JavaScript • Trickery
  • 10. Canvas Element What it is and when to use it • An empty box element where JavaScript directly draws lines, shapes, images, and other 2D primitives • Very similar concept to Java2D and Quartz 2D • Sophisticated path construction with strokes and fills • Image layering and transformation • Uses native code under the hood, so render time is fast • Use it to break outside the DOM “box” model • Ad-hoc graphs and charts • Synchronized animation with multiple images
  • 11. Sample Code: Line Graph A simple Canvas example • Basic stage • Simple “Graph” class • Array goes in • Graph goes out • Auto-scales Break away to example before clicking -- reveal screen after code walkthru
  • 12. Sample Code: Line Graph A simple Canvas example • Basic stage • Simple “Graph” class • Array goes in • Graph goes out • Auto-scales • Boring! Break away to example before • Does illustrate the point clicking -- reveal screen after code • Definitely not “Rockstar” material walkthru • We’ll add some goodies later
  • 13. Canvas: Other Uses Drawing lines is fine, but you can do a lot more • Image manipulation • Transformations (scale, rotate) • Compositing (think Photoshop layers) • Animation • Sprites • Complex physics • The downside: your animation loop will be in JavaScript, which can be difficult to get great performance
  • 14. Canvas Gotchas Current limitations to keep in mind • Today’s webOS Canvas element has limitations: • No pixel operations (getImageData, putImageData) • No shadows (shadowOffsetX/Y, shadowBlur, shadowColor) • Cannot save raster contents of canvas (toDataURL) • No “round” or “mitre” lineJoin or lineCap (“bevel” only)
  • 15. Canvas Gotchas Current limitations to keep in mind • Today’s webOS Canvas element has limitations: • No pixel operations (getImageData, putImageData) • No shadows (shadowOffsetX/Y, shadowBlur, shadowColor) • Cannot save raster contents of canvas (toDataURL) • No “round” or “mitre” lineJoin or lineCap (“bevel” only) • And Text? Forget it. • The W3 spec for Canvas text rendering is exciting, but largely unsupported anywhere • Layering with DOM/CSS3 is the practical approach for now
  • 16. CSS3
  • 17. CSS3 Mention the excitingg news about 3D and What it is and when to use it hardware accelerated transitions • Sophisticated declarative styling language • Pixel-perfect font, color, image properties • Scale, rotate, stretch, and move any DOM element • Animate property changes with simple physics • Huge benefits for • Adding unique and consistent look and feel to your apps • Creating your own specialized widgets • Simple, unsynchronized animations
  • 18. Sample Code: Screensaver A contrived yet fun example of CSS3 animation • CSS3 animation • Minimal JavaScript • Timer loop • Setting properties • Letting CSS do the hard stuff Break away to example before clicking -- reveal screen after code walkthru
  • 19. Sample Code: Screensaver A contrived yet fun example of CSS3 animation • CSS3 animation • Minimal JavaScript • Timer loop • Setting properties • Letting CSS do the hard stuff Break away to example before clicking -- reveal screen after code walkthru
  • 20. CSS3 Gotchas Current webOS limitations to keep in mind
  • 21. CSS3 Gotchas Current webOS limitations to keep in mind • No custom fonts • No textShadow or boxShadow (bummer) • No gradients • Have to use gradient background images today • No transitionEnd event • Limits synchronized animation chaining • For now, have to use setTimeout to match transition interval and “hope for the best”
  • 23. Layering Using CSS3 and Canvas elements together can be powerful • Both can be controlled with JavaScript • A good example is a network diagram:
  • 24. Layering Using CSS3 and Canvas elements together can be powerful • Both can be controlled with JavaScript • A good example is a network diagram: CSS Styled Elements + Canvas 2D Lines 2 5 1 4 7 3 6
  • 25. Sample Code: Line Graph + Our first Canvas example was pretty boring • Canvas still draws the graph • CSS adds some spice • Activate/deactivate animation • More interesting styling • No additional JavaScript
  • 26. Sample Code: Line Graph + Our first Canvas example was pretty boring • Canvas still draws the graph • CSS adds some spice • Activate/deactivate animation • More interesting styling • No additional JavaScript
  • 27. Mix and Match for the Win Feature CSS Canvas Text Styling ✔ 2D Drawing Primitives ✔ Sprite Animation ✔ ✔ Generated Gradients ✔ Image Transformations ✔ ✔ “Set it and forget it” Animation ✔ Synchronized Animation ✔ Layered transitions ✔ Layered transformations ✔
  • 28. Mix and Match for the Win Dipping into both Canvas and CSS techniques Feature CSS Canvas Text Styling ✔ 2D Drawing Primitives ✔ Sprite Animation ✔ ✔ Generated Gradients ✔ Image Transformations ✔ ✔ “Set it and forget it” Animation ✔ Synchronized Animation ✔ Layered transitions ✔ Layered transformations ✔
  • 29. Layering Example: Poker Drops A quick peek at this game currently in testing • CSS3 Animations • Menu and UI transitions • Dealing cards • Rotating the game board to match device orientation • Custom scroller widget with basic physics • Canvas • Drawing the path between poker cards • Game timer
  • 30. Layering Example: Poker Drops A quick peek at this game currently in testing • CSS3 Animations • Menu and UI transitions • Dealing cards • Rotating the game board to match device orientation • Custom scroller widget with basic physics • Canvas • Drawing the path between poker cards • Game timer
  • 32. JavaScript Performance Efficiencies Boils down to taking all unnecessary computation out of loops • Pre-compute everything • Make the native code do more work by using CSS3, built-in array operations and other goodies wherever possible • Reduce garbage collection impact by re-using objects instead of tossing them
  • 33. Trickery: Examples Taking a second look at some of the goodness in the examples • Graph • Simple array-in, graph-out structure • Fancy transitions done with CSS3 • Screensaver Pull up graph example, walk thru use of CSS to offload the • CSS3 does all the heavy lifting goodies, and simple array processing • Our timer loop does very little • Our “random” animation paths are built from pre- computed data
  • 35. What We Can Look Forward To Palm is on board—here’s hoping for speedy implementation • More complete CSS3 implementation • More complete Canvas implementation • Hardware accelerated CSS! • Canvas 3D • WebGL • 3D Transformations in CSS3
  • 36. Q &A
  • 37. More Information Dave Balmer, Gobico Games @balmer dave@gobico.com http://gobico.com Good CSS and HTML5 Walkthroughs http://css3.info http://diveintohtml5.org “Far Out Fowl” Canvas Game Development Tutorial http://bit.ly/cdfuQb

Editor's Notes