SlideShare a Scribd company logo
1 of 32
5 tips for your
HTML5 games
 @ernesto_jimenez
 Lead Developer, Six to Start
5 things that
   might be helpful
developing your games
the game loop
GAME LOOP
function updateGame () {
  processPlayerInput();
  updateGameLogic();
  draw();
  setTimeout(updateGame, 25);
}
GAME LOOP


• Drawing   is the most expensive

• Game   is locked while running the update

• We   are consuming resources
you don’t always need
     a game loop
frame buffering
ABOUT FLICKERING
function draw() {
  var canvas = document.getElementById('visible-canvas');
  var context = canvas.getContext('2d');
  context.fillStyle = 'red';
  // Draw 200x200 square in x: 0 y: 0
  context.fillRect(0, 0, 200, 200);
  // Draw 200x200 square in x: 200 y: 200
  context.fillRect(0, 0, 200, 200);
}
ABOUT FLICKERING
function draw() {
  var canvas = document.getElementById('visible-canvas');
  var context = canvas.getContext('2d');
  context.fillStyle = 'red';
  // Draw 200x200 square in x: 0 y: 0
  context.fillRect(0, 0, 200, 200);
  // Draw 200x200 square in x: 200 y: 200
  context.fillRect(0, 0, 200, 200);
}
ABOUT FLICKERING
function draw() {
  var canvas = document.getElementById('visible-canvas');
  var context = canvas.getContext('2d');
  context.fillStyle = 'red';
  // Draw 200x200 square in x: 0 y: 0
  context.fillRect(0, 0, 200, 200);
  // Draw 200x200 square in x: 200 y: 200
  context.fillRect(0, 0, 200, 200);
}
USE TWO CANVAS




off-screen      visible
1) DRAW OFF-SCREEN




off-screen     visible
2) COPY THE RESULT




off-screen      visible
RIGHT FRAME BUFFER

function draw() {
  var buffer = document.createElement('canvas');
  var canvas = document.getElementById('visible-canvas');
  buffer.width = canvas.width;
  buffer.height = canvas.height;

    var buffer_context = buffer.getContext('2d');
    var context = canvas.getContext('2d');

    buffer_context.fillStyle = 'red';
    // Draw ...

    context.drawImage(buffer, 0, 0);
}
WRONG FRAME BUFFER
function draw() {
  var buffer = document.createElement('canvas');
  var canvas = document.getElementById('visible-canvas');
  buffer.width = canvas.width;
  buffer.height = canvas.height;

 var buffer_context = buffer.getContext('2d');
 var context = canvas.getContext('2d');

 buffer_context.fillStyle = 'red';
 // Draw ...

  var data = buffer_context.getImageData(0, 0, canvas.width,
canvas.height);
  context.putImageData(data, 0, 0);
}
avg. time for 1,000 frame-buffer operations in Firefox 4.0b7
              right frame buffer                 wrong frame buffer


 7,000ms
 6,300ms
 5,600ms
 4,900ms
 4,200ms
 3,500ms
 2,800ms
 2,100ms
 1,400ms
  700ms
    0ms
                                   plain color
frame buffer is not
always useful right now
    Browsers are repainting the canvas after your JS
expensive drawing
getImageData
     &
putImageData
avg. time for 1,000 fillRect in Firefox 4.0b7
                 fillRect 100x100px                   fillRect 500x500px


4,000ms

3,500ms

3,000ms

2,500ms

2,000ms

1,500ms

1,000ms

 500ms

   0ms
             plain color         3 stops linear gradient       blurred shadow
fillText is cool
but it is expensive
think outside of the
       canvas
1 GAME != 1 CANVAS
combine different
canvas to produce a
   single screen
images from Belén Albeza (@ladybenko)
images from Belén Albeza (@ladybenko)
dirty rectangles
redraw only those areas
   that have changed
images from Belén Albeza (@ladybenko)
images from Belén Albeza (@ladybenko)
HIGH
     PERFORMANCE
      JAVASCRIPT
         Nicholas C. Zakas




http://oreilly.com/catalog/9780596802806

More Related Content

What's hot

サウンドクリエイターがほんの少しBPに触れるだけで起こる革命
サウンドクリエイターがほんの少しBPに触れるだけで起こる革命サウンドクリエイターがほんの少しBPに触れるだけで起こる革命
サウンドクリエイターがほんの少しBPに触れるだけで起こる革命Satoru Okubo
 
誰でも見やすいパワーポイントを作るための パワーポイントバイブル
誰でも見やすいパワーポイントを作るための パワーポイントバイブル誰でも見やすいパワーポイントを作るための パワーポイントバイブル
誰でも見やすいパワーポイントを作るための パワーポイントバイブルJun Akizaki
 
UE4 Saitama 初心者向けハンズオン #7『サウンド機能』
UE4 Saitama 初心者向けハンズオン #7『サウンド機能』UE4 Saitama 初心者向けハンズオン #7『サウンド機能』
UE4 Saitama 初心者向けハンズオン #7『サウンド機能』Yuuki Ogino
 
「龍が如く7 光と闇の行方」の自動テスト活用事例とテスト自動化チーム(仮)による若手育成の取り組みについて
「龍が如く7 光と闇の行方」の自動テスト活用事例とテスト自動化チーム(仮)による若手育成の取り組みについて「龍が如く7 光と闇の行方」の自動テスト活用事例とテスト自動化チーム(仮)による若手育成の取り組みについて
「龍が如く7 光と闇の行方」の自動テスト活用事例とテスト自動化チーム(仮)による若手育成の取り組みについてSEGADevTech
 
PMの採用について
PMの採用についてPMの採用について
PMの採用についてTakuya Oikawa
 
3DCGMeetup08_MayaRigSystem_mGear
3DCGMeetup08_MayaRigSystem_mGear3DCGMeetup08_MayaRigSystem_mGear
3DCGMeetup08_MayaRigSystem_mGearue_ta
 
『FINAL FANTASY VII REMAKE』におけるプロファイリングと最適化事例 UNREAL FEST EXTREME 2021 SUMMER
『FINAL FANTASY VII REMAKE』におけるプロファイリングと最適化事例 UNREAL FEST EXTREME 2021 SUMMER『FINAL FANTASY VII REMAKE』におけるプロファイリングと最適化事例 UNREAL FEST EXTREME 2021 SUMMER
『FINAL FANTASY VII REMAKE』におけるプロファイリングと最適化事例 UNREAL FEST EXTREME 2021 SUMMERエピック・ゲームズ・ジャパン Epic Games Japan
 
SAMURAI JACK開発事例:海外むけアクションゲームをオーソドックスに作ってみた UNREAL FEST EXTREME 2021 SUMMER
SAMURAI JACK開発事例:海外むけアクションゲームをオーソドックスに作ってみた UNREAL FEST EXTREME 2021 SUMMERSAMURAI JACK開発事例:海外むけアクションゲームをオーソドックスに作ってみた UNREAL FEST EXTREME 2021 SUMMER
SAMURAI JACK開発事例:海外むけアクションゲームをオーソドックスに作ってみた UNREAL FEST EXTREME 2021 SUMMERエピック・ゲームズ・ジャパン Epic Games Japan
 
UE4勉強会 in 大阪 - もっとアニメーションBP
UE4勉強会 in 大阪 - もっとアニメーションBPUE4勉強会 in 大阪 - もっとアニメーションBP
UE4勉強会 in 大阪 - もっとアニメーションBPcom044
 
プロジェクトマネジメントは仕組み化が9割
プロジェクトマネジメントは仕組み化が9割プロジェクトマネジメントは仕組み化が9割
プロジェクトマネジメントは仕組み化が9割Mharu
 
マーケティングを捨てよ、サポートへ出よう 事例から見るスタートアップ初期におけるユーザー獲得
マーケティングを捨てよ、サポートへ出よう 事例から見るスタートアップ初期におけるユーザー獲得マーケティングを捨てよ、サポートへ出よう 事例から見るスタートアップ初期におけるユーザー獲得
マーケティングを捨てよ、サポートへ出よう 事例から見るスタートアップ初期におけるユーザー獲得Takaaki Umada
 
Unity開発で使える設計の話+Zenjectの紹介
Unity開発で使える設計の話+Zenjectの紹介Unity開発で使える設計の話+Zenjectの紹介
Unity開発で使える設計の話+Zenjectの紹介torisoup
 

What's hot (20)

サウンドクリエイターがほんの少しBPに触れるだけで起こる革命
サウンドクリエイターがほんの少しBPに触れるだけで起こる革命サウンドクリエイターがほんの少しBPに触れるだけで起こる革命
サウンドクリエイターがほんの少しBPに触れるだけで起こる革命
 
誰でも見やすいパワーポイントを作るための パワーポイントバイブル
誰でも見やすいパワーポイントを作るための パワーポイントバイブル誰でも見やすいパワーポイントを作るための パワーポイントバイブル
誰でも見やすいパワーポイントを作るための パワーポイントバイブル
 
UE4 Saitama 初心者向けハンズオン #7『サウンド機能』
UE4 Saitama 初心者向けハンズオン #7『サウンド機能』UE4 Saitama 初心者向けハンズオン #7『サウンド機能』
UE4 Saitama 初心者向けハンズオン #7『サウンド機能』
 
「龍が如く7 光と闇の行方」の自動テスト活用事例とテスト自動化チーム(仮)による若手育成の取り組みについて
「龍が如く7 光と闇の行方」の自動テスト活用事例とテスト自動化チーム(仮)による若手育成の取り組みについて「龍が如く7 光と闇の行方」の自動テスト活用事例とテスト自動化チーム(仮)による若手育成の取り組みについて
「龍が如く7 光と闇の行方」の自動テスト活用事例とテスト自動化チーム(仮)による若手育成の取り組みについて
 
UE4.14で広がるVRの可能性
UE4.14で広がるVRの可能性UE4.14で広がるVRの可能性
UE4.14で広がるVRの可能性
 
PMの採用について
PMの採用についてPMの採用について
PMの採用について
 
Hemorragia Digestiva Baixa
Hemorragia Digestiva BaixaHemorragia Digestiva Baixa
Hemorragia Digestiva Baixa
 
Gasometria arterial en la altura (2016)
Gasometria arterial en la altura (2016)Gasometria arterial en la altura (2016)
Gasometria arterial en la altura (2016)
 
猫でも分かる Control Rig UE4.25 版
猫でも分かる Control Rig UE4.25 版猫でも分かる Control Rig UE4.25 版
猫でも分かる Control Rig UE4.25 版
 
3DCGMeetup08_MayaRigSystem_mGear
3DCGMeetup08_MayaRigSystem_mGear3DCGMeetup08_MayaRigSystem_mGear
3DCGMeetup08_MayaRigSystem_mGear
 
『FINAL FANTASY VII REMAKE』におけるプロファイリングと最適化事例 UNREAL FEST EXTREME 2021 SUMMER
『FINAL FANTASY VII REMAKE』におけるプロファイリングと最適化事例 UNREAL FEST EXTREME 2021 SUMMER『FINAL FANTASY VII REMAKE』におけるプロファイリングと最適化事例 UNREAL FEST EXTREME 2021 SUMMER
『FINAL FANTASY VII REMAKE』におけるプロファイリングと最適化事例 UNREAL FEST EXTREME 2021 SUMMER
 
SAMURAI JACK開発事例:海外むけアクションゲームをオーソドックスに作ってみた UNREAL FEST EXTREME 2021 SUMMER
SAMURAI JACK開発事例:海外むけアクションゲームをオーソドックスに作ってみた UNREAL FEST EXTREME 2021 SUMMERSAMURAI JACK開発事例:海外むけアクションゲームをオーソドックスに作ってみた UNREAL FEST EXTREME 2021 SUMMER
SAMURAI JACK開発事例:海外むけアクションゲームをオーソドックスに作ってみた UNREAL FEST EXTREME 2021 SUMMER
 
Criptorquidia / Varicocele / Hidrocele
Criptorquidia / Varicocele / HidroceleCriptorquidia / Varicocele / Hidrocele
Criptorquidia / Varicocele / Hidrocele
 
Unreal Engine 4 Education 3 シーケンサーでリアルタイム映像作成
Unreal Engine 4 Education 3 シーケンサーでリアルタイム映像作成Unreal Engine 4 Education 3 シーケンサーでリアルタイム映像作成
Unreal Engine 4 Education 3 シーケンサーでリアルタイム映像作成
 
UE4勉強会 in 大阪 - もっとアニメーションBP
UE4勉強会 in 大阪 - もっとアニメーションBPUE4勉強会 in 大阪 - もっとアニメーションBP
UE4勉強会 in 大阪 - もっとアニメーションBP
 
プロジェクトマネジメントは仕組み化が9割
プロジェクトマネジメントは仕組み化が9割プロジェクトマネジメントは仕組み化が9割
プロジェクトマネジメントは仕組み化が9割
 
マーケティングを捨てよ、サポートへ出よう 事例から見るスタートアップ初期におけるユーザー獲得
マーケティングを捨てよ、サポートへ出よう 事例から見るスタートアップ初期におけるユーザー獲得マーケティングを捨てよ、サポートへ出よう 事例から見るスタートアップ初期におけるユーザー獲得
マーケティングを捨てよ、サポートへ出よう 事例から見るスタートアップ初期におけるユーザー獲得
 
Trastornos del potasio
Trastornos del potasioTrastornos del potasio
Trastornos del potasio
 
UE4とBlenderでランニングコストを抑えるモダンなワークフロー
UE4とBlenderでランニングコストを抑えるモダンなワークフローUE4とBlenderでランニングコストを抑えるモダンなワークフロー
UE4とBlenderでランニングコストを抑えるモダンなワークフロー
 
Unity開発で使える設計の話+Zenjectの紹介
Unity開発で使える設計の話+Zenjectの紹介Unity開発で使える設計の話+Zenjectの紹介
Unity開発で使える設計の話+Zenjectの紹介
 

Similar to 5 tips for your HTML5 games

Advanced html5 diving into the canvas tag
Advanced html5 diving into the canvas tagAdvanced html5 diving into the canvas tag
Advanced html5 diving into the canvas tagDavid Voyles
 
I Can't Believe It's Not Flash
I Can't Believe It's Not FlashI Can't Believe It's Not Flash
I Can't Believe It's Not FlashThomas Fuchs
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billynimbleltd
 
Getting Visual with Ruby Processing
Getting Visual with Ruby ProcessingGetting Visual with Ruby Processing
Getting Visual with Ruby ProcessingRichard LeBer
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video gamedandylion13
 
HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!Phil Reither
 
Building a Visualization Language
Building a Visualization LanguageBuilding a Visualization Language
Building a Visualization Languagejeresig
 
Introduction to Generative Art with Processing
Introduction to Generative Art with ProcessingIntroduction to Generative Art with Processing
Introduction to Generative Art with Processingstefk00
 
XNA L07–Skybox and Terrain
XNA L07–Skybox and TerrainXNA L07–Skybox and Terrain
XNA L07–Skybox and TerrainMohammad Shaker
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Patrick Chanezon
 
Canvas
CanvasCanvas
CanvasRajon
 
A practical intro to BabylonJS
A practical intro to BabylonJSA practical intro to BabylonJS
A practical intro to BabylonJSHansRontheWeb
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricksdeanhudson
 
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
 
Interactive Mouse (Report On Processing)
Interactive Mouse (Report On Processing)Interactive Mouse (Report On Processing)
Interactive Mouse (Report On Processing)TongXu520
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreRemy Sharp
 

Similar to 5 tips for your HTML5 games (20)

Wallpaper Notifier
Wallpaper NotifierWallpaper Notifier
Wallpaper Notifier
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
Advanced html5 diving into the canvas tag
Advanced html5 diving into the canvas tagAdvanced html5 diving into the canvas tag
Advanced html5 diving into the canvas tag
 
I Can't Believe It's Not Flash
I Can't Believe It's Not FlashI Can't Believe It's Not Flash
I Can't Believe It's Not Flash
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billy
 
Getting Visual with Ruby Processing
Getting Visual with Ruby ProcessingGetting Visual with Ruby Processing
Getting Visual with Ruby Processing
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video game
 
HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
 
Building a Visualization Language
Building a Visualization LanguageBuilding a Visualization Language
Building a Visualization Language
 
Peint talk
Peint talkPeint talk
Peint talk
 
Introduction to Generative Art with Processing
Introduction to Generative Art with ProcessingIntroduction to Generative Art with Processing
Introduction to Generative Art with Processing
 
XNA L07–Skybox and Terrain
XNA L07–Skybox and TerrainXNA L07–Skybox and Terrain
XNA L07–Skybox and Terrain
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
 
Canvas
CanvasCanvas
Canvas
 
A practical intro to BabylonJS
A practical intro to BabylonJSA practical intro to BabylonJS
A practical intro to BabylonJS
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricks
 
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
 
Interactive Mouse (Report On Processing)
Interactive Mouse (Report On Processing)Interactive Mouse (Report On Processing)
Interactive Mouse (Report On Processing)
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
 

Recently uploaded

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Recently uploaded (20)

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

5 tips for your HTML5 games

  • 1. 5 tips for your HTML5 games @ernesto_jimenez Lead Developer, Six to Start
  • 2. 5 things that might be helpful developing your games
  • 4. GAME LOOP function updateGame () { processPlayerInput(); updateGameLogic(); draw(); setTimeout(updateGame, 25); }
  • 5. GAME LOOP • Drawing is the most expensive • Game is locked while running the update • We are consuming resources
  • 6. you don’t always need a game loop
  • 8. ABOUT FLICKERING function draw() { var canvas = document.getElementById('visible-canvas'); var context = canvas.getContext('2d'); context.fillStyle = 'red'; // Draw 200x200 square in x: 0 y: 0 context.fillRect(0, 0, 200, 200); // Draw 200x200 square in x: 200 y: 200 context.fillRect(0, 0, 200, 200); }
  • 9. ABOUT FLICKERING function draw() { var canvas = document.getElementById('visible-canvas'); var context = canvas.getContext('2d'); context.fillStyle = 'red'; // Draw 200x200 square in x: 0 y: 0 context.fillRect(0, 0, 200, 200); // Draw 200x200 square in x: 200 y: 200 context.fillRect(0, 0, 200, 200); }
  • 10. ABOUT FLICKERING function draw() { var canvas = document.getElementById('visible-canvas'); var context = canvas.getContext('2d'); context.fillStyle = 'red'; // Draw 200x200 square in x: 0 y: 0 context.fillRect(0, 0, 200, 200); // Draw 200x200 square in x: 200 y: 200 context.fillRect(0, 0, 200, 200); }
  • 13. 2) COPY THE RESULT off-screen visible
  • 14. RIGHT FRAME BUFFER function draw() { var buffer = document.createElement('canvas'); var canvas = document.getElementById('visible-canvas'); buffer.width = canvas.width; buffer.height = canvas.height; var buffer_context = buffer.getContext('2d'); var context = canvas.getContext('2d'); buffer_context.fillStyle = 'red'; // Draw ... context.drawImage(buffer, 0, 0); }
  • 15. WRONG FRAME BUFFER function draw() { var buffer = document.createElement('canvas'); var canvas = document.getElementById('visible-canvas'); buffer.width = canvas.width; buffer.height = canvas.height; var buffer_context = buffer.getContext('2d'); var context = canvas.getContext('2d'); buffer_context.fillStyle = 'red'; // Draw ... var data = buffer_context.getImageData(0, 0, canvas.width, canvas.height); context.putImageData(data, 0, 0); }
  • 16. avg. time for 1,000 frame-buffer operations in Firefox 4.0b7 right frame buffer wrong frame buffer 7,000ms 6,300ms 5,600ms 4,900ms 4,200ms 3,500ms 2,800ms 2,100ms 1,400ms 700ms 0ms plain color
  • 17. frame buffer is not always useful right now Browsers are repainting the canvas after your JS
  • 19. getImageData & putImageData
  • 20. avg. time for 1,000 fillRect in Firefox 4.0b7 fillRect 100x100px fillRect 500x500px 4,000ms 3,500ms 3,000ms 2,500ms 2,000ms 1,500ms 1,000ms 500ms 0ms plain color 3 stops linear gradient blurred shadow
  • 21. fillText is cool but it is expensive
  • 22. think outside of the canvas
  • 23. 1 GAME != 1 CANVAS
  • 24. combine different canvas to produce a single screen
  • 25. images from Belén Albeza (@ladybenko)
  • 26. images from Belén Albeza (@ladybenko)
  • 28. redraw only those areas that have changed
  • 29. images from Belén Albeza (@ladybenko)
  • 30. images from Belén Albeza (@ladybenko)
  • 31.
  • 32. HIGH PERFORMANCE JAVASCRIPT Nicholas C. Zakas http://oreilly.com/catalog/9780596802806

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n