SlideShare ist ein Scribd-Unternehmen logo
1 von 62
HTML5 Animation
in Mobile Web Games

Sangmin, Shim
Speaker
What is Animation?
文, 絵 ゾングダゾング



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 …
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?
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
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

Weitere ähnliche Inhalte

Was ist angesagt?

3Dtexture_doc_rep
3Dtexture_doc_rep3Dtexture_doc_rep
3Dtexture_doc_repLiu Zhen-Yu
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 CanvasHenry Osborne
 
Chapter 02 sprite and texture
Chapter 02 sprite and textureChapter 02 sprite and texture
Chapter 02 sprite and textureboybuon205
 
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 PhonesMicrosoft 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 WebRobin Hawkes
 
Android Vector Drawable
 Android Vector Drawable Android Vector Drawable
Android Vector DrawablePhearum THANN
 
ENEI16 - WebGL with Three.js
ENEI16 - WebGL with Three.jsENEI16 - WebGL with Three.js
ENEI16 - WebGL with Three.jsJosé 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 184Mahmoud Samir Fayed
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkJussi 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 AnimationMohammad Shaker
 
XNA L02–Basic Matrices and Transformations
XNA L02–Basic Matrices and TransformationsXNA L02–Basic Matrices and Transformations
XNA L02–Basic Matrices and TransformationsMohammad Shaker
 

Was ist angesagt? (19)

3Dtexture_doc_rep
3Dtexture_doc_rep3Dtexture_doc_rep
3Dtexture_doc_rep
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 Canvas
 
HTML 5_Canvas
HTML 5_CanvasHTML 5_Canvas
HTML 5_Canvas
 
HTML 5 Canvas & SVG
HTML 5 Canvas & SVGHTML 5 Canvas & SVG
HTML 5 Canvas & SVG
 
Chapter 02 sprite and texture
Chapter 02 sprite and textureChapter 02 sprite and texture
Chapter 02 sprite and texture
 
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
 
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
 
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
 
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
 
Android Vector Drawable
 Android Vector Drawable Android Vector Drawable
Android Vector Drawable
 
MIDP: Game API
MIDP: Game APIMIDP: Game API
MIDP: Game API
 
ENEI16 - WebGL with Three.js
ENEI16 - WebGL with Three.jsENEI16 - WebGL with Three.js
ENEI16 - WebGL with Three.js
 
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
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation Framework
 
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
 
XNA L02–Basic Matrices and Transformations
XNA L02–Basic Matrices and TransformationsXNA L02–Basic Matrices and Transformations
XNA L02–Basic Matrices and Transformations
 
Canvas - HTML 5
Canvas - HTML 5Canvas - HTML 5
Canvas - HTML 5
 
Lec2
Lec2Lec2
Lec2
 
Css5 canvas
Css5 canvasCss5 canvas
Css5 canvas
 

Andere mochten auch

ロケタッチの裏側
ロケタッチの裏側ロケタッチの裏側
ロケタッチの裏側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-03Martin 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 Buffetjoshsager
 
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 SnyderHxRefactored
 
Crafting animation on the web
Crafting animation on the webCrafting animation on the web
Crafting animation on the webBenjy 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, 2016Ekta 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 2016Rami 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 SolutionsColin058
 

Andere mochten auch (14)

ロケタッチの裏側
ロケタッチの裏側ロケタッチの裏側
ロケタッチの裏側
 
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
 
Solr Payloads for Ranking Data
Solr Payloads for Ranking Data Solr Payloads for Ranking Data
Solr Payloads for Ranking Data
 
RocksDB meetup
RocksDB meetupRocksDB meetup
RocksDB meetup
 
Web Animation Buffet
Web Animation BuffetWeb Animation Buffet
Web Animation Buffet
 
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
 
Crafting animation on the web
Crafting animation on the webCrafting animation on the web
Crafting animation on the web
 
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
 
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
 
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...
 
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)
 
Animation meet web
Animation meet webAnimation meet web
Animation meet web
 
Animation
AnimationAnimation
Animation
 
Network Security Threats and Solutions
Network Security Threats and SolutionsNetwork Security Threats and Solutions
Network Security Threats and Solutions
 

Ähnlich wie HTML5 Animation in Mobile Web Games

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 HTML5Sangmin Shim
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricksdeanhudson
 
Mapping the world with Twitter
Mapping the world with TwitterMapping the world with Twitter
Mapping the world with Twittercarlo 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 TechniquesVitaly Friedman
 
Canvas in html5 - TungVD
Canvas in html5 - TungVDCanvas in html5 - TungVD
Canvas in html5 - TungVDFramgia Vietnam
 
Building a game engine with jQuery
Building a game engine with jQueryBuilding a game engine with jQuery
Building a game engine with jQueryPaul Bakaus
 
Image_Processing_LECTURE_c#_programming.ppt
Image_Processing_LECTURE_c#_programming.pptImage_Processing_LECTURE_c#_programming.ppt
Image_Processing_LECTURE_c#_programming.pptLOUISSEVERINOROMANO
 
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 GraphicsBlazing Cloud
 
Graphics on the Go
Graphics on the GoGraphics on the Go
Graphics on the GoGil 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 standardAndrea Verlicchi
 
FITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesFITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesRami 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 CodersKevin Gisi
 
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficientTh 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficientBin Shao
 
Pointer Events in Canvas
Pointer Events in CanvasPointer Events in Canvas
Pointer Events in Canvasdeanhudson
 

Ähnlich wie 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
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricks
 
Mapping the world with Twitter
Mapping the world with TwitterMapping the world with Twitter
Mapping the world with Twitter
 
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
 
Canvas in html5 - TungVD
Canvas in html5 - TungVDCanvas in html5 - TungVD
Canvas in html5 - TungVD
 
Iagc2
Iagc2Iagc2
Iagc2
 
Power of canvas
Power of canvasPower of canvas
Power of canvas
 
Building a game engine with jQuery
Building a game engine with jQueryBuilding a game engine with jQuery
Building a game engine with jQuery
 
Image_Processing_LECTURE_c#_programming.ppt
Image_Processing_LECTURE_c#_programming.pptImage_Processing_LECTURE_c#_programming.ppt
Image_Processing_LECTURE_c#_programming.ppt
 
Responsive Web Design tips and tricks.
Responsive Web Design tips and tricks.Responsive Web Design tips and tricks.
Responsive Web Design tips and tricks.
 
Rwd slidedeck
Rwd slidedeckRwd slidedeck
Rwd slidedeck
 
Whats new in Feathers 3.0?
Whats new in Feathers 3.0?Whats new in Feathers 3.0?
Whats new in Feathers 3.0?
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
 
Graphics on the Go
Graphics on the GoGraphics on the Go
Graphics on the Go
 
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
 
FITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesFITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive Images
 
Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)
 
Picture Perfect: Images for Coders
Picture Perfect: Images for CodersPicture Perfect: Images for Coders
Picture Perfect: Images for Coders
 
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficientTh 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
 
Pointer Events in Canvas
Pointer Events in CanvasPointer Events in Canvas
Pointer Events in Canvas
 

Kürzlich hochgeladen

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Kürzlich hochgeladen (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

HTML5 Animation in Mobile Web Games

  • 1. HTML5 Animation in Mobile Web Games Sangmin, Shim
  • 4.
  • 5. 文, 絵 ゾングダゾング twitter @yameyori e-mail usamibabe@naver.com 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 …
  • 8.
  • 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
  • 48.
  • 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
  • 55.
  • 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