際際滷

際際滷Share a Scribd company logo
Rockstar Graphics with HTML5
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 theyre 鍖rmly
  entrenched in browser-centric approaches (Im
  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 鍖lls
   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
   De鍖nitely not Rockstar material   walkthru
   Well add some goodies later
Canvas: Other Uses
Drawing lines is 鍖ne, 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


 Todays 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


 Todays 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 bene鍖ts 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 鍖rst 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 鍖rst 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 of鍖oad 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 boardheres 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
Ad

Recommended

Svcc 2013-css3-and-mobile
Svcc 2013-css3-and-mobile
Oswald Campesato
Choosing your animation adventure - Generate NYC 2018
Choosing your animation adventure - Generate NYC 2018
Val Head
Next generation Graphics: SVG
Next generation Graphics: SVG
David Corbacho Rom叩n
Dive into HTML5: SVG and Canvas
Dive into HTML5: SVG and Canvas
Doris Chen
Learn svg
Learn svg
FitBlar Mit
HTML5 and SVG
HTML5 and SVG
yarcub
Html5 more than just html5 v final
Html5 more than just html5 v final
Lohith Goudagere Nagaraj
Make your own Print & Play card game using SVG and JavaScript
Make your own Print & Play card game using SVG and JavaScript
Kevin Hakanson
Drupal Backbone.js in the Frontend
Drupal Backbone.js in the Frontend
David Corbacho Rom叩n
Simply Responsive CSS3
Simply Responsive CSS3
Denise Jacobs
Before Going Vector
Before Going Vector
david deraedt
SVG - Scalable Vector Graphic
SVG - Scalable Vector Graphic
Akila Iroshan
Deliverance - a compelling way to theme Plone sites
Deliverance - a compelling way to theme Plone sites
Jazkarta, Inc.
Svg
Svg
Steve Fort
CSS3: Ripe and Ready
CSS3: Ripe and Ready
Denise Jacobs
Introduction to HTML5
Introduction to HTML5
Kunal Johar
From Flash to Canvas - a penchant for black holes
From Flash to Canvas - a penchant for black holes
Patric Lanhed
Rockstar Graphics with HTML5 @Media UK
Rockstar Graphics with HTML5 @Media UK
Dave Balmer
HTML5 - A Whirlwind tour
HTML5 - A Whirlwind tour
Lohith Goudagere Nagaraj
Javascript Animation with Canvas - Gregory Starr 2015
Javascript Animation with Canvas - Gregory Starr 2015
Gregory Starr
Toronto HTML5 User Group Meet Up #2 Application Development with HTML 5
Toronto HTML5 User Group Meet Up #2 Application Development with HTML 5
Nathaniel Bagnell
What is HTML5
What is HTML5
Kyohei Morimoto
HTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web Games
livedoor
Building a Better Web with HTML5 and CSS3
Building a Better Web with HTML5 and CSS3
Karambir Singh Nain
HTML5: An Overview
HTML5: An Overview
Nagendra Um
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)
Felix Faber
Building a game engine with jQuery
Building a game engine with jQuery
Paul Bakaus
A Holistic Approach to HTML5 Game Design & Development
A Holistic Approach to HTML5 Game Design & Development
Karl Bunyan
Rapid Evolution of Web Dev? aka Talking About The Web
Rapid Evolution of Web Dev? aka Talking About The Web
PINT Inc
Html5
Html5
Ahmed Jadalla

More Related Content

What's hot (8)

Drupal Backbone.js in the Frontend
Drupal Backbone.js in the Frontend
David Corbacho Rom叩n
Simply Responsive CSS3
Simply Responsive CSS3
Denise Jacobs
Before Going Vector
Before Going Vector
david deraedt
SVG - Scalable Vector Graphic
SVG - Scalable Vector Graphic
Akila Iroshan
Deliverance - a compelling way to theme Plone sites
Deliverance - a compelling way to theme Plone sites
Jazkarta, Inc.
Svg
Svg
Steve Fort
CSS3: Ripe and Ready
CSS3: Ripe and Ready
Denise Jacobs
Introduction to HTML5
Introduction to HTML5
Kunal Johar
Simply Responsive CSS3
Simply Responsive CSS3
Denise Jacobs
Before Going Vector
Before Going Vector
david deraedt
SVG - Scalable Vector Graphic
SVG - Scalable Vector Graphic
Akila Iroshan
Deliverance - a compelling way to theme Plone sites
Deliverance - a compelling way to theme Plone sites
Jazkarta, Inc.
CSS3: Ripe and Ready
CSS3: Ripe and Ready
Denise Jacobs
Introduction to HTML5
Introduction to HTML5
Kunal Johar

Similar to Rockstar Graphics with HTML5 (20)

From Flash to Canvas - a penchant for black holes
From Flash to Canvas - a penchant for black holes
Patric Lanhed
Rockstar Graphics with HTML5 @Media UK
Rockstar Graphics with HTML5 @Media UK
Dave Balmer
HTML5 - A Whirlwind tour
HTML5 - A Whirlwind tour
Lohith Goudagere Nagaraj
Javascript Animation with Canvas - Gregory Starr 2015
Javascript Animation with Canvas - Gregory Starr 2015
Gregory Starr
Toronto HTML5 User Group Meet Up #2 Application Development with HTML 5
Toronto HTML5 User Group Meet Up #2 Application Development with HTML 5
Nathaniel Bagnell
What is HTML5
What is HTML5
Kyohei Morimoto
HTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web Games
livedoor
Building a Better Web with HTML5 and CSS3
Building a Better Web with HTML5 and CSS3
Karambir Singh Nain
HTML5: An Overview
HTML5: An Overview
Nagendra Um
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)
Felix Faber
Building a game engine with jQuery
Building a game engine with jQuery
Paul Bakaus
A Holistic Approach to HTML5 Game Design & Development
A Holistic Approach to HTML5 Game Design & Development
Karl Bunyan
Rapid Evolution of Web Dev? aka Talking About The Web
Rapid Evolution of Web Dev? aka Talking About The Web
PINT Inc
Html5
Html5
Ahmed Jadalla
Graphics on the Go
Graphics on the Go
Gil Irizarry
HTML5 for Rich User Experience
HTML5 for Rich User Experience
Mahbubur Rahman
Finding harmony in web development
Finding harmony in web development
Christian Heilmann
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JS
Naga Harish M
HTML5: The Future of Web Development with IE9, IE10 and Windows 8
HTML5: The Future of Web Development with IE9, IE10 and Windows 8
Shaymaa
How to build a html5 websites.v1
How to build a html5 websites.v1
Bitla Software
From Flash to Canvas - a penchant for black holes
From Flash to Canvas - a penchant for black holes
Patric Lanhed
Rockstar Graphics with HTML5 @Media UK
Rockstar Graphics with HTML5 @Media UK
Dave Balmer
Javascript Animation with Canvas - Gregory Starr 2015
Javascript Animation with Canvas - Gregory Starr 2015
Gregory Starr
Toronto HTML5 User Group Meet Up #2 Application Development with HTML 5
Toronto HTML5 User Group Meet Up #2 Application Development with HTML 5
Nathaniel Bagnell
HTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web Games
livedoor
Building a Better Web with HTML5 and CSS3
Building a Better Web with HTML5 and CSS3
Karambir Singh Nain
HTML5: An Overview
HTML5: An Overview
Nagendra Um
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)
Felix Faber
Building a game engine with jQuery
Building a game engine with jQuery
Paul Bakaus
A Holistic Approach to HTML5 Game Design & Development
A Holistic Approach to HTML5 Game Design & Development
Karl Bunyan
Rapid Evolution of Web Dev? aka Talking About The Web
Rapid Evolution of Web Dev? aka Talking About The Web
PINT Inc
Graphics on the Go
Graphics on the Go
Gil Irizarry
HTML5 for Rich User Experience
HTML5 for Rich User Experience
Mahbubur Rahman
Finding harmony in web development
Finding harmony in web development
Christian Heilmann
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JS
Naga Harish M
HTML5: The Future of Web Development with IE9, IE10 and Windows 8
HTML5: The Future of Web Development with IE9, IE10 and Windows 8
Shaymaa
How to build a html5 websites.v1
How to build a html5 websites.v1
Bitla Software
Ad

Recently uploaded (20)

Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
Wenn alles versagt - IBM Tape sch端tzt, was z辰hlt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape sch端tzt, was z辰hlt! Und besonders mit dem neust...
Josef Weingand
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
Wenn alles versagt - IBM Tape sch端tzt, was z辰hlt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape sch端tzt, was z辰hlt! Und besonders mit dem neust...
Josef Weingand
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
Ad

Rockstar Graphics with HTML5

  • 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 theyre 鍖rmly entrenched in browser-centric approaches (Im 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 鍖lls 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 De鍖nitely not Rockstar material walkthru Well add some goodies later
  • 13. Canvas: Other Uses Drawing lines is 鍖ne, 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 Todays 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 Todays 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 bene鍖ts 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 鍖rst 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 鍖rst 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 of鍖oad 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 boardheres 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