SlideShare a Scribd company logo
HTML5 Animation
in Mobile Web Games

Sangmin, Shim
Speaker
What is Animation?
HTML5 Animation in Mobile Web Games
文, 絵 ゾングダゾング



twitter @yameyori
e-mail usamibabe@naver.com
webtoon http://comic.naver.com/webtoon/list.nhn?titleId=409630
Animation is the rapid display of
a sequence of images to create
   an illusion of movement.
Each image contains small
changes in movement, rotation,
           scale …
HTML5 Animation in Mobile Web Games
Let’s see more detail
1. Resource Management
Resource Management




    Loading Image
Resource Management

• Game or Animation contains many
  resources. Each resource size is bigger
  than resources in web pages(larger than
  3Mbytes)
Resource Management

• Loading screens are required to load
  resources
Resource Management

• Always load resources asynchronously
  var img = document.createElement(“img”);
  img.onload = function () {
      alert("ok!");
  };
  img.onerror = function () {
      alert("error");
  };

  img.src = "test.png";
  document.body.appendChild(img);
2. Objectivation
Objectivation




  abstraction into an object
Objectivation

• DOM Elements can be handled separately.
  However objects cannot be handled
  separately in HTML5 Canvas




 DOM Elements have regions each   Canvas draw object to one Context
Objectivation
          Objects that contain the necessary information is required
          when drawing

                                     Canvas
Objectivation

• Contains position and properties for
  display.
            var oItem = new Item();
            oItem.width = 100;
            oItem.height = 100;
            oItem.x = 50;
            oItem.y = 150;
            oItem.color = "#123456";
            oItem.visible = true;
3. Animation
Animation




            Animation
Animation

• Rendering-Pipeline must be used to tackle
  multiple objects simultaneously.

                           no


                Register        Is there    yes     Draw
   Initialize                   updated
                Pipeline        object?             object




                                   one tick cycle
Animation
 // drawing
 function draw() {
     // clear canvas
     ctx.clearRect(0, 0, ctx.canvas.width,
 ctx.canvas.height);

      // draw each object.
      for (var i = 0; i < list.length; i++) {
          list[i].drawEachObject();
      }
 };

 // repeat 60 times per second
 setInterval(draw, 1000 / 60);
Animation




     draw   draw   draw   draw   draw


       Repeat 60 times per second
Why is it repeated 60 times per second?
• Most PC monitors show 60 frames per
  second. Therefore, there is no point in
  making animation that is 60 FPS.
Using requestAnimationFrame
instead of setInterval
• requestAnimationFrame is the browser's native
  way of handling animations.
• Helps get a smooth 60 frames per second.
• iOS6 supports requestAnimationFrame.
 function draw() {
     requestAnimationFrame(draw);
     // ...
 }

 requestAnimationFrame(draw);
4. Drawing
Clear Canvas

• Using drawRect method
  var ctx = elCanvas.getContext("2d");
  ctx.fillStyle = "#ffffff";
  ctx.drawRect(0, 0, elCanvas.width, elCanvas.height);

  It's slow.



• Reset width or height attributes
  elCanvas.width = 100;
  elCanvas.height = 100;

  It's fast on old browser.
Clear Canvas

• Using clearRect method
  var ctx = elCanvas.getContext(“2d”);
  ctx.clearRect(0, 0, elCanvas.width, elCanvas.height);



  Fast on most browsers.
Sprite Animation

• A Sprite Animation is a two-dimension
  image that is integrated into a larger scene
Sprite Animation in Canvas

• Using drawImage method
  var ctx = elCanvas.getContext("2d");
  ctx.drawImage(target Element, sourceX,
  sourceY, sourceWidth, sourceHeight,
  targetX, targetY, targetWidth,
  targetHeight);

Source x,y,width,height               Target x,y,width,height


                          drawImage
Pixel Manipulation

• Using different size sources and targets
  results in low performance in iOS4. Use
  drawImage method with original dimension.



                               drawImage




Pixel manipulation occurs when using different dimensions
                       with source.
Avoid Floating Coordinates

• When floating point coordinates are used,
  anti-aliasing is automatically used to try to
  smooth out the lines.
5. Event
Event Processing
• Inspect and see if the location the event occurred is in
  each object’s region in order to find objects that are
  related to event.
 for (var i in list) {
     if (
          list[i].x <= mouseX &&
          mouseX <= list[i].x + list[i].width &&
          list[i].y <= mouseY &&
          mouseY <= list[i].y + list[i].height
     ) {
          // region of this object contains mouse
 point
     }
 }
Event Processing
• The aforementioned method only recognizes objects as
  rectangles.
• More detail is needed to detect objects.
Event Processing
• getImageData method can be used to get pixel data
 var imageData = ctx.getImageData(mouseX,
 mouseY, 1, 1);

 if (imageData.data[0]       !== 0 ||
 imageData.data[1] !==       0 ||
 imageData.data[2] !==       0 ||
 imageData.data[3] !==       0) {
     // a pixel is not       empty data
 }
Security with Canvas Element
• Information leakage can occur if scripts from one origin
  can access information (e.g. read pixels) from images
  from another origin (one that isn't the same).
• The toDataURL(), toBlob(), and getImageData() methods
  check the flag and will throw a SecurityError exception
  rather than leak cross-origin data.
Animation Demo

      iOS5
Animation Demo

      iOS4
What the?!?!
Hardware Acceleration
• Safari in iOS5 and up has GPU accelerated Mobile
  Canvas implementation.
• Without GPU Acceleration, mobile browsers generally
  have poor performance for Canvas.
Using CSS 3D Transforms
• CSS 3D Transforms supports iOS4 and Android 3 and
  above.
• Using the following CSS3 style with webkit prefix

  .displayObject {
  -webkit-transform:translate3d(x,y,z)
  scale3d(x, y, z) rotateZ(deg);
  -wekit-transform-origin:0 0;
  -webkit-transform-style:preserve-3d;
  }
Sprite Animation in DOM
• A child image element is needed to use only the CSS 3D
  Transforms.


              overflow:hidden

              DIV

               IMG
Sprite Animation in DOM
 <div style="position:absolute;
 overflow:hidden; width:100px;
 height:100px; -webkit-
 transform:translate3d(100px, 100px, 0);
 ">
     <img src="sprite.png"
 style="position:absolute; -webkit-
 transform:translate3d(-100px, 0, 0); "
 border="0" alt="" />
 </div>
CSS 3D Transforms
 Animation Demo
       iOS4
Is that all?
HTML5 Animation in Mobile Web Games
Performance different on each device

• iOS4 supports CSS 3D Transforms with
  Hardware Acceleration(H/A)
• iOS5 supports Canvas with H/A
• There is no solution on Anroid 2.x devices.
• Androind ICS supports CSS 3D
  Transforms with H/A
Choose Rendering method


                                               under     over
  Device/    iPhone     iPhone       iPhone
                                              Android   Android
    OS         3GS         4           4S
                                                 3         3

                         CSS3D
                      (under iOS4)            Canvas
 Rendering
             CSS3D                   Canvas     or      CSS3D
  Method
                        Canvas                 DOM
                      (over iOS5)
Be careful using Android CSS 3D Transforms
• Unfortunately, Android ICS has many bugs associated
  with CSS 3D Transforms
• The image turns black if an image that has a dimension
  of over 2048 pixels is used.
• When an element that has a CSS overflow attribute with
  a hidden value is rotated, then that hidden area becomes
  visible.
Need to optimize detailed
• Tick occurs 60 times per second.
• If 100 objects are made, a logic in drawing object occurs
  6,000 times per second.
There is a solution for you
Collie
HTML5 Animation in Mobile Web Games
Collie

• Collie is a high performance animation library for
  javascript
• Collie supports more than 13 mobile devices
  and PCs with its optimized methods.
Collie

• Collie supports retina display
Collie

• Collie supports detail region to detect object in
  both Canvas and DOM
• Collie provides tool to make path about object
  shape.
Collie

• Collie supports object cache for better speed
• Collie is most effective for drawing that requires
  a lot of cost.




                                  Drawing
Collie is an opensource project

      LGPL v2.1
For more detailed information, visit
 http://jindo.dev.naver.com/collie
HTML5 Animation in Mobile Web Games
Ad

More Related Content

What's hot (19)

3Dtexture_doc_rep
3Dtexture_doc_rep3Dtexture_doc_rep
3Dtexture_doc_rep
Liu Zhen-Yu
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 Canvas
Henry Osborne
 
HTML 5_Canvas
HTML 5_CanvasHTML 5_Canvas
HTML 5_Canvas
Vishakha Vaidya
 
HTML 5 Canvas & SVG
HTML 5 Canvas & SVGHTML 5 Canvas & SVG
HTML 5 Canvas & SVG
Ofir's Fridman
 
Chapter 02 sprite and texture
Chapter 02 sprite and textureChapter 02 sprite and texture
Chapter 02 sprite and texture
boybuon205
 
WebGL and three.js - Web 3D Graphics
WebGL and three.js - Web 3D Graphics WebGL and three.js - Web 3D Graphics
WebGL and three.js - Web 3D Graphics
PSTechSerbia
 
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
Ontico
 
Getting Started with 3D Game Development on Nokia Series 40 Asha Phones
Getting Started with 3D Game Development on Nokia Series 40 Asha PhonesGetting Started with 3D Game Development on Nokia Series 40 Asha Phones
Getting Started with 3D Game Development on Nokia Series 40 Asha Phones
Microsoft Mobile Developer
 
HTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebHTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the Web
Robin Hawkes
 
Android Vector Drawable
 Android Vector Drawable Android Vector Drawable
Android Vector Drawable
Phearum THANN
 
MIDP: Game API
MIDP: Game APIMIDP: Game API
MIDP: Game API
Jussi Pohjolainen
 
ENEI16 - WebGL with Three.js
ENEI16 - WebGL with Three.jsENEI16 - WebGL with Three.js
ENEI16 - WebGL with Three.js
José Ferrão
 
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184
Mahmoud Samir Fayed
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation Framework
Jussi Pohjolainen
 
XNA L03–Models, Basic Effect and Animation
XNA L03–Models, Basic Effect and AnimationXNA L03–Models, Basic Effect and Animation
XNA L03–Models, Basic Effect and Animation
Mohammad Shaker
 
XNA L02–Basic Matrices and Transformations
XNA L02–Basic Matrices and TransformationsXNA L02–Basic Matrices and Transformations
XNA L02–Basic Matrices and Transformations
Mohammad Shaker
 
Canvas - HTML 5
Canvas - HTML 5Canvas - HTML 5
Canvas - HTML 5
Jaeni Sahuri
 
Lec2
Lec2Lec2
Lec2
Amba Research
 
Css5 canvas
Css5 canvasCss5 canvas
Css5 canvas
Vadim Spiridenko
 
3Dtexture_doc_rep
3Dtexture_doc_rep3Dtexture_doc_rep
3Dtexture_doc_rep
Liu Zhen-Yu
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 Canvas
Henry Osborne
 
Chapter 02 sprite and texture
Chapter 02 sprite and textureChapter 02 sprite and texture
Chapter 02 sprite and texture
boybuon205
 
WebGL and three.js - Web 3D Graphics
WebGL and three.js - Web 3D Graphics WebGL and three.js - Web 3D Graphics
WebGL and three.js - Web 3D Graphics
PSTechSerbia
 
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
Ontico
 
Getting Started with 3D Game Development on Nokia Series 40 Asha Phones
Getting Started with 3D Game Development on Nokia Series 40 Asha PhonesGetting Started with 3D Game Development on Nokia Series 40 Asha Phones
Getting Started with 3D Game Development on Nokia Series 40 Asha Phones
Microsoft Mobile Developer
 
HTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebHTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the Web
Robin Hawkes
 
Android Vector Drawable
 Android Vector Drawable Android Vector Drawable
Android Vector Drawable
Phearum THANN
 
ENEI16 - WebGL with Three.js
ENEI16 - WebGL with Three.jsENEI16 - WebGL with Three.js
ENEI16 - WebGL with Three.js
José Ferrão
 
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184
Mahmoud Samir Fayed
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation Framework
Jussi Pohjolainen
 
XNA L03–Models, Basic Effect and Animation
XNA L03–Models, Basic Effect and AnimationXNA L03–Models, Basic Effect and Animation
XNA L03–Models, Basic Effect and Animation
Mohammad Shaker
 
XNA L02–Basic Matrices and Transformations
XNA L02–Basic Matrices and TransformationsXNA L02–Basic Matrices and Transformations
XNA L02–Basic Matrices and Transformations
Mohammad Shaker
 

Viewers also liked (14)

ロケタッチの裏側
ロケタッチの裏側ロケタッチの裏側
ロケタッチの裏側
livedoor
 
REDRAFT - Resume Martin Firth 2017-01-03
REDRAFT - Resume Martin Firth 2017-01-03REDRAFT - Resume Martin Firth 2017-01-03
REDRAFT - Resume Martin Firth 2017-01-03
Martin Firth
 
Solr Payloads for Ranking Data
Solr Payloads for Ranking Data Solr Payloads for Ranking Data
Solr Payloads for Ranking Data
BloomReach
 
RocksDB meetup
RocksDB meetupRocksDB meetup
RocksDB meetup
Javier González
 
Web Animation Buffet
Web Animation BuffetWeb Animation Buffet
Web Animation Buffet
joshsager
 
HxRefactored: Rebounding with Web Animation by Nick Snyder
HxRefactored: Rebounding with Web Animation by Nick SnyderHxRefactored: Rebounding with Web Animation by Nick Snyder
HxRefactored: Rebounding with Web Animation by Nick Snyder
HxRefactored
 
Crafting animation on the web
Crafting animation on the webCrafting animation on the web
Crafting animation on the web
Benjy Stanton
 
Facilitating product discovery in e-commerce inventory, The Fifth elephant, 2016
Facilitating product discovery in e-commerce inventory, The Fifth elephant, 2016Facilitating product discovery in e-commerce inventory, The Fifth elephant, 2016
Facilitating product discovery in e-commerce inventory, The Fifth elephant, 2016
Ekta Grover
 
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Rami Sayar
 
Understanding Computers: Today and Tomorrow, 13th Edition Chapter 10 - Multim...
Understanding Computers: Today and Tomorrow, 13th Edition Chapter 10 - Multim...Understanding Computers: Today and Tomorrow, 13th Edition Chapter 10 - Multim...
Understanding Computers: Today and Tomorrow, 13th Edition Chapter 10 - Multim...
yaminohime
 
Serious Animation (an introduction to Web Animations)
Serious Animation (an introduction to Web Animations)Serious Animation (an introduction to Web Animations)
Serious Animation (an introduction to Web Animations)
brianskold
 
Animation meet web
Animation meet webAnimation meet web
Animation meet web
Taufshwara Diasriandaru
 
Animation
AnimationAnimation
Animation
ankur bhalla
 
Network Security Threats and Solutions
Network Security Threats and SolutionsNetwork Security Threats and Solutions
Network Security Threats and Solutions
Colin058
 
ロケタッチの裏側
ロケタッチの裏側ロケタッチの裏側
ロケタッチの裏側
livedoor
 
REDRAFT - Resume Martin Firth 2017-01-03
REDRAFT - Resume Martin Firth 2017-01-03REDRAFT - Resume Martin Firth 2017-01-03
REDRAFT - Resume Martin Firth 2017-01-03
Martin Firth
 
Solr Payloads for Ranking Data
Solr Payloads for Ranking Data Solr Payloads for Ranking Data
Solr Payloads for Ranking Data
BloomReach
 
Web Animation Buffet
Web Animation BuffetWeb Animation Buffet
Web Animation Buffet
joshsager
 
HxRefactored: Rebounding with Web Animation by Nick Snyder
HxRefactored: Rebounding with Web Animation by Nick SnyderHxRefactored: Rebounding with Web Animation by Nick Snyder
HxRefactored: Rebounding with Web Animation by Nick Snyder
HxRefactored
 
Crafting animation on the web
Crafting animation on the webCrafting animation on the web
Crafting animation on the web
Benjy Stanton
 
Facilitating product discovery in e-commerce inventory, The Fifth elephant, 2016
Facilitating product discovery in e-commerce inventory, The Fifth elephant, 2016Facilitating product discovery in e-commerce inventory, The Fifth elephant, 2016
Facilitating product discovery in e-commerce inventory, The Fifth elephant, 2016
Ekta Grover
 
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Rami Sayar
 
Understanding Computers: Today and Tomorrow, 13th Edition Chapter 10 - Multim...
Understanding Computers: Today and Tomorrow, 13th Edition Chapter 10 - Multim...Understanding Computers: Today and Tomorrow, 13th Edition Chapter 10 - Multim...
Understanding Computers: Today and Tomorrow, 13th Edition Chapter 10 - Multim...
yaminohime
 
Serious Animation (an introduction to Web Animations)
Serious Animation (an introduction to Web Animations)Serious Animation (an introduction to Web Animations)
Serious Animation (an introduction to Web Animations)
brianskold
 
Network Security Threats and Solutions
Network Security Threats and SolutionsNetwork Security Threats and Solutions
Network Security Threats and Solutions
Colin058
 
Ad

Similar to HTML5 Animation in Mobile Web Games (20)

High Performance Mobile Web Game Development in HTML5
High Performance Mobile Web Game Development in HTML5High Performance Mobile Web Game Development in HTML5
High Performance Mobile Web Game Development in HTML5
Sangmin Shim
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricks
deanhudson
 
Mapping the world with Twitter
Mapping the world with TwitterMapping the world with Twitter
Mapping the world with Twitter
carlo zapponi
 
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
Vitaly Friedman
 
Canvas in html5 - TungVD
Canvas in html5 - TungVDCanvas in html5 - TungVD
Canvas in html5 - TungVD
Framgia Vietnam
 
Iagc2
Iagc2Iagc2
Iagc2
Lee Lundrigan
 
Power of canvas
Power of canvasPower of canvas
Power of canvas
chrismartinez99
 
Building a game engine with jQuery
Building a game engine with jQueryBuilding a game engine with jQuery
Building a game engine with jQuery
Paul Bakaus
 
Image_Processing_LECTURE_c#_programming.ppt
Image_Processing_LECTURE_c#_programming.pptImage_Processing_LECTURE_c#_programming.ppt
Image_Processing_LECTURE_c#_programming.ppt
LOUISSEVERINOROMANO
 
Rwd slidedeck
Rwd slidedeckRwd slidedeck
Rwd slidedeck
Vera Kovaleva
 
Responsive Web Design tips and tricks.
Responsive Web Design tips and tricks.Responsive Web Design tips and tricks.
Responsive Web Design tips and tricks.
GaziAhsan
 
Whats new in Feathers 3.0?
Whats new in Feathers 3.0?Whats new in Feathers 3.0?
Whats new in Feathers 3.0?
Josh Tynjala
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
Blazing Cloud
 
Graphics on the Go
Graphics on the GoGraphics on the Go
Graphics on the Go
Gil Irizarry
 
Responsive images, an html 5.1 standard
Responsive images, an html 5.1 standardResponsive images, an html 5.1 standard
Responsive images, an html 5.1 standard
Andrea Verlicchi
 
FITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesFITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive Images
Rami Sayar
 
Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)
Marakana Inc.
 
Picture Perfect: Images for Coders
Picture Perfect: Images for CodersPicture Perfect: Images for Coders
Picture Perfect: Images for Coders
Kevin Gisi
 
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficientTh 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Bin Shao
 
Pointer Events in Canvas
Pointer Events in CanvasPointer Events in Canvas
Pointer Events in Canvas
deanhudson
 
High Performance Mobile Web Game Development in HTML5
High Performance Mobile Web Game Development in HTML5High Performance Mobile Web Game Development in HTML5
High Performance Mobile Web Game Development in HTML5
Sangmin Shim
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricks
deanhudson
 
Mapping the world with Twitter
Mapping the world with TwitterMapping the world with Twitter
Mapping the world with Twitter
carlo zapponi
 
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
Vitaly Friedman
 
Canvas in html5 - TungVD
Canvas in html5 - TungVDCanvas in html5 - TungVD
Canvas in html5 - TungVD
Framgia Vietnam
 
Building a game engine with jQuery
Building a game engine with jQueryBuilding a game engine with jQuery
Building a game engine with jQuery
Paul Bakaus
 
Image_Processing_LECTURE_c#_programming.ppt
Image_Processing_LECTURE_c#_programming.pptImage_Processing_LECTURE_c#_programming.ppt
Image_Processing_LECTURE_c#_programming.ppt
LOUISSEVERINOROMANO
 
Responsive Web Design tips and tricks.
Responsive Web Design tips and tricks.Responsive Web Design tips and tricks.
Responsive Web Design tips and tricks.
GaziAhsan
 
Whats new in Feathers 3.0?
Whats new in Feathers 3.0?Whats new in Feathers 3.0?
Whats new in Feathers 3.0?
Josh Tynjala
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
Blazing Cloud
 
Graphics on the Go
Graphics on the GoGraphics on the Go
Graphics on the Go
Gil Irizarry
 
Responsive images, an html 5.1 standard
Responsive images, an html 5.1 standardResponsive images, an html 5.1 standard
Responsive images, an html 5.1 standard
Andrea Verlicchi
 
FITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesFITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive Images
Rami Sayar
 
Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)
Marakana Inc.
 
Picture Perfect: Images for Coders
Picture Perfect: Images for CodersPicture Perfect: Images for Coders
Picture Perfect: Images for Coders
Kevin Gisi
 
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficientTh 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Bin Shao
 
Pointer Events in Canvas
Pointer Events in CanvasPointer Events in Canvas
Pointer Events in Canvas
deanhudson
 
Ad

Recently uploaded (20)

Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 

HTML5 Animation in Mobile Web Games

  • 1. HTML5 Animation in Mobile Web Games Sangmin, Shim
  • 5. 文, 絵 ゾングダゾング twitter @yameyori e-mail [email protected] webtoon http://comic.naver.com/webtoon/list.nhn?titleId=409630
  • 6. Animation is the rapid display of a sequence of images to create an illusion of movement.
  • 7. Each image contains small changes in movement, rotation, scale …
  • 11. Resource Management Loading Image
  • 12. Resource Management • Game or Animation contains many resources. Each resource size is bigger than resources in web pages(larger than 3Mbytes)
  • 13. Resource Management • Loading screens are required to load resources
  • 14. Resource Management • Always load resources asynchronously var img = document.createElement(“img”); img.onload = function () { alert("ok!"); }; img.onerror = function () { alert("error"); }; img.src = "test.png"; document.body.appendChild(img);
  • 16. Objectivation abstraction into an object
  • 17. Objectivation • DOM Elements can be handled separately. However objects cannot be handled separately in HTML5 Canvas DOM Elements have regions each Canvas draw object to one Context
  • 18. Objectivation Objects that contain the necessary information is required when drawing Canvas
  • 19. Objectivation • Contains position and properties for display. var oItem = new Item(); oItem.width = 100; oItem.height = 100; oItem.x = 50; oItem.y = 150; oItem.color = "#123456"; oItem.visible = true;
  • 21. Animation Animation
  • 22. Animation • Rendering-Pipeline must be used to tackle multiple objects simultaneously. no Register Is there yes Draw Initialize updated Pipeline object? object one tick cycle
  • 23. Animation // drawing function draw() { // clear canvas ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); // draw each object. for (var i = 0; i < list.length; i++) { list[i].drawEachObject(); } }; // repeat 60 times per second setInterval(draw, 1000 / 60);
  • 24. Animation draw draw draw draw draw Repeat 60 times per second
  • 25. Why is it repeated 60 times per second? • Most PC monitors show 60 frames per second. Therefore, there is no point in making animation that is 60 FPS.
  • 26. Using requestAnimationFrame instead of setInterval • requestAnimationFrame is the browser's native way of handling animations. • Helps get a smooth 60 frames per second. • iOS6 supports requestAnimationFrame. function draw() { requestAnimationFrame(draw); // ... } requestAnimationFrame(draw);
  • 28. Clear Canvas • Using drawRect method var ctx = elCanvas.getContext("2d"); ctx.fillStyle = "#ffffff"; ctx.drawRect(0, 0, elCanvas.width, elCanvas.height); It's slow. • Reset width or height attributes elCanvas.width = 100; elCanvas.height = 100; It's fast on old browser.
  • 29. Clear Canvas • Using clearRect method var ctx = elCanvas.getContext(“2d”); ctx.clearRect(0, 0, elCanvas.width, elCanvas.height); Fast on most browsers.
  • 30. Sprite Animation • A Sprite Animation is a two-dimension image that is integrated into a larger scene
  • 31. Sprite Animation in Canvas • Using drawImage method var ctx = elCanvas.getContext("2d"); ctx.drawImage(target Element, sourceX, sourceY, sourceWidth, sourceHeight, targetX, targetY, targetWidth, targetHeight); Source x,y,width,height Target x,y,width,height drawImage
  • 32. Pixel Manipulation • Using different size sources and targets results in low performance in iOS4. Use drawImage method with original dimension. drawImage Pixel manipulation occurs when using different dimensions with source.
  • 33. Avoid Floating Coordinates • When floating point coordinates are used, anti-aliasing is automatically used to try to smooth out the lines.
  • 35. Event Processing • Inspect and see if the location the event occurred is in each object’s region in order to find objects that are related to event. for (var i in list) { if ( list[i].x <= mouseX && mouseX <= list[i].x + list[i].width && list[i].y <= mouseY && mouseY <= list[i].y + list[i].height ) { // region of this object contains mouse point } }
  • 36. Event Processing • The aforementioned method only recognizes objects as rectangles. • More detail is needed to detect objects.
  • 37. Event Processing • getImageData method can be used to get pixel data var imageData = ctx.getImageData(mouseX, mouseY, 1, 1); if (imageData.data[0] !== 0 || imageData.data[1] !== 0 || imageData.data[2] !== 0 || imageData.data[3] !== 0) { // a pixel is not empty data }
  • 38. Security with Canvas Element • Information leakage can occur if scripts from one origin can access information (e.g. read pixels) from images from another origin (one that isn't the same). • The toDataURL(), toBlob(), and getImageData() methods check the flag and will throw a SecurityError exception rather than leak cross-origin data.
  • 42. Hardware Acceleration • Safari in iOS5 and up has GPU accelerated Mobile Canvas implementation. • Without GPU Acceleration, mobile browsers generally have poor performance for Canvas.
  • 43. Using CSS 3D Transforms • CSS 3D Transforms supports iOS4 and Android 3 and above. • Using the following CSS3 style with webkit prefix .displayObject { -webkit-transform:translate3d(x,y,z) scale3d(x, y, z) rotateZ(deg); -wekit-transform-origin:0 0; -webkit-transform-style:preserve-3d; }
  • 44. Sprite Animation in DOM • A child image element is needed to use only the CSS 3D Transforms. overflow:hidden DIV IMG
  • 45. Sprite Animation in DOM <div style="position:absolute; overflow:hidden; width:100px; height:100px; -webkit- transform:translate3d(100px, 100px, 0); "> <img src="sprite.png" style="position:absolute; -webkit- transform:translate3d(-100px, 0, 0); " border="0" alt="" /> </div>
  • 46. CSS 3D Transforms Animation Demo iOS4
  • 49. Performance different on each device • iOS4 supports CSS 3D Transforms with Hardware Acceleration(H/A) • iOS5 supports Canvas with H/A • There is no solution on Anroid 2.x devices. • Androind ICS supports CSS 3D Transforms with H/A
  • 50. Choose Rendering method under over Device/ iPhone iPhone iPhone Android Android OS 3GS 4 4S 3 3 CSS3D (under iOS4) Canvas Rendering CSS3D Canvas or CSS3D Method Canvas DOM (over iOS5)
  • 51. Be careful using Android CSS 3D Transforms • Unfortunately, Android ICS has many bugs associated with CSS 3D Transforms • The image turns black if an image that has a dimension of over 2048 pixels is used. • When an element that has a CSS overflow attribute with a hidden value is rotated, then that hidden area becomes visible.
  • 52. Need to optimize detailed • Tick occurs 60 times per second. • If 100 objects are made, a logic in drawing object occurs 6,000 times per second.
  • 53. There is a solution for you
  • 56. Collie • Collie is a high performance animation library for javascript • Collie supports more than 13 mobile devices and PCs with its optimized methods.
  • 57. Collie • Collie supports retina display
  • 58. Collie • Collie supports detail region to detect object in both Canvas and DOM • Collie provides tool to make path about object shape.
  • 59. Collie • Collie supports object cache for better speed • Collie is most effective for drawing that requires a lot of cost. Drawing
  • 60. Collie is an opensource project LGPL v2.1
  • 61. For more detailed information, visit http://jindo.dev.naver.com/collie