<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>David Rousset</title><link>http://blogs.msdn.com/b/davrous/</link><description>aka Luke CloudWalker</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>Windows 8 HTML5 Metro Style App: How to create a small RSS reader in 30min (part 2/2)</title><link>http://blogs.msdn.com/b/davrous/archive/2012/05/14/windows-8-html5-metro-style-app-how-to-create-a-small-rss-reader-in-30min-part-2-2.aspx</link><pubDate>Mon, 14 May 2012 13:42:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10304853</guid><dc:creator>David Rousset</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10304853</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/05/14/windows-8-html5-metro-style-app-how-to-create-a-small-rss-reader-in-30min-part-2-2.aspx#comments</comments><description>&lt;!-- Include the VideoJS Library --&gt;&lt;script src="http://i1.blogs.msdn.com/rrcontent/7ea68542355902505304335fe8c7c129-f82aa988dbd4168e170cfdbb1d5e898f-RequestReducedScript.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;  &lt;div itemscope="itemscope" itemtype="http://schema.org/SoftwareApplication"&gt;&lt;span itemprop="description"&gt;We’re now going to see how to display the details of each article. We will use for that a &lt;strong&gt;transition animation&lt;/strong&gt;, we will play with the &lt;strong&gt;simulator&lt;/strong&gt; and we will continue to discover Blend to use &lt;strong&gt;CSS3 Multi-columns&lt;/strong&gt; for instance.&lt;/span&gt;&amp;#160;&lt;/div&gt;  &lt;div itemscope="itemscope" itemtype="http://schema.org/SoftwareApplication"&gt;&lt;img style="margin: 10px 0px" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7848.image_5F00_thumb_5F00_0252CBAD.png" itemprop="image" /&gt; &lt;/div&gt;  &lt;p&gt;Like in the previous article, you’ll find a video as well as the source code to download at the end of the article.&lt;/p&gt;  &lt;p&gt;This article is the second part of this one: &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/05/11/windows-8-html5-metro-style-app-how-to-create-a-small-rss-reader-in-30min-part-1-2.aspx"&gt;Windows 8 HTML5 Metro Style App: How to create a small RSS reader in 30min (part 1/2)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;During this article, we’ll see:&lt;/p&gt;  &lt;p&gt;- Step 1: using the simulator    &lt;br /&gt;- &lt;a href="#etape2"&gt;Step 2:&amp;#160; displaying the articles’ details&lt;/a&gt;     &lt;br /&gt;- &lt;a href="#etape3"&gt;Step 3: finishing the design of the detail view with Blend&lt;/a&gt;     &lt;br /&gt;- &lt;a href="#etape4"&gt;Step 4: video and source code to download&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;Step 1: using the simulator &lt;/h2&gt;  &lt;p&gt;It’s important to know how your application behaves with touch devices and with the various resolutions of future Windows 8 tablets &amp;amp; PC.&lt;/p&gt;  &lt;p&gt;We’re providing a cool tool that could help you doing your first tests: the simulator.&lt;/p&gt;  &lt;p&gt;For instance, if you’re opening the project as it was at the end of the previous article, we can simulate some touch interactions by launching the simulator via this button:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8741.clip_5F00_image001_5F00_2130A188.png"&gt;&lt;img title="clip_image001" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image001" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3652.clip_5F00_image001_5F00_thumb_5F00_69EA1A4C.png" width="202" height="123" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The simulator will then be launched. It is more or less simulating a RDP session on yourself. Here is the output you should have:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3073.clip_5F00_image003_5F00_19A7C2CC.jpg"&gt;&lt;img title="clip_image003" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image003" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1488.clip_5F00_image003_5F00_thumb_5F00_4BA1F407.jpg" width="640" height="394" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;You can now click on this icon:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1004.clip_5F00_image004_5F00_28748955.png"&gt;&lt;img title="clip_image004" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image004" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2477.clip_5F00_image004_5F00_thumb_5F00_3CF9D8D3.png" width="29" height="29" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;It will simulate touch. Try to slide the virtual finger on the virtual display. You’ll then see that some inertia and bouncing effects are already implemented for you. In the same manner, if you touch an element and slide it down, you will select it. It’s the same action as doing a right-click on it with your mouse. You see here the benefits of using native WinJS controls that implement all this kind of logic for you.&lt;/p&gt;  &lt;p&gt;Another useful button is the one handling the various resolutions:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0250.clip_5F00_image005_5F00_7F6C7B09.png"&gt;&lt;img title="clip_image005" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image005" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5127.clip_5F00_image005_5F00_thumb_5F00_55F839C9.png" width="201" height="189" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Try for instance to simulate a 23’’ monitor having a 1920x1080 resolution. You should now see this kind of layout:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2806.clip_5F00_image007_5F00_17927616.jpg"&gt;&lt;img title="clip_image007" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image007" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5621.clip_5F00_image007_5F00_thumb_5F00_69A7B40E.jpg" width="640" height="395" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;You may have noticed that we’re switching from 2 lines of elements to 3 lines in 1080p and from 5 visible columns to 7. The ListView control handles also the various form factors for you.&lt;/p&gt;  &lt;p&gt;So even if WinJS is not mandatory inside HTML5 Metro projects, don’t underestimate all the benefits it may bring you for free!&lt;/p&gt;  &lt;h2 id="etape2"&gt;Step 2: displaying the articles’ details &lt;/h2&gt;  &lt;p&gt;In order to display the articles’ content, we need another piece of HTML. Navigate to the “&lt;i&gt;default.html&lt;/i&gt;” page and insert this one:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;articlecontent&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;We will insert the article’s content by code. Open “&lt;i&gt;default.js&lt;/i&gt;”. Just above the Binding.List instantiation, insert this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;articlelistElement = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;articlelist&amp;quot;&lt;/span&gt;);
articlelistElement.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;iteminvoked&amp;quot;&lt;/span&gt;, itemInvoked);
backbutton.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;click&amp;quot;&lt;/span&gt;, backButtonClick);&lt;/pre&gt;

&lt;p&gt;We’re targeting our “&lt;i&gt;articlelist&lt;/i&gt;” element from the DOM that now must be a WinJS &lt;i&gt;ListView&lt;/i&gt; control thanks to the execution of the processAll function. This one is then now exposing an event named “&lt;i&gt;iteminvoked&lt;/i&gt;”. It’s raised when you will click/touch one of the elements of the list. Moreover, we’re subscribing to the “click” event of the “back” button to be able to simply go back to the welcome screen.&lt;/p&gt;

&lt;p&gt;We now need to create the associated event handlers. Here they are:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;backButtonClick(e) {
    articlecontent.style.display = &lt;span style="color: maroon"&gt;&amp;quot;none&amp;quot;&lt;/span&gt;;
    articlelist.style.display = &lt;span style="color: maroon"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;itemInvoked(e) {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;currentArticle = articlesList.getAt(e.detail.itemIndex);
    setInnerHTMLUnsafe(articlecontent, currentArticle.content);
    articlelist.style.display = &lt;span style="color: maroon"&gt;&amp;quot;none&amp;quot;&lt;/span&gt;;
    articlecontent.style.display = &lt;span style="color: maroon"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;The concept is really simple here. When the user will click on one of the elements, we will retrieve in the collection the appropriate object with its index (&lt;i&gt;e.detail.itemIndex&lt;/i&gt;). We’re injecting the HTML content into the innerHTML property of the div node just inserted in the main page via the &lt;b&gt;&lt;i&gt;setInnerHTMLUnsage()&lt;/i&gt;&lt;/b&gt; function. But why do we need to use this special function for that? &lt;/p&gt;

&lt;h3&gt;Some quick notes about the Metro Style Apps security context&lt;/h3&gt;

&lt;p&gt;The security context of an HTML5 Metro application is different from a classical web page. In our case, trying to access directly to the innerHTML property is protected/scanned. &lt;/p&gt;

&lt;p&gt;For instance, if you try to insert some HTML downloaded from the « public web » space, a security exception will be raised by default to protect you. I’m sure you don’t want to have some script injection taking control of your application. So by default, we’re preventing that.&lt;/p&gt;

&lt;p&gt;But if you really know what you’re doing, you have the choice to “by-pass” this automatic check by calling the &lt;b&gt;&lt;i&gt;setInnerHTMLUnsafe()&lt;/i&gt;&lt;/b&gt; function.&lt;/p&gt;

&lt;p&gt;Linked to the security context also, inserting an &amp;lt;iframe&amp;gt; in your application is slightly different for instance. If you’re interested in the details, here are some articles to read:&lt;/p&gt;

&lt;p&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx"&gt;HTML, CSS, and JavaScript features and differences&lt;/a&gt; 

  &lt;br /&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465373.aspx"&gt;Features and restrictions by context&lt;/a&gt; 

  &lt;br /&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465388.aspx"&gt;Making HTML safer: details for toStaticHTML&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, let’s go back to our main topic.&lt;/p&gt;

&lt;p&gt;The way we’re displaying the content of the article is really simple. We’re hiding the list of our elements by switching its “&lt;i&gt;display&lt;/i&gt;” to “&lt;i&gt;none&lt;/i&gt;” and we’re displaying the “&lt;i&gt;articlecontent&lt;/i&gt;” div. When pressing the “&lt;i&gt;back&lt;/i&gt;” button, we’re doing the exact opposite.&lt;/p&gt;

&lt;p&gt;Ok, press F5 and you should have something like that after clicking on one of the items: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4503.clip_5F00_image009_5F00_49D2FF06.jpg"&gt;&lt;img title="clip_image009" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image009" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2425.clip_5F00_image009_5F00_thumb_5F00_229B4682.jpg" width="640" height="360" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You’ll notice that the layout is far from being cool but we’re going to work on that in a few moments with Blend. &lt;/p&gt;

&lt;p&gt;In the meantime, I’d like to focus on something really annoying in the current version. The navigation inside an article and back to the welcome screen works fine. But the user experience is not optimal. The detail of the article arrives without any transition. &lt;/p&gt;

&lt;p&gt;We’re then coming to an important point of the Metro Style Apps: the “&lt;i&gt;Fast &amp;amp; Fluid&lt;/i&gt;” experience. You need to suggest performance to your user and tell them that your application is really alive. To do that, simply adding some slight transitions animations can totally change the perception. Technically, you can implement them in 2 manners. &lt;/p&gt;

&lt;p&gt;You can implement them using pure CSS3 Transitions/Animations to display the content you’re interested in. It is then up to you to find the appropriate animations. If you’d like to discover how these new CSS3 features work, we’ve made some introduction articles David Catuhe and I here: &lt;/p&gt;

&lt;p&gt;- &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2011/12/06/css3-transitions.aspx"&gt;Introduction to CSS3 Transitions&lt;/a&gt; 

  &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-to-css3-animations.aspx"&gt;Introduction to CSS3 Animations&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or you can use the WinJS library which exposes prebuilt animations to help following the Metro guidelines. Under the hood, you’ll find the usage of CSS Transform &amp;amp; transitions. But for us developers, we just have a simple line of JavaScript to call. &lt;/p&gt;

&lt;p&gt;For instance, in the &lt;i&gt;itemInvoked()&lt;/i&gt; handler, insert this line of code at the end of the function: &lt;/p&gt;

&lt;pre class="code"&gt;WinJS.UI.Animation.enterPage(articlecontent);&lt;/pre&gt;

&lt;p&gt;And please insert this one at the end of the second event handler:&lt;/p&gt;

&lt;pre class="code"&gt;WinJS.UI.Animation.enterPage(articlelist);&lt;/pre&gt;

&lt;p&gt;Pressing F5, you should now have some subtle transitions while you’re navigating inside the application. Trust us, they will really make the difference in the user experience!&lt;/p&gt;

&lt;h2 id="etape3"&gt;Step 3: finishing the design of the detail view with Blend&lt;/h2&gt;

&lt;p&gt;Switch back to Blend. It will ask you again to reload all the changes you’ve done inside Visual Studio.&lt;/p&gt;

&lt;p&gt;Question of the day: &lt;b&gt;how will you be able to design the detail view as we need to simulate a navigation action via an item selection?&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Well, you already had the answer in the previous article. Blend 5 is live running your HTML5 Metro application. But you’re maybe lacking an additional detail. You can switch into an “interactive” mode by clicking on this button:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1263.clip_5F00_image010_5F00_31D1AF4F.png"&gt;&lt;img title="clip_image010" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image010" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2437.clip_5F00_image010_5F00_thumb_5F00_0620E553.png" width="96" height="25" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;It should be named “&lt;b&gt;&lt;i&gt;Turn on Interactive Mode&lt;/i&gt;&lt;/b&gt;”. Once done, you should be able to interact with your application, navigate to the article content you’d like to review and switch back to the design surface by clicking on the same button. It my case, I’ve decided to use this article as a base:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3173.clip_5F00_image012_5F00_6CB8E218.jpg"&gt;&lt;img title="clip_image012" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image012" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3808.clip_5F00_image012_5F00_thumb_5F00_1EB31354.jpg" width="640" height="341" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;In the style section, under the appropriate &lt;i&gt;Media Query&lt;/i&gt;, add a new rule targeting “&lt;b&gt;&lt;i&gt;#articlecontent&lt;/i&gt;&lt;/b&gt;” and select it immediately.&lt;/p&gt;

&lt;p&gt;In the “&lt;b&gt;Sizing&lt;/b&gt;“ section, fix the &lt;b&gt;width&lt;/b&gt; &amp;amp; &lt;b&gt;height&lt;/b&gt; to &lt;b&gt;100%&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;In the “&lt;b&gt;Layout&lt;/b&gt;” part, put a left &lt;b&gt;padding&lt;/b&gt; of &lt;b&gt;120px&lt;/b&gt; to align the content with the title.&lt;/p&gt;

&lt;p&gt;This raises a new problem. The layout our “&lt;i&gt;articlecontent&lt;/i&gt;” div doesn’t fit anymore in the width of our screen. &lt;/p&gt;

&lt;p&gt;To fix that, modify the “&lt;b&gt;&lt;i&gt;width&lt;/i&gt;&lt;/b&gt;” property and click to select a “&lt;b&gt;&lt;i&gt;custom expression&lt;/i&gt;&lt;/b&gt;”:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3007.clip_5F00_image013_5F00_2FDFAD28.png"&gt;&lt;img title="clip_image013" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image013" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4578.clip_5F00_image013_5F00_thumb_5F00_587E192F.png" width="244" height="174" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We’re going to use the &lt;a href="http://www.w3.org/TR/css3-values/#calc0"&gt;CSS Calc() operator&lt;/a&gt;. Enter the following expression “&lt;b&gt;calc(100%-120px)&lt;/b&gt;”.&lt;/p&gt;

&lt;p&gt;We’re better following the Metro guidelines this way. We’ve got an ultimate task to do it in an even better way: allowing the user to slide horizontally the content and make it more readable. &lt;/p&gt;

&lt;p&gt;Let’s start by readability. There is a very useful CSS3 feature for that easy to put in place: &lt;b&gt;CSS3 Multicolumns&lt;/b&gt;. &lt;/p&gt;

&lt;p&gt;Jump into the “&lt;b&gt;&lt;i&gt;Multicolumn&lt;/i&gt;&lt;/b&gt;” section of the “&lt;b&gt;&lt;i&gt;CSS Properties&lt;/i&gt;&lt;/b&gt;” panel. Modify the layout to create &lt;b&gt;480px columns width&lt;/b&gt; with &lt;b&gt;gaps of 80px&lt;/b&gt; between them.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4062.clip_5F00_image015_5F00_1796678D.jpg"&gt;&lt;img title="clip_image015" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image015" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5618.clip_5F00_image015_5F00_thumb_5F00_1FAD93E2.jpg" width="640" height="270" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;It starts to look fine, isn’t it? &lt;/p&gt;

&lt;p&gt;To conclude, we need to implement horizontal sliding. Go into the “&lt;b&gt;&lt;i&gt;Search Properties&lt;/i&gt;&lt;/b&gt;” textbox and type “&lt;b&gt;&lt;i&gt;over&lt;/i&gt;&lt;/b&gt;”. Blend will then filter all the properties containing the “over” keyword.&lt;/p&gt;

&lt;p&gt;Set the “&lt;b&gt;overflow-x&lt;/b&gt;” property to “&lt;b&gt;auto&lt;/b&gt;” and “&lt;b&gt;overflow-y&lt;/b&gt;” to “&lt;b&gt;hidden&lt;/b&gt;”.&lt;/p&gt;

&lt;p&gt;You can switch back to Visual Studio, accept the changes and press F5 to play with the final result.&lt;/p&gt;

&lt;h3&gt;Special additional bonus level for warriors&lt;/h3&gt;

&lt;p&gt;Well, as I feel you still want to play with Blend, let’s add another feature. What is the most important thing for us while we’re reading a technical article? The source code of course!&lt;/p&gt;

&lt;p&gt;Once you know that, don’t hesitate to put some emphasis on the code in a way or in another to catch the eye of the developers.&lt;/p&gt;

&lt;p&gt;In the Channel9 case, they had the excellent idea to insert the code parts into &amp;lt;pre&amp;gt; tags. It will simplify our life to style this part.&lt;/p&gt;

&lt;p&gt;Add a new CSS rule “&lt;b&gt;#articlecontent pre&lt;/b&gt;”.&lt;/p&gt;

&lt;p&gt;Switch into the interactive mode and navigate into an article where some source code is visible enough. &lt;/p&gt;

&lt;p&gt;Select the last rule you’ve just added and go into the “&lt;b&gt;&lt;i&gt;Background&lt;/i&gt;&lt;/b&gt;” section of the CSSS properties. Click to set a color:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7762.clip_5F00_image016_5F00_23BA7265.png"&gt;&lt;img title="clip_image016" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image016" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6278.clip_5F00_image016_5F00_thumb_5F00_383FC1E3.png" width="240" height="48" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You will then be able to use this wonderful color editor to make your choice:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7762.clip_5F00_image017_5F00_7CEEECD5.png"&gt;&lt;img title="clip_image017" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image017" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4532.clip_5F00_image017_5F00_thumb_5F00_00FBCB59.png" width="240" height="218" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;But if you’re a poor developer like myself, you will probably have a natural tendency to choose the worst color ever. So, click on the color picked icon and choose the nearest Blend grey. It’s obviously a good grey.&lt;/p&gt;

&lt;p&gt;To definitely conclude, on the &amp;lt;pre&amp;gt;, set the “&lt;b&gt;overflow-x”&lt;/b&gt; property to auto and the “&lt;b&gt;overflow-y”&lt;/b&gt; to “&lt;b&gt;hidden”&lt;/b&gt;. &lt;/p&gt;

&lt;p&gt;Pressing F5 will bring you this kind of experience:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8836.clip_5F00_image019_5F00_0912F7AE.jpg"&gt;&lt;img title="clip_image019" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image019" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0871.clip_5F00_image019_5F00_thumb_5F00_41C0326C.jpg" width="640" height="360" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h2 id="etape4"&gt;Step 4: video and source code to download&lt;/h2&gt;

&lt;p&gt;Well, I hope you’re now convinced I wasn’t lying. If you were focused enough, you should have spent 30 minutes to build this little application.&lt;/p&gt;

&lt;p&gt;Here is the video to watch following these steps:&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="SimpleChannel9ReaderPart2" class="video-js" poster="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2.jpg" preload="preload" controls="controls" width="640" height="360"&gt;&lt;source type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2.mp4" /&gt;&lt;source type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2.webm" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="640" type="application/x-shockwave-flash" height="360"&gt;  
 &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  
 &lt;param name="allowfullscreen" value="true" /&gt;  
 &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  
 &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   
 &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2.jpg" width="512" height="288" /&gt;   
 &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt;&lt;a href="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;And here is the source code to download: &lt;a title="http://david.blob.core.windows.net/win8/SimpleChannel9ReaderArticle2.zip" href="http://david.blob.core.windows.net/win8/SimpleChannel9ReaderArticle2.zip"&gt;Simple Channel9 Reader Article2&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading! If you’d like to go further, here are some good articles to read:&lt;/p&gt;

&lt;p&gt;- An excellent series done by David Catuhe: &lt;a title="http://blogs.msdn.com/b/eternalcoding/archive/2012/04/16/how-to-cook-a-complete-windows-8-application-with-html5-css3-and-javascript-in-a-week-day-0.aspx" href="http://blogs.msdn.com/b/eternalcoding/archive/2012/04/16/how-to-cook-a-complete-windows-8-application-with-html5-css3-and-javascript-in-a-week-day-0.aspx"&gt;How to cook a complete Windows 8 application with HTML5, CSS3 and JavaScript in a week&lt;/a&gt;. You will discover how to support the snapped view, the search contract, the navigation framework and a lot of other cool Windows 8 features. 

  &lt;br /&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br211385.aspx"&gt;Create your first Metro style app using JavaScript&lt;/a&gt; covering the same topic and complementary to these 2 articles.&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10304853" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/CSS3/">CSS3</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Blend+5/">Blend 5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/WinJS/">WinJS</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Windows+8/">Windows 8</category></item><item><title>Windows 8 HTML5 Metro Style App: How to create a small RSS reader in 30min (part 1/2)</title><link>http://blogs.msdn.com/b/davrous/archive/2012/05/11/windows-8-html5-metro-style-app-how-to-create-a-small-rss-reader-in-30min-part-1-2.aspx</link><pubDate>Fri, 11 May 2012 17:55:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10304325</guid><dc:creator>David Rousset</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10304325</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/05/11/windows-8-html5-metro-style-app-how-to-create-a-small-rss-reader-in-30min-part-1-2.aspx#comments</comments><description>&lt;!-- Include the VideoJS Library --&gt;&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;  &lt;p&gt;Starting from scratch, we’re going to learn through these 2 tutorials how to build a small RSS reader with &lt;b&gt;HTML5&lt;/b&gt;, &lt;b&gt;CSS3&lt;/b&gt; and &lt;b&gt;WinJS&lt;/b&gt;, the Microsoft JavaScript framework for Windows 8 Metro Style Apps. We’ll try also to follow the Metro design guidelines by using &lt;strong&gt;Expression Blend 5&lt;/strong&gt;. If everything goes fine, you should be able to follow these 2 articles in 30 minutes. &lt;/p&gt;  &lt;p&gt;This first article will help you to create the welcome screen that will use a WinJS ListView control. This control will display all the blog posts recently published via nice thumbnails. The 2nd one will work on the detail view displayed when you’ll click on one of the items. At last, you’ll find a video at the end of this article playing in real-time the following steps as well as the final solution to download. See them as useful complementary resources if you need to clarify some parts of this article. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Pre-requisites:&lt;/u&gt;&lt;/strong&gt; to follow these tutorials, you need first to: &lt;/p&gt;  &lt;p&gt;1 – Download &amp;amp; install &lt;strong&gt;Windows 8 Consumer Preview&lt;/strong&gt; on your machine: &lt;a href="http://preview.windows.com/"&gt;http://preview.windows.com&lt;/a&gt;     &lt;br /&gt;2 – Download &amp;amp; install &lt;strong&gt;Visual Studio 11 Express &lt;/strong&gt;for Windows 8: &lt;a title="http://msdn.microsoft.com/en-us/windows/apps/br229516" href="http://msdn.microsoft.com/en-us/windows/apps/br229516"&gt;http://msdn.microsoft.com/en-us/windows/apps/br229516&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; If you’ve got a Mac, it works perfectly fine thanks to BootCamp or inside a virtual machine handled by Parallels for instance&lt;/p&gt;  &lt;p&gt;Here is a brief summary of what we’re going to see in this article:&lt;/p&gt;  &lt;p&gt;- Step 1: creating a blank application    &lt;br /&gt;- &lt;a href="#etape2"&gt;Step 2: creating the HTML &amp;amp; CSS base of our main page&lt;/a&gt;     &lt;br /&gt;- &lt;a href="#etape3"&gt;Step 3: first contact with Blend&lt;/a&gt;     &lt;br /&gt;- &lt;a href="#etape4"&gt;Step 4: loading the data with XHR and bind them to the ListView control&lt;/a&gt;     &lt;br /&gt;- &lt;a href="#etape5"&gt;Step 5: using a template and modifying the design with Blend&lt;/a&gt;     &lt;br /&gt;- &lt;a href="#etape6"&gt;Step 6: video demonstrating all the steps &amp;amp; source code to download&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; these tutorials are based on the &lt;a href="http://channel9.msdn.com/events/BUILD/BUILD2011/BPS-1006"&gt;Tools for building Metro style apps&lt;/a&gt; session of the BUILD delivered by Chris Sell &amp;amp; Kieran Mockford. I’ve simply updated it for Windows 8 CP. &lt;/p&gt;  &lt;h2&gt;Step 1: creating a blank application &lt;/h2&gt;  &lt;p&gt;First thing you need to do is to launch Visual Studio 11 and create a new JavaScript Windows Metro Style project via “File –&amp;gt;&amp;#160; New Project”:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1323.clip_5F00_image002_5F00_37E6D929.jpg"&gt;&lt;img title="clip_image002" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image002" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0763.clip_5F00_image002_5F00_thumb_5F00_2222122E.jpg" width="640" height="344" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Name it “&lt;b&gt;SimpleChannel9Reader&lt;/b&gt; ” as we’re going to download the RSS stream of the Coding4Fun section of Channel9 available here: &lt;a href="http://channel9.msdn.com/coding4fun/articles/RSS"&gt;http://channel9.msdn.com/coding4fun/articles/RSS&lt;/a&gt; &lt;/p&gt;  &lt;h2 id="etape2"&gt;Step 2: creating the HTML &amp;amp; CSS base of our main page&lt;/h2&gt;  &lt;p&gt;Open the “default.html” file which describes the first page that will be displayed when you’ll launch the application. Instead of the following HTML part:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;p&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Content goes here&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;p&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Insert this one:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;main&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;header &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;banner&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;button &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;backbutton&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;win-backbutton&amp;quot;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;button&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;h1 &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;maintitle&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;win-title&amp;quot;&amp;gt;
            &lt;/span&gt;Welcome to Channel 9!&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;h1&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;section &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;content&amp;quot;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;section&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;We now have a global div container with the “main” id embedding 2 sub-containers named “banner” and “content”. The header will be obviously displayed at the top of the page and the content section will be displayed just below. &lt;/p&gt;

&lt;p&gt;Let’s add a bit of CSS to that by opening the “default.css” file stored in the “css” directory. You’ll see that there is already some predefined CSS to handle the various available Windows 8 views thanks to &lt;strong&gt;Media Queries&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;In these 2 articles, we will concentrate our efforts only on the “&lt;strong&gt;fullscreen-landscape&lt;/strong&gt;“ state. So jump into this section and insert the following piece of CSS:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#main
&lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
}

&lt;span style="color: maroon"&gt;#banner
&lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
}

&lt;span style="color: maroon"&gt;#backbutton
&lt;/span&gt;{
}

&lt;span style="color: maroon"&gt;#maintitle
&lt;/span&gt;{
}

&lt;span style="color: maroon"&gt;#content
&lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;This simply indicates that we’d like to take all the available space for our 3 main containers. &lt;/p&gt;

&lt;p&gt;Run your application by pressing the F5 key or by clicking on the following button: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7674.clip_5F00_image003_5F00_39DE6AF6.png"&gt;&lt;img title="clip_image003" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image003" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4370.clip_5F00_image003_5F00_thumb_5F00_09B72033.png" width="127" height="23" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Logically, you should now see this screen:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8267.clip_5F00_image005_5F00_4BBD8F74.jpg"&gt;&lt;img title="clip_image005" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image005" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7181.clip_5F00_image005_5F00_thumb_5F00_5FD6ABFD.jpg" width="240" height="136" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And you should also see an obvious design problem: the back button and the title are not aligned. Let’s resolve this by using Blend 5! &lt;/p&gt;

&lt;h2 id="etape3"&gt;Step 3: first contact with Blend&lt;/h2&gt;

&lt;p&gt;Launch Blend and navigate to the folder where your SimpleChannel9Reader project is. Blend will then show that:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0160.clip_5F00_image007_5F00_73EFC886.jpg"&gt;&lt;img title="clip_image007" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image007" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3806.clip_5F00_image007_5F00_thumb_5F00_1335000B.jpg" width="640" height="341" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The goal here is to create 2 grids. The first one will be for the main container. It will be defined by 1 column that will take all the available width &amp;amp; by 2 lines. The 2&lt;sup&gt;nd&lt;/sup&gt; one will be defined by 1 line &amp;amp; 2 columns for the back button and the title. &lt;/p&gt;

&lt;p&gt;Let’s start by the select the “main” element by using the “&lt;strong&gt;Live DOM&lt;/strong&gt;” window: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5050.clip_5F00_image008_5F00_54D1CD08.png"&gt;&lt;img title="clip_image008" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image008" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1323.clip_5F00_image008_5F00_thumb_5F00_243E4F50.png" width="240" height="104" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Jump to the “&lt;b&gt;Layout&lt;/b&gt;” window and switch the display to “&lt;b&gt;&lt;i&gt;-ms-grid&lt;/i&gt;&lt;/b&gt;”: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2804.clip_5F00_image009_5F00_0F4F5D8E.png"&gt;&lt;img title="clip_image009" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image009" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7585.clip_5F00_image009_5F00_thumb_5F00_50E999DA.png" width="240" height="185" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We’re going to use the &lt;b&gt;CSS Grid Layout&lt;/b&gt; specification currently only supported by IE10 but that should soon land in other browser. If you’d like to know more about the type of layout supported in the Metro mode, you can read this article: &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465327.aspx"&gt;Choosing a CSS3 layout for your app&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;If you simply want to discover the CSS3 Grid specification, feel free to play with this IE Test Drive demo: &lt;a title="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_grid.htm" href="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_grid.htm"&gt;Hands On: CSS3 Grid Layout&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Ok, now that the display is properly switched into grid, we need to define our grid. For that, jump to the “&lt;b&gt;Grid&lt;/b&gt;” part and declare the following properties:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0741.clip_5F00_image010_5F00_697BC7DB.png"&gt;&lt;img title="clip_image010" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image010" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8255.clip_5F00_image010_5F00_thumb_5F00_128666D8.png" width="240" height="63" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;We will have a unique column spanning through the complete width of the screen (whatever the resolution will be) and 2 lines. The first line will have a “fixed” height size of 132px and the other one will take the remaining space. You can see this inside the Blend designer surface:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7266.clip_5F00_image012_5F00_6FC52F1A.jpg"&gt;&lt;img title="clip_image012" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image012" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0333.clip_5F00_image012_5F00_thumb_5F00_1CDCAC9A.jpg" width="640" height="395" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now, we’re going to move the “&lt;b&gt;content&lt;/b&gt;” element into the 2&lt;sup&gt;nd&lt;/sup&gt; line. Select it into the “&lt;b&gt;Live DOM&lt;/b&gt;” and move to its “&lt;b&gt;Grid&lt;/b&gt;” properties. Change the “&lt;b&gt;-ms-grid-row&lt;/b&gt;” value to 2. You can also move the “&lt;b&gt;banner&lt;/b&gt;” element to the row 1 but it will be there by default otherwise. &lt;/p&gt;

&lt;p&gt;We’re now going to split our first line into 2 columns in order to move each element in the right places. Select the “&lt;b&gt;banner&lt;/b&gt;” element, switch its display property to “-ms-grid” and define 1fr line &amp;amp; 2 columns of 120px and 1fr: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2388.clip_5F00_image013_5F00_42D4EDA1.png"&gt;&lt;img title="clip_image013" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image013" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6507.clip_5F00_image013_5F00_thumb_5F00_5DA113AD.png" width="224" height="70" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Move the “&lt;b&gt;maintitle&lt;/b&gt;” element into column 2 and center it vertically thanks to the “&lt;b&gt;-ms-grid-row-align&lt;/b&gt;” property changed to “&lt;b&gt;center&lt;/b&gt;”:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4861.clip_5F00_image014_5F00_342CD26D.png"&gt;&lt;img title="clip_image014" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image014" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6505.clip_5F00_image014_5F00_thumb_5F00_040587AA.png" width="240" height="187" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Select the “&lt;b&gt;backbutton&lt;/b&gt;” and jump to the “&lt;b&gt;Layout&lt;/b&gt;” part. Set a &lt;b&gt;54px&lt;/b&gt; top margin and a &lt;b&gt;40px&lt;/b&gt; left margin. If you haven’t missed something, you should now see that on the design surface:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7585.clip_5F00_image016_5F00_23B6F223.jpg"&gt;&lt;img title="clip_image016" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image016" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3343.clip_5F00_image016_5F00_thumb_5F00_1C2E1367.jpg" width="240" height="144" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Save all changes via “&lt;em&gt;File&lt;/em&gt;” à “&lt;em&gt;Save All&lt;/em&gt;” and go back to Visual Studio. Open “&lt;em&gt;default.css&lt;/em&gt;” and you’ll see that Blend has generated some “clean” CSS in the right rules:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@media &lt;/span&gt;screen and (-ms-view-state: fullscreen-landscape)
{

    &lt;span style="color: maroon"&gt;#main
    &lt;/span&gt;{
        &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
        &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
        &lt;span style="color: red"&gt;display&lt;/span&gt;: &lt;span style="color: blue"&gt;-ms-grid&lt;/span&gt;;
        &lt;span style="color: red"&gt;-ms-grid-columns&lt;/span&gt;: &lt;span style="color: blue"&gt;1fr&lt;/span&gt;;
        &lt;span style="color: red"&gt;-ms-grid-rows&lt;/span&gt;: &lt;span style="color: blue"&gt;132px 1fr&lt;/span&gt;;
    }

    &lt;span style="color: maroon"&gt;#banner
    &lt;/span&gt;{
        &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
        &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
        &lt;span style="color: red"&gt;display&lt;/span&gt;: &lt;span style="color: blue"&gt;-ms-grid&lt;/span&gt;;
        &lt;span style="color: red"&gt;-ms-grid-columns&lt;/span&gt;: &lt;span style="color: blue"&gt;120px 1fr&lt;/span&gt;;
        &lt;span style="color: red"&gt;-ms-grid-rows&lt;/span&gt;: &lt;span style="color: blue"&gt;1fr&lt;/span&gt;;
    }

    &lt;span style="color: maroon"&gt;#backbutton
    &lt;/span&gt;{
        &lt;span style="color: red"&gt;margin-top&lt;/span&gt;: &lt;span style="color: blue"&gt;54px&lt;/span&gt;;
        &lt;span style="color: red"&gt;margin-left&lt;/span&gt;: &lt;span style="color: blue"&gt;40px&lt;/span&gt;;
    }

    &lt;span style="color: maroon"&gt;#maintitle
    &lt;/span&gt;{
        &lt;span style="color: red"&gt;-ms-grid-column&lt;/span&gt;: &lt;span style="color: blue"&gt;2&lt;/span&gt;;
        &lt;span style="color: red"&gt;-ms-grid-row-align&lt;/span&gt;: &lt;span style="color: blue"&gt;center&lt;/span&gt;;
    }

    &lt;span style="color: maroon"&gt;#content
    &lt;/span&gt;{
        &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
        &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
        &lt;span style="color: red"&gt;-ms-grid-row&lt;/span&gt;: &lt;span style="color: blue"&gt;2&lt;/span&gt;;
    }
}&lt;/pre&gt;

&lt;p&gt;Simply check that the application works fine by pressing F5. &lt;/p&gt;

&lt;h2 id="etape4"&gt;Step 4: loading the data with XHR and bind them to the ListView control&lt;/h2&gt;

&lt;p&gt;Ok, let’s now dig a little bit into the code. &lt;/p&gt;

&lt;p&gt;First thing to do is to insert the control that will be in charge of displaying our articles’ thumbnails on the welcome screen. We’re going to use WinJS for that. &lt;/p&gt;

&lt;p&gt;The WinJS library or “&lt;b&gt;Microsoft Window Library for JavaScript SDK&lt;/b&gt;” is made to help the JavaScript developers implementing the Windows 8 Metro experience in an easy way. It provides a set of Metro controls, a templating engine, a binding engine, Promises to handle the asynchronous calls, helpers to handle Namespaces, etc. &lt;/p&gt;

&lt;p&gt;For instance, if you’d like to learn more about the controls part, you can read this article: &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465493"&gt;Quickstart: adding WinJS controls and styles&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;In Windows 8 Metro projects, you’ll find this library in the references section of the “&lt;b&gt;Solution Explorer&lt;/b&gt;”: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8461.image_5F00_1E6A2512.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4251.image_5F00_thumb_5F00_5B8DE097.png" width="240" height="184" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Inside, you’ll find the default style sheets with the 2 &lt;i&gt;dark&lt;/i&gt; &amp;amp; &lt;i&gt;light&lt;/i&gt; themes provided as well as the JavaScript code. Feel free to have a look to it. It could be interesting to learn by reading the code. &lt;/p&gt;

&lt;p&gt;In our case, we’re going to use the ListView control which creates a grid layout to display the list of elements. &lt;/p&gt;

&lt;p&gt;Open “&lt;b&gt;&lt;i&gt;default.html&lt;/i&gt;&lt;/b&gt;” and inside the section tag, type this piece of HTML: &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;articlelist&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;data-win-control&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;WinJS.UI.ListView&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Currently, it’s only a simple classical div. However, it’s annotated with the &lt;b&gt;data-win-control&lt;/b&gt; attribute which indicates that we’d like to use the &lt;b&gt;WinJS&lt;/b&gt; library to transform this simple div into a JavaScript &lt;b&gt;ListView&lt;/b&gt; control. &lt;/p&gt;

&lt;p&gt;This operation is done thanks to a magical line of JavaScript code you’ll find into “&lt;i&gt;default.js&lt;/i&gt;”. Here it is: &lt;/p&gt;

&lt;pre class="code"&gt;WinJS.UI.processAll();&lt;/pre&gt;

&lt;p&gt;This asynchronous operation will parse the DOM to find all the elements tagged with “data-win-control” attributes to transform them into real WinJS controls implementing the Metro experience for you. If you remove this line by mistake, all your div will become again some simple div. &lt;/p&gt;

&lt;p&gt;We now need to feed this &lt;i&gt;ListView&lt;/i&gt; with some data grabbed from the RSS feed. In the function bind to the “&lt;b&gt;onactivated&lt;/b&gt;” event, add this piece of code just above the &lt;b&gt;processAll()&lt;/b&gt; line: &lt;/p&gt;

&lt;pre class="code"&gt;articlesList = &lt;span style="color: blue"&gt;new &lt;/span&gt;WinJS.Binding.List();
&lt;span style="color: blue"&gt;var &lt;/span&gt;publicMembers = { ItemList: articlesList };
WinJS.Namespace.define(&lt;span style="color: maroon"&gt;&amp;quot;C9Data&amp;quot;&lt;/span&gt;, publicMembers);&lt;/pre&gt;

&lt;p&gt;You’ll need then to declare the “&lt;i&gt;articlesList&lt;/i&gt;” variable at the top of the function just below the “&lt;i&gt;app&lt;/i&gt;” one for instance. &lt;/p&gt;

&lt;p&gt;We’re declaring here a &lt;b&gt;Binding.List()&lt;/b&gt; type. It’s the type to use to bind your data to the WinJS controls. It contains for instance some methods that will help you to add some data in background and thanks to the binding mechanism; it will be reflected into the view automatically. &lt;/p&gt;

&lt;p&gt;Moreover, you may have noticed that we’re using some clean JavaScript code by using modern patterns like the “&lt;b&gt;module pattern&lt;/b&gt;” for instance. For that, we have an anonymous self-executed JS function into “&lt;i&gt;default.js&lt;/i&gt;”. We then need to find a way to expose some public data to external functions. That’s why we’re implementing the &lt;b&gt;Namespace&lt;/b&gt; concept into the associated WinJS helper. It helps us to easily define what we’d like to expose. In our case, we will have a public “&lt;b&gt;C9Data&lt;/b&gt;” object that will have an “&lt;b&gt;ItemList&lt;/b&gt;” property containing our future elements to display. &lt;/p&gt;

&lt;p&gt;We now need a function that’ll grad the data from the RSS feed, parse them and create some JS objects on the fly to push them into the famous binding list. Here is mine: &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;downloadC9BlogFeed() {
    WinJS.xhr({ url: &lt;span style="color: maroon"&gt;&amp;quot;http://channel9.msdn.com/coding4fun/articles/RSS&amp;quot; &lt;/span&gt;}).then(&lt;span style="color: blue"&gt;function &lt;/span&gt;(rss) {

    });
}&lt;/pre&gt;

&lt;p&gt;This function starts by running an asynchronous &lt;b&gt;XmlHttpRequest&lt;/b&gt; to the specified URL. The code defined into the &lt;b&gt;Promise&lt;/b&gt; (into the .then() if you want) will then be executed only once the request will be finished and the data received. It’s then here that we need to filter the data via this piece of code you have to insert into the anonymous function:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;items = rss.responseXML.selectNodes(&lt;span style="color: maroon"&gt;&amp;quot;//item&amp;quot;&lt;/span&gt;);

&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;n = 0; n &amp;lt; items.length; n++) {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;article = {};
    article.title = items[n].selectSingleNode(&lt;span style="color: maroon"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;).text;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;thumbs = items[n].selectNodes(&lt;span style="color: maroon"&gt;&amp;quot;media:thumbnail&amp;quot;&lt;/span&gt;);
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(thumbs.length &amp;gt; 1) {
        article.thumbnail = thumbs[1].attributes.getNamedItem(&lt;span style="color: maroon"&gt;&amp;quot;url&amp;quot;&lt;/span&gt;).text;
        article.content = items[n].text;
        articlesList.push(article);
    }
}&lt;/pre&gt;

&lt;p&gt;I hope that this code will be self-explicit. It selects the “&lt;i&gt;item&lt;/i&gt;” nodes, access to their interesting properties to map them to an “article” object created on the fly on the “&lt;i&gt;title&lt;/i&gt;”, “&lt;i&gt;thumbs&lt;/i&gt;” &amp;amp; “&lt;i&gt;content&lt;/i&gt;” properties. Please keep in mind the name of those properties; we will use them later on. At last, this function finishes by adding this new object to the binding collection. &lt;/p&gt;

&lt;p&gt;We now need to run this function during the starting phase of our application. This code should run once the DOM parsing will be done to build the WinJS controls. So, to do that, use this line of code: &lt;/p&gt;

&lt;pre class="code"&gt;WinJS.UI.processAll().then(downloadC9BlogFeed);&lt;/pre&gt;

&lt;p&gt;We have to specify to the control its data source. Jump back into the HTML code and modify the div associated to the ListView to change its options:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;articlelist&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;data-win-control&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;WinJS.UI.ListView&amp;quot;
    &lt;/span&gt;&lt;span style="color: red"&gt;data-win-options&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{ itemDataSource: C9Data.ItemList.dataSource }&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;At last, we need some basic CSS to help the control to know how to draw each of its items. Jump to the “&lt;em&gt;default.css&lt;/em&gt;” file and add these 2 rules:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#articlelist
&lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
}

&lt;span style="color: maroon"&gt;#articlelist .win-item
&lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;150px&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;150px&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;This CSS indicates that our ListView control should take all the available space of its container and that each of its items (via the “&lt;b&gt;.win-item&lt;/b&gt;” class”) should take 150 by 150 pixels. &lt;/p&gt;

&lt;p&gt;Run the solution by pressing F5. You’ll have something as ugly as that: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4540.clip_5F00_image018_5F00_5DC84FB3.jpg"&gt;&lt;img title="clip_image018" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image018" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8540.clip_5F00_image018_5F00_thumb_5F00_10BD017D.jpg" width="640" height="360" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;But don’t panic, this ugly output is the expected behavior! &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7674.wlEmoticon_2D00_winkingsmile_5F00_612DF9C6.png" /&gt; We still have a bit of design to work on. But you can already see that the binding works correctly and that the control works fine with touch’ &amp;amp; mouse experiences. Moreover, the control automatically scales to the various resolutions. You’ll then not have the exact layout (number of columns &amp;amp; lines displayed) that the above screen in your case. &lt;/p&gt;

&lt;h2 id="etape5"&gt;Step 5: using a template and modifying the design with Blend&lt;/h2&gt;

&lt;p&gt;We now need to change the way each element is drawn. This is exactly the purpose of the templating engine. A template is only a piece of HTML marked with WinJS attributes. &lt;/p&gt;

&lt;p&gt;Navigate to the “&lt;i&gt;default.html&lt;/i&gt;” page and add this piece of HTML just above the “&lt;i&gt;main&lt;/i&gt;” part: &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;C9ItemTemplate&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;data-win-control&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;WinJS.Binding.Template&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;style&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color: red"&gt;display&lt;/span&gt;&lt;span style="color: blue"&gt;: none;&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;listItemTemplate&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;listItemImage&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;img &lt;/span&gt;&lt;span style="color: red"&gt;data-win-bind&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;src: thumbnail&amp;quot; /&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;listItemTitle&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;data-win-bind&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;innerText: title&amp;quot;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;It’s an HTML template marked with the “&lt;b&gt;WinJS.Binding.Template&lt;/b&gt;” value. This will help WinJS to know what to do with this special piece of HTML after the &lt;b&gt;processAll()&lt;/b&gt; execution. You’ll find also the usage of “&lt;b&gt;&lt;i&gt;data-win-bind&lt;/i&gt;&lt;/b&gt;” to define binding expressions. It will help the binding engine to know which JavaScript properties from the data source to map to the appropriate HTML nodes. Except that, you can use some classic HTML. &lt;/p&gt;

&lt;p&gt;We now need to configure the WinJS control to not use the default template anymore but to use the new one above instead. It’s done by simply changing the options: &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;articlelist&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;data-win-control&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;WinJS.UI.ListView&amp;quot;
    &lt;/span&gt;&lt;span style="color: red"&gt;data-win-options&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{ itemDataSource: C9Data.ItemList.dataSource, itemTemplate: C9ItemTemplate }&amp;quot;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;If you now run the application, you should have this screen:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4846.clip_5F00_image020_5F00_6A7FC986.jpg"&gt;&lt;img title="clip_image020" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image020" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2055.clip_5F00_image020_5F00_thumb_5F00_69405209.jpg" width="640" height="360" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;It’s better but we’re not done yet. To go further in the design review, we need the help of our friend Blend. &lt;/p&gt;

&lt;p&gt;So, let’s go back into Blend. It will ask you to reload all the modifications you’ve done inside Visual Studio. Once done, you’ll have that: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3823.clip_5F00_image022_5F00_12D93E9F.jpg"&gt;&lt;img title="clip_image022" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image022" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5001.clip_5F00_image022_5F00_thumb_5F00_01F72B60.jpg" width="640" height="341" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Aren’t you surprised? You should! Indeed, we see here the same visual output you will have when you’ll press F5 in Visual Studio. This means that &lt;b&gt;Blend 5 is dynamically executing the JavaScript&lt;/b&gt; part of your application directly inside the designer! This is an awesome feature. &lt;/p&gt;

&lt;p&gt;Thanks to that, you will be able to directly work on real data without being forced to put in place what we call “&lt;i&gt;mocking&lt;/i&gt;”. It’s the cool part of JavaScript. Blend was able to execute the JS code that launch the XHR request and build the WinJS objects. &lt;/p&gt;

&lt;p&gt;Under “&lt;i&gt;default.css&lt;/i&gt;”, let’s add 2 new CSS rules. Click on the “+” button on the main media query: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5001.clip_5F00_image023_5F00_059A679F.png"&gt;&lt;img title="clip_image023" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image023" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6558.clip_5F00_image023_5F00_thumb_5F00_34EBDD29.png" width="240" height="212" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;And add these new selectors: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;.listItemTemplate&lt;/em&gt;&lt;/strong&gt; and&lt;strong&gt;&lt;em&gt; .listItemTemplate img&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Select the &lt;b&gt;#articlelist .win-item&lt;/b&gt; rule that will highlight each element of the ListView control with the “&lt;i&gt;articlelist&lt;/i&gt;” ID. &lt;/p&gt;

&lt;p&gt;Change the size of these elements to go from 150px by 150px to &lt;b&gt;250px by 250px&lt;/b&gt;. You simply need to jump into the “&lt;b&gt;Sizing&lt;/b&gt;” part of the right panel. &lt;/p&gt;

&lt;p&gt;Force a refresh of the design surface by clicking on the dedicated button: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6175.clip_5F00_image024_5F00_0FF0AD61.png"&gt;&lt;img title="clip_image024" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image024" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0218.clip_5F00_image024_5F00_thumb_5F00_31DC0FE5.png" width="89" height="30" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;And here is the result you should have:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4503.clip_5F00_image026_5F00_73E27F26.jpg"&gt;&lt;img title="clip_image026" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image026" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8132.clip_5F00_image026_5F00_thumb_5F00_492C35B8.jpg" width="640" height="391" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We’re now going to resize the template’s images. For that, select the “&lt;b&gt;Direct Selection&lt;/b&gt;” pointer and click on one of the images:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3581.clip_5F00_image028_5F00_1588EABC.jpg"&gt;&lt;img title="clip_image028" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image028" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5164.clip_5F00_image028_5F00_thumb_5F00_641F97CA.jpg" width="640" height="226" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;You can see the current applied CSS rules in the “&lt;b&gt;Applied Rules&lt;/b&gt;” section. Click on “&lt;b&gt;.listItemTemplate img&lt;/b&gt;” and resize with your mouse the image you’ve just selected. All the other images matching the same selector will then dynamically reflect the changes in real time. &lt;/p&gt;

&lt;p&gt;Rather than searching the appropriate size, I’m going to help you. Jump into the “&lt;b&gt;Sizing&lt;/b&gt;” section and fix the following size: &lt;b&gt;234px width&lt;/b&gt; and &lt;b&gt;165px height&lt;/b&gt;. &lt;/p&gt;

&lt;p&gt;To enhance a bit more our design, we need some more space between each element and to align our ListView control with the title. &lt;/p&gt;

&lt;p&gt;Click on the “&lt;b&gt;.listItemTemplate&lt;/b&gt;” selector, navigate to the “&lt;b&gt;Layout&lt;/b&gt;” section and click on the “&lt;b&gt;Lock&lt;/b&gt;” icon at the right of the “&lt;b&gt;Margin&lt;/b&gt;” area. Select any margin and type &lt;b&gt;8px&lt;/b&gt;. &lt;/p&gt;

&lt;p&gt;At last, to align the grid of the ListView control with the title, we need to move it from the left by 120px – 8px of the element margin we’ve just set. &lt;/p&gt;

&lt;p&gt;Add a new selector by pressing on the “+” button and name it “&lt;b&gt;.win-surface&lt;/b&gt;”. Fix a left margin of &lt;b&gt;112px&lt;/b&gt;. &lt;/p&gt;

&lt;p&gt;Go back to Visual Studio, accept the changes done and press F5. You should now have this kind of layout: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3581.clip_5F00_image030_5F00_6EE21081.jpg"&gt;&lt;img title="clip_image030" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image030" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3326.clip_5F00_image030_5F00_thumb_5F00_0B14EA11.jpg" width="640" height="360" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h2 id="etape6"&gt;Step 6: video demonstrating all the steps &amp;amp; source code to download&lt;/h2&gt;

&lt;p&gt;Here are 2 HTML5 videos where I’m playing all these steps for you:&lt;/p&gt;

&lt;p&gt;The first one will show you the &lt;strong&gt;steps 1, 2 &amp;amp; 3&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="SimpleChannel9ReaderPart1A" class="video-js" height="360" width="640" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1A.jpg"&gt;&lt;source src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1A.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1A.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="640" type="application/x-shockwave-flash" height="360"&gt;  
 &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  
 &lt;param name="allowfullscreen" value="true" /&gt;  
 &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1A.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1A.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  
 &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   
 &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1A.jpg" width="512" height="288" /&gt;   
 &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt;&lt;a href="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1A.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1A.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;The 2nd one will do the &lt;strong&gt;steps 4 and 5&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="SimpleChannel9ReaderPart1B" class="video-js" height="360" width="640" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1B.jpg"&gt;&lt;source src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1B.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1B.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="640" type="application/x-shockwave-flash" height="360"&gt;  
 &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  
 &lt;param name="allowfullscreen" value="true" /&gt;  
 &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1B.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1B.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  
 &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   
 &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1B.jpg" width="512" height="288" /&gt;   
 &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt;&lt;a href="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1B.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1B.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;We’ve made good progress so far. We now need to display the detail of each article, to continue discovering the power of Blend as well as a couple of new cool CSS3 features. You can download the solution associated to this first article here: &lt;a title="http://david.blob.core.windows.net/win8/SimpleChannel9ReaderArticle1.zip" href="http://david.blob.core.windows.net/win8/SimpleChannel9ReaderArticle1.zip"&gt;Simple Channel9 Reader Article1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See you in the next article for that.&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10304325" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/CSS3/">CSS3</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Metro/">Metro</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Blend+5/">Blend 5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/WinJS/">WinJS</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Windows+8/">Windows 8</category></item><item><title>Comment créer un petit lecteur RSS pour Windows 8 Metro en HTML5 en 30 min (partie 2/2)</title><link>http://blogs.msdn.com/b/davrous/archive/2012/04/20/comment-cr-233-er-un-petit-lecteur-de-flux-rss-pour-windows-8-metro-en-html5-et-en-30-min-partie-2-2.aspx</link><pubDate>Fri, 20 Apr 2012 18:50:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10295918</guid><dc:creator>David Rousset</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10295918</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/04/20/comment-cr-233-er-un-petit-lecteur-de-flux-rss-pour-windows-8-metro-en-html5-et-en-30-min-partie-2-2.aspx#comments</comments><description>&lt;!-- Include the VideoJS Library --&gt;  &lt;p&gt;&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;&lt;/p&gt;  &lt;p&gt;Nous allons maintenant voir comment afficher le détail des articles de blogs. Pour cela, nous allons utiliser une &lt;b&gt;animation de transition&lt;/b&gt;, jouer avec le &lt;b&gt;simulateur&lt;/b&gt; et continuer à utiliser Blend pour mettre en place du &lt;b&gt;CSS3 Multi-columns&lt;/b&gt;.&lt;/p&gt;  &lt;p&gt;Comme toujours, vous trouverez à la fin une vidéo déroulant les étapes que vous pouvez suivre en lisant cet article ainsi que le code source de la solution.&lt;/p&gt;  &lt;p&gt;Cet article fait suite au précédent : &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/04/19/comment-cr-233-er-un-petit-lecteur-de-flux-rss-pour-windows-8-metro-en-html5-et-en-30-min-partie-1-2.aspx"&gt;Comment créer un petit lecteur de flux RSS pour Windows 8 Metro en HTML5 et en 30 min (partie 1/2)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Au menu pour ce deuxième article :&lt;/p&gt;  &lt;p&gt;- Etape 1 : utiliser le simulateur    &lt;br /&gt;- &lt;a href="#etape2"&gt;Etape 2 : afficher le détail de l’article&lt;/a&gt;     &lt;br /&gt;- &lt;a href="#etape3"&gt;Etape 3 : finaliser le design de la vue détail sous Blend&lt;/a&gt;     &lt;br /&gt;- &lt;a href="#etape4"&gt;Etape 4 : vidéo et code source à télécharger&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;Etape 1 : utiliser le simulateur &lt;/h2&gt;  &lt;p&gt;Il est important de savoir comment son application se comporte au touch et avec les différentes résolutions des futurs PC et tablettes Windows 8. &lt;/p&gt;  &lt;p&gt;Avant de vous ruer sur l’achat d’une tablette, étape malgré tout indispensable pour bien tester son application, il existe un outil qui peut être pratique pour dégrossir le sujet : le simulateur. &lt;/p&gt;  &lt;p&gt;Par exemple, si l’on reprend notre projet tel que fini à l’étape précédente, on peut observer le comportement au touch en lançant le simulateur via ce bouton :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8741.clip_5F00_image001_5F00_2130A188.png"&gt;&lt;img title="clip_image001" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image001" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3652.clip_5F00_image001_5F00_thumb_5F00_69EA1A4C.png" width="202" height="123" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Le simulateur se lance alors. Ce dernier consiste en fait à faire une session RDP (de type Terminal Server si vous voulez) sur vous-même. Voici le résultat que vous devriez avoir :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3073.clip_5F00_image003_5F00_19A7C2CC.jpg"&gt;&lt;img title="clip_image003" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image003" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1488.clip_5F00_image003_5F00_thumb_5F00_4BA1F407.jpg" width="640" height="394" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Vous pouvez commencer par cliquer sur cet icône :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1004.clip_5F00_image004_5F00_28748955.png"&gt;&lt;img title="clip_image004" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image004" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2477.clip_5F00_image004_5F00_thumb_5F00_3CF9D8D3.png" width="29" height="29" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Pour simuler le touch. &lt;/p&gt;  &lt;p&gt;Jouer à « glisser » le doigt virtuel sur l’affichage. Vous verrez alors que l’inertie et le rebond sur les côtés sont déjà bien gérés. De la même manière, si vous touchez un élément et que vous maintenez en descendant légèrement vers le bas, vous sélectionnerez un élément de la liste. C’est la même action que le bouton droit de la souris et c’est la même action que vous pouvez faire sur l’écran de démarrage de Windows 8. Cette gesture est donc commune à l’expérience Metro que nous construisons avec Windows 8. &lt;/p&gt;  &lt;p&gt;Un autre bouton qui peut être bien pratique est celui permettant de simuler les différentes résolutions :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0250.clip_5F00_image005_5F00_7F6C7B09.png"&gt;&lt;img title="clip_image005" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image005" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5127.clip_5F00_image005_5F00_thumb_5F00_55F839C9.png" width="201" height="189" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Essayez par exemple de simuler un 23’’ de 1920x1080 en cliquant sur ce modèle. Vous devriez maintenant avoir ce type de répartition de vos éléments :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2806.clip_5F00_image007_5F00_17927616.jpg"&gt;&lt;img title="clip_image007" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image007" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5621.clip_5F00_image007_5F00_thumb_5F00_69A7B40E.jpg" width="640" height="395" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Vous observerez que l’on passe de 2 lignes d’éléments à 3 lignes en 1080p. De la même manière, on passe de 5 colonnes visibles en largeur à 7. C’est le contrôle &lt;em&gt;ListView&lt;/em&gt; qui s’occupe de gérer les différents facteurs de forme pour vous. &lt;/p&gt;  &lt;p&gt;Donc même si WinJS n’est pas obligatoire dans un projet HTML5 Metro, ne sous-estimez pas l’intérêt de son utilisation. Surtout lorsque l’on voit le type de service qu’elle peut facilement rendre !&lt;/p&gt;  &lt;h2 id="etape2"&gt;Etape 2 : afficher le détail de l’article &lt;/h2&gt;  &lt;p&gt;Pour afficher le contenu de l’article, il nous faut un morceau d’HTML supplémentaire. Pour cela, rendez-vous dans la page « &lt;i&gt;default.html &lt;/i&gt;» et insérez cette partie :&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;articlecontent&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;On va insérer le contenu de l’article sélectionné par code. Rendez-vous donc dans « &lt;i&gt;default.js&lt;/i&gt; ». Juste au-dessus de l’instanciation de la Binding.List, insérez ce code :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;articlelistElement = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;articlelist&amp;quot;&lt;/span&gt;);
articlelistElement.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;iteminvoked&amp;quot;&lt;/span&gt;, itemInvoked);
backbutton.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;click&amp;quot;&lt;/span&gt;, backButtonClick);&lt;/pre&gt;

&lt;p&gt;On récupère notre élément « &lt;em&gt;articlelist&lt;/em&gt; » du DOM qui se trouvera être un contrôle WinJS de type &lt;em&gt;ListView&lt;/em&gt; juste après le passage du processAll. Ce dernier exposera donc un évènement nommé « &lt;em&gt;iteminvoked&lt;/em&gt; » levé lorsque vous cliquerez/toucherez un des éléments de la liste. Par ailleurs, on s’abonne à l’évènement « &lt;em&gt;click&lt;/em&gt; » du bouton « &lt;em&gt;back&lt;/em&gt; » pour revenir simplement sur la page d’accueil.&lt;/p&gt;

&lt;p&gt;Il nous faut maintenant les gestionnaires d’évènements associés. Les voici :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;backButtonClick(e) {
    articlecontent.style.display = &lt;span style="color: maroon"&gt;&amp;quot;none&amp;quot;&lt;/span&gt;;
    articlelist.style.display = &lt;span style="color: maroon"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;itemInvoked(e) {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;currentArticle = articlesList.getAt(e.detail.itemIndex);
    setInnerHTMLUnsafe(articlecontent, currentArticle.content);
    articlelist.style.display = &lt;span style="color: maroon"&gt;&amp;quot;none&amp;quot;&lt;/span&gt;;
    articlecontent.style.display = &lt;span style="color: maroon"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;L’idée est extrêmement simple. Lorsque l’utilisateur va cliquer sur un des éléments, on va récupérer dans la collection l’objet qui nous intéresse via son index (&lt;i&gt;e.detail.itemIndex&lt;/i&gt;). On injecte ensuite le contenu HTML de l’article dans la propriété &lt;em&gt;innerHTML&lt;/em&gt; de la div que nous venons juste d’insérer dans la page HTML principale. Par contre, cela se fait via l’appel à &lt;b&gt;&lt;i&gt;setInnerHTMLUnsafe()&lt;/i&gt;&lt;/b&gt;. Pourquoi d’ailleurs l’appel à cette méthode étrange venue d’ailleurs ? &lt;/p&gt;

&lt;h3&gt;Petite aparté sur le contexte de sécurité des applications Metro&lt;/h3&gt;

&lt;p&gt;Le contexte de sécurité dans lequel vous vous trouvez dans une application HTML5 Metro est bien évidemment différent d’une application web classique. Toute tentative de manipulation directe de la propriété &lt;em&gt;innerHTML&lt;/em&gt; est ainsi par exemple protégée. &lt;/p&gt;

&lt;p&gt;Si vous tentez par exemple d’y insérer du HTML venant du « web public », une exception de sécurité sera levée par défaut pour vous protéger. Imaginez en effet que quelqu’un y injecte un morceau de script prenant le contrôle de votre application ? Cela ne vous ferait pas plaisir.&lt;/p&gt;

&lt;p&gt;On préfère ainsi que vous ayez conscience de cela mais on vous laisse la possibilité de « by-passer » cette vérification via l’appel de la fonction &lt;b&gt;&lt;i&gt;setInnerHTMLUnsafe()&lt;/i&gt;&lt;/b&gt; qui porte bien son nom. &lt;/p&gt;

&lt;p&gt;De la même manière, la technique pour insérer un &amp;lt;iframe&amp;gt; est légèrement différente. Si tout cela vous intéresse, voici quelques articles à lire :&lt;/p&gt;

&lt;p&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx"&gt;HTML, CSS, and JavaScript features and differences&lt;/a&gt; 

  &lt;br /&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465373.aspx"&gt;Features and restrictions by context 
    &lt;br /&gt;&lt;/a&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465388.aspx"&gt;Making HTML safer: details for toStaticHTML&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bon revenons à nos moutons. &lt;/p&gt;

&lt;p&gt;La technique que nous utilisons pour faire apparaitre le contenu est donc toute simple. On cache la liste des éléments en basculant son « &lt;i&gt;display&lt;/i&gt; » à « &lt;i&gt;none&lt;/i&gt; » et on fait apparaitre le div « &lt;i&gt;articlecontent&lt;/i&gt; ». Lorsque l’on clique que le bouton « &lt;i&gt;back&lt;/i&gt; », on fait exactement l’inverse.&lt;/p&gt;

&lt;p&gt;Si vous lancez l’ensemble en faisant F5, vous aurez ce type de résultat en cliquant sur un des éléments :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4503.clip_5F00_image009_5F00_49D2FF06.jpg"&gt;&lt;img title="clip_image009" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image009" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2425.clip_5F00_image009_5F00_thumb_5F00_229B4682.jpg" width="640" height="360" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On observe que la mise en page n’est pas super sympa. Nous allons y remédier dans un instant avec l’ami Blend. &lt;/p&gt;

&lt;p&gt;Mais en attendant, j’aimerais attirer votre attention sur un point gênant. La navigation vers un article puis le retour en arrière fonctionnent bien. Mais tout cela est un peu &lt;em&gt;brut de fonderie&lt;/em&gt; en terme d’expérience utilisateur. &lt;/p&gt;

&lt;p&gt;La philosophie derrière le concept Metro introduit également la notion de « &lt;em&gt;Fast &amp;amp; Fluid&lt;/em&gt; ». Il faut donner l’impression à l’utilisateur que votre application est toujours bien vivante et performante. Pour cela, il se trouve que mettre en place de légères animations de transitions permet d’influer sur cette impression de fluidité. Pour cela, vous avez 2 options. &lt;/p&gt;

&lt;p&gt;Soit vous utilisez CSS3 Transitions/Animations pour faire afficher/disparaitre les contenus qui vous intéressent. Charge alors à vous de trouver les bonnes animations et le bon dosage. Si vous souhaitez d’ailleurs vous initier à cette nouvelle partie de CSS3, je vous conseille la lecture d’articles que nous avons écrit mon collègue David Catuhe et moi-même sur ce sujet précis :&lt;/p&gt;

&lt;p&gt;- &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2011/11/24/fr-introduction-224-css3-transitions.aspx"&gt;Introduction aux transitions CSS3&lt;/a&gt; 

  &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-aux-animations-css3.aspx"&gt;Introduction aux animations CSS3&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Soit vous utilisez la librairie WinJS qui expose un moteur d’animations préconçues pour vous aider à respecter la philosophie Metro. Derrière, ce sont finalement bien des transitions/animations CSS utilisées. Mais pour vous développeur, ce n’est qu’une simple ligne de JavaScript à appeler. &lt;/p&gt;

&lt;p&gt;Par exemple, dans le gestionnaire&lt;em&gt; itemInvoked()&lt;/em&gt;, insérez cette ligne à la fin de la fonction :&lt;/p&gt;

&lt;pre class="code"&gt;WinJS.UI.Animation.enterPage(articlecontent);&lt;/pre&gt;

&lt;p&gt;Et insérez celle-ci dans l’autre gestionnaire d’évènement :&lt;/p&gt;

&lt;pre class="code"&gt;WinJS.UI.Animation.enterPage(articlelist);&lt;/pre&gt;

&lt;p&gt;Si vous relancez l’ensemble en pressant F5, vous devriez maintenant voir de subtiles transitions pendant votre navigation. C’est celles-ci qui vont faire toute la différence croyez-moi !&lt;/p&gt;

&lt;h2 id="etape3"&gt;Etape 3 : finaliser le design de la vue détail sous Blend&lt;/h2&gt;

&lt;p&gt;Retournez sous Blend. Ce dernier devrait à nouveau vous demander de recharger l’ensemble suite à vos modifications sous Visual Studio.&lt;/p&gt;

&lt;p&gt;Alors la question du jour sera : &lt;strong&gt;comment réussir à designer la page détail de l’article vu qu’il faut simuler le fait que l’on sélectionne un des articles pour cela ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;La réponse, vous l’avez déjà eu dans l’article précédent. Blend 5 exécute en live votre application HTML5 Metro ! Mais il vous manque une information supplémentaire pour vous en sortir. Voici la solution. Vous pouvez passer en mode « interactif » en cliquant sur ce bouton-là :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1263.clip_5F00_image010_5F00_31D1AF4F.png"&gt;&lt;img title="clip_image010" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image010" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2437.clip_5F00_image010_5F00_thumb_5F00_0620E553.png" width="96" height="25" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;qui devrait s’appeler « &lt;strong&gt;&lt;em&gt;Turn on Interactive Mode&lt;/em&gt;&lt;/strong&gt; ». En cliquant dessus, vous pouvez alors ensuite interagir avec votre application, naviguez vers la page que vous souhaitez travailler et revenir dans l’interface de design en cliquant sur le même bouton. Dans mon cas, j’ai choisi de partir sur cet article :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3173.clip_5F00_image012_5F00_6CB8E218.jpg"&gt;&lt;img title="clip_image012" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image012" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3808.clip_5F00_image012_5F00_thumb_5F00_1EB31354.jpg" width="640" height="341" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dans les styles, sous la bonne &lt;em&gt;Media Query&lt;/em&gt;, ajoutez une règle sur le sélecteur « &lt;b&gt;&lt;i&gt;#artictecontent&lt;/i&gt;&lt;/b&gt; » puis sélectionnez là immédiatement.&lt;/p&gt;

&lt;p&gt;Dans la partie « &lt;b&gt;&lt;i&gt;Sizing&lt;/i&gt;&lt;/b&gt; », fixez la &lt;b&gt;largeur&lt;/b&gt; et la &lt;b&gt;hauteur&lt;/b&gt; à &lt;b&gt;100%&lt;/b&gt;. &lt;/p&gt;

&lt;p&gt;Dans la partie « &lt;b&gt;&lt;i&gt;Layout&lt;/i&gt;&lt;/b&gt; », fixez un &lt;b&gt;padding&lt;/b&gt; à gauche de &lt;b&gt;120px&lt;/b&gt; afin d’aligner le contenu avec le titre principal. &lt;/p&gt;

&lt;p&gt;Oops… cela génère un problème du coup. Le layout dans notre div « &lt;i&gt;articlecontent&lt;/i&gt; » a tendance à trop déborder sur la largeur. &lt;/p&gt;

&lt;p&gt;Pour régler ce problème, modifiez la propriété « &lt;b&gt;&lt;i&gt;width&lt;/i&gt;&lt;/b&gt; » et indiquez sur vous souhaitez utiliser une « &lt;b&gt;&lt;i&gt;custom expression&lt;/i&gt;&lt;/b&gt; » :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3007.clip_5F00_image013_5F00_2FDFAD28.png"&gt;&lt;img title="clip_image013" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image013" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4578.clip_5F00_image013_5F00_thumb_5F00_587E192F.png" width="244" height="174" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nous allons utiliser &lt;a href="http://www.w3.org/TR/css3-values/#calc0"&gt;l’opérateur CSS Calc()&lt;/a&gt;. Entrez l’expression suivante : « &lt;b&gt;calc(100%-120px)&lt;/b&gt; ».&lt;/p&gt;

&lt;p&gt;Le design Metro commence alors à prendre forme. Il reste une ultime étape pour bien faire : mettre en place une expérience de défilement horizontal et mettre en forme le texte de manière plus lisible.&lt;/p&gt;

&lt;p&gt;Commençons par rendre plus lisible le texte. Une nouvelle fonctionnalité de CSS3 est extrêmement pratique et se trouve être simple à mettre en œuvre :&lt;strong&gt; CSS3 Multi-columns&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Pour cela, rendez-vous dans la section « &lt;b&gt;&lt;i&gt;Multicolumn&lt;/i&gt;&lt;/b&gt; » du panneau « &lt;b&gt;&lt;i&gt;CSS Properties&lt;/i&gt;&lt;/b&gt; » et demandez à découper le layout en colonnes de &lt;b&gt;480px de large&lt;/b&gt; séparées par &lt;b&gt;au moins 80px&lt;/b&gt; chacune.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4062.clip_5F00_image015_5F00_1796678D.jpg"&gt;&lt;img title="clip_image015" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image015" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5618.clip_5F00_image015_5F00_thumb_5F00_1FAD93E2.jpg" width="640" height="270" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cela commence à être chouette non ? &lt;/p&gt;

&lt;p&gt;Pour finir, il reste à permettre un défilement horizontal pour faire glisser l’ensemble du contenu de gauche à droite et vice-versa. Pour cela, rendez-vous dans la zone de saisie &lt;b&gt;&lt;i&gt;« Search Properties&lt;/i&gt;&lt;/b&gt; » et tapez « &lt;b&gt;over&lt;/b&gt; ». Blend vous filtre alors toutes les propriétés contenant le mot clé « over ».&lt;/p&gt;

&lt;p&gt;Fixez « &lt;b&gt;overflow-x&lt;/b&gt; » à « &lt;b&gt;auto&lt;/b&gt; » et « &lt;b&gt;overflow-y&lt;/b&gt; » à « &lt;b&gt;hidden&lt;/b&gt; ».&lt;/p&gt;

&lt;p&gt;Vous pouvez vous rendre dans Visual Studio, accepter les changements et faire F5 pour jouer avec le résultat.&lt;/p&gt;

&lt;h3&gt;Niveau bonus de fin pour les guerriers&lt;/h3&gt;

&lt;p&gt;Allez, on va se faire encore un peu plaisir pour les plus courageux. Au final, qu’est ce qui nous intéresse le plus nous les développeurs lorsque l’on lit un article technique ? Le code bien évidemment !&lt;/p&gt;

&lt;p&gt;Donc une fois que l’on sait ça, il ne faut pas hésiter à mettre en avant son code d’une manière ou d’une autre pour attirer davantage l’œil du développeur curieux et pressé de copier/coller le précieux sésame. &lt;/p&gt;

&lt;p&gt;Dans le cas de Channel 9, ils ont eu l’excellente idée de mettre le code dans des balises &amp;lt;pre&amp;gt;. Cela va donc nous faciliter la tâche pour styler les morceaux de code.&lt;/p&gt;

&lt;p&gt;Ajoutez une règle CSS « &lt;b&gt;#articlecontent pre&lt;/b&gt; »&lt;/p&gt;

&lt;p&gt;Passez en mode interactif et naviguez vers un article où l’on voit bien un morceau de code.&lt;/p&gt;

&lt;p&gt;Sélectionnez la règle fraichement créée et rendez-vous dans la section « &lt;b&gt;&lt;i&gt;Background&lt;/i&gt;&lt;/b&gt; » des propriétés CSS. Cliquez pour affecter une couleur :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7762.clip_5F00_image016_5F00_23BA7265.png"&gt;&lt;img title="clip_image016" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image016" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6278.clip_5F00_image016_5F00_thumb_5F00_383FC1E3.png" width="240" height="48" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Vous aurez alors cette merveilleuse palette pour faire votre choix :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7762.clip_5F00_image017_5F00_7CEEECD5.png"&gt;&lt;img title="clip_image017" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image017" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4532.clip_5F00_image017_5F00_thumb_5F00_00FBCB59.png" width="240" height="218" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mais si comme moi vous avez une tendance naturelle à vous diriger vers une couleur immonde, cliquez sur la petite pipette et choisissez une des couleurs de Blend. C’est forcément une bonne couleur vu que cela a été conçu par des personnes brillantes comme mon collègue Designer &lt;a href="http://blogs.msdn.com/b/designmichel/"&gt;Michel Rousseau&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Pour finir, sur les &amp;lt;pre&amp;gt;, mettez dans les champs « &lt;b&gt;overflow-x&lt;/b&gt; » la valeur « &lt;b&gt;auto&lt;/b&gt; » et « &lt;b&gt;overflow-y&lt;/b&gt; » la valeur « &lt;b&gt;hidden&lt;/b&gt; » comme tout à l’heure.&lt;/p&gt;

&lt;p&gt;Voici le résultat final que vous devriez obtenir :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8836.clip_5F00_image019_5F00_0912F7AE.jpg"&gt;&lt;img title="clip_image019" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image019" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0871.clip_5F00_image019_5F00_thumb_5F00_41C0326C.jpg" width="640" height="360" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="etape4"&gt;Etape 4 : vidéo et code source à télécharger&lt;/h2&gt;

&lt;p&gt;Voilà, je pense que je ne vous avais pas menti. Si vous étiez bien réveillé et concentré, vous avez dû passer environ 30 minutes pour fabriquer cette petite application. &lt;/p&gt;

&lt;p&gt;Voici la vidéo réalisant les étapes de ce 2&lt;sup&gt;ème&lt;/sup&gt; article :&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="SimpleChannel9ReaderPart2FR" class="video-js" height="360" width="640" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2FR.jpg"&gt;&lt;source src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2FR.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2FR.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="640" type="application/x-shockwave-flash" height="360"&gt;  
 &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  
 &lt;param name="allowfullscreen" value="true" /&gt;  
 &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2FR.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2FR.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  
 &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   
 &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2FR.jpg" width="512" height="288" /&gt;   
 &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt;&lt;a href="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2FR.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart2FR.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;Et voici le code source à télécharger : &lt;a title="http://david.blob.core.windows.net/win8/SimpleChannel9ReaderArticle2.zip" href="http://david.blob.core.windows.net/win8/SimpleChannel9ReaderArticle2.zip"&gt;Simple Channel9 Reader Article2&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Merci d’avoir suivi l’aventure. Si vous souhaitez aller plus loin, voici les articles que je vous recommande chaudement :&lt;/p&gt;

&lt;p&gt;- L’&lt;strong&gt;excellente série d’articles en français&lt;/strong&gt; de David Catuhe : &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/04/07/comment-cuisiner-une-application-windows-8-avec-html-5-css3-et-javascript-en-une-semaine-jour-0.aspx"&gt;Comment “cuisiner” une application Windows 8 avec HTML 5, CSS3 et JavaScript en une semaine&lt;/a&gt; . Ils vous feront découvrir comment réaliser une application qui supporte le « search », la vue « snapped » que nous n’avons pas vu ensemble, le framework de navigation de pages et pleins d’autres joyeusetés ! “&lt;em&gt;A must read&lt;/em&gt;” comme disent nos amis américains. 

  &lt;br /&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br211385.aspx"&gt;Create your first Metro style app using JavaScript&lt;/a&gt; dont le sujet tourne aussi autour de la récupération de données depuis des blogs en RSS et couvrant des sujets complémentaires à mes 2 articles.&lt;/p&gt;

&lt;p&gt;Je vous rappelle pour finir, pour ceux qui ne le savent pas encore, que nous avons un &lt;strong&gt;programme spécial pour vous aider à être les 1ers dans le Windows Store de Windows 8&lt;/strong&gt;. Ce programme s’appelle &lt;strong&gt;l’accélérateur&lt;/strong&gt; et vous pouvez vous inscrire ici: &lt;a href="http://bit.ly/accelerateurw8"&gt;http://bit.ly/accelerateurw8&lt;/a&gt; . Donc si vous vous sentez capable de développer une application rapidement, on peut vous aider à être parmi les 1ers dans notre Store ! Et qui sait, vous deviendrez peut-être riche grâce à nous. ;-)&lt;/p&gt;

&lt;p&gt;En tout cas, c’est tout le mal que je vous souhaite. Sur ce, bonnes vacances !&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10295918" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/CSS3/">CSS3</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Blend+5/">Blend 5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/WinJS/">WinJS</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Windows+8/">Windows 8</category></item><item><title>Comment créer un petit lecteur RSS pour Windows 8 Metro en HTML5 en 30 min (partie 1/2)</title><link>http://blogs.msdn.com/b/davrous/archive/2012/04/20/comment-cr-233-er-un-petit-lecteur-de-flux-rss-pour-windows-8-metro-en-html5-et-en-30-min-partie-1-2.aspx</link><pubDate>Fri, 20 Apr 2012 14:02:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10295795</guid><dc:creator>David Rousset</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10295795</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/04/20/comment-cr-233-er-un-petit-lecteur-de-flux-rss-pour-windows-8-metro-en-html5-et-en-30-min-partie-1-2.aspx#comments</comments><description>&lt;!-- Include the VideoJS Library --&gt;  &lt;p&gt;&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;&lt;/p&gt;  &lt;p&gt;Nous allons voir à travers ces 2 tutoriaux comment, en partant de zéro, réaliser un petit lecteur de flux RSS avec &lt;b&gt;HTML5, CSS3 et WinJS&lt;/b&gt;, le framework JavaScript de Microsoft pour Windows 8 Metro. Nous essaierons également de suivre au mieux les règles de design Metro en faisant appel à l’outil &lt;strong&gt;Expression Blend 5&lt;/strong&gt;. Si vous vous débrouillez bien, vous devriez pouvoir jouer ces 2 articles en 30 minutes.&lt;/p&gt;  &lt;p&gt;Ce 1er article vous permettra de créer la page d’accueil utilisant un contrôle de type liste affichant l’ensemble des derniers articles de blog publiés. Le 2ème s’occupera de créer la vue de détail affichée lorsque vous cliquerez sur l’un des éléments de la liste. Vous trouverez à la fin 2 petites vidéos déroulant les étapes que vous pouvez suivre en lisant cet article ainsi que le code source de solution. Voyez-les comme un complément pratique pour éventuellement éclaircir certaines zones d’ombres.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Prérequis :&lt;/u&gt;&lt;/strong&gt; pour pouvoir suivre ces tutoriaux, vous devez au préalable :&lt;/p&gt;  &lt;p&gt;1 – Avoir téléchargé et installé la version &lt;strong&gt;Consumer Preview de Windows 8&lt;/strong&gt; sur votre machine : &lt;a href="http://preview.windows.com/"&gt;http://preview.windows.com&lt;/a&gt;     &lt;br /&gt;2 – Avoir téléchargé et installé les outils&lt;strong&gt; Visual Studio 11 Express&lt;/strong&gt; pour Windows 8 : &lt;a title="http://msdn.microsoft.com/en-us/windows/apps/br229516" href="http://msdn.microsoft.com/en-us/windows/apps/br229516"&gt;http://msdn.microsoft.com/en-us/windows/apps/br229516&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/strong&gt; Si vous avez un Mac, Windows 8 s’installe très bien via BootCamp ou dans une machine virtuelle gérée par Parallels par exemple &lt;/p&gt;  &lt;p&gt;Au menu de cet 1er article :&lt;/p&gt;  &lt;p&gt;- Etape 1 : création du projet vide    &lt;br /&gt;- &lt;a href="#etape2"&gt;Etape 2 : création du squelette HTML et CSS de notre page principale&lt;/a&gt;     &lt;br /&gt;- &lt;a href="#etape3"&gt;Etape 3 : premier contact avec Blend&lt;/a&gt;     &lt;br /&gt;- &lt;a href="#etape4"&gt;Etape 4 : charger les données via XHR et les associer au contrôle ListView&lt;/a&gt;     &lt;br /&gt;- &lt;a href="#etape5"&gt;Etape 5 : mise en place d’un template et revue du design sous Blend&lt;/a&gt;     &lt;br /&gt;- &lt;a href="#etape6"&gt;Etape 6 : vidéos déroulant toutes les étapes précédentes&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;Etape 1 : création du projet vide &lt;/h2&gt;  &lt;p&gt;La première chose à faire est de lancer Visual Studio 11 et de créer un nouveau projet de type JavaScript Metro en faisant « &lt;em&gt;File&amp;#160; -&amp;gt;&amp;#160; New Project&lt;/em&gt; » :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1323.clip_5F00_image002_5F00_37E6D929.jpg"&gt;&lt;img title="clip_image002" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image002" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0763.clip_5F00_image002_5F00_thumb_5F00_2222122E.jpg" width="640" height="344" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Nommez-le « &lt;b&gt;SimpleChannel9Reader&lt;/b&gt; » car nous allons récupérer le flux RSS de la section Coding4Fun de Channel 9 disponible ici : &lt;a href="http://channel9.msdn.com/coding4fun/articles/RSS"&gt;http://channel9.msdn.com/coding4fun/articles/RSS&lt;/a&gt;&lt;/p&gt;  &lt;h2 id="etape2"&gt;Etape 2 : création du squelette HTML et CSS de notre page principale&lt;/h2&gt;  &lt;p&gt;Rendez-vous dans le fichier « &lt;em&gt;default.html&lt;/em&gt; » qui représente la page qui sera affichée au démarrage de notre application. A la place du morceau HTML suivant :&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;p&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Content goes here&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;p&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Insérez celui-là :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;main&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;header &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;banner&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;button &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;backbutton&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;win-backbutton&amp;quot;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;button&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;h1 &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;maintitle&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;win-title&amp;quot;&amp;gt;
            &lt;/span&gt;Welcome to Channel 9!&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;h1&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;section &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;content&amp;quot;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;section&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Nous avons un conteneur global avec l’id « &lt;em&gt;main&lt;/em&gt; » contenant 2 sous-conteneurs nommés « &lt;em&gt;banner&lt;/em&gt; » et « &lt;em&gt;content&lt;/em&gt; ». Le header sera affiché en haut de page et le contenu présent dans la section sera affiché juste en dessous.&lt;/p&gt;

&lt;p&gt;Ajoutons un peu de CSS à tout cela en nous rendant dans le fichier « &lt;em&gt;default.css&lt;/em&gt; » présent dans le répertoire « &lt;em&gt;css&lt;/em&gt; ». Vous verrez qu’il y a déjà un peu de CSS fournit par défaut pour vous indiquer les différentes vues disponibles dans une application Windows 8 gérées via des&lt;strong&gt; Media Queries&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Nous nous intéresserons dans ces 2 articles qu’à la vue plein écran donc l’état « &lt;em&gt;&lt;strong&gt;fullscreen-landscape&lt;/strong&gt;&lt;/em&gt; ». Insérez dans cette partie le CSS suivant :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#main
&lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
}

&lt;span style="color: maroon"&gt;#banner
&lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
}

&lt;span style="color: maroon"&gt;#backbutton
&lt;/span&gt;{
}

&lt;span style="color: maroon"&gt;#maintitle
&lt;/span&gt;{
}

&lt;span style="color: maroon"&gt;#content
&lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Indiquant tout simplement que l’on souhaite prendre l’ensemble de la taille disponible pour nos 3 conteneurs principaux. &lt;/p&gt;

&lt;p&gt;Exécutez votre application en appuyant sur la touche F5 ou en cliquant sur la touche suivante :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7674.clip_5F00_image003_5F00_39DE6AF6.png"&gt;&lt;img title="clip_image003" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image003" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4370.clip_5F00_image003_5F00_thumb_5F00_09B72033.png" width="127" height="23" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Logiquement, vous devriez avoir quelque chose comme :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8267.clip_5F00_image005_5F00_4BBD8F74.jpg"&gt;&lt;img title="clip_image005" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image005" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7181.clip_5F00_image005_5F00_thumb_5F00_5FD6ABFD.jpg" width="240" height="136" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On voit ici un problème évident de design : le bouton de retour et le texte ne sont pas du tout alignés. Résolvons cela à l’aide de Blend 5.&lt;/p&gt;

&lt;h2 id="etape3"&gt;Etape 3 : premier contact avec Blend&lt;/h2&gt;

&lt;p&gt;Lancez Blend et allez chercher votre projet SimpleChannel9Reader sur votre système de fichiers pour obtenir cela :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0160.clip_5F00_image007_5F00_73EFC886.jpg"&gt;&lt;img title="clip_image007" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image007" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3806.clip_5F00_image007_5F00_thumb_5F00_1335000B.jpg" width="640" height="341" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;L’idée ici est de créer 2 grilles. Une 1&lt;sup&gt;ère&lt;/sup&gt; qui va contenir 1 colonne sur toute la largeur et 2 lignes pour le conteneur global et une 2&lt;sup&gt;ème&lt;/sup&gt; qui va contenir 1 ligne et 2 colonnes pour le bouton back et le titre.&lt;/p&gt;

&lt;p&gt;Commençons par sélectionner dans la section «&lt;strong&gt;&lt;em&gt; Live DOM&lt;/em&gt;&lt;/strong&gt; » l’élément « &lt;em&gt;main&lt;/em&gt; » :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5050.clip_5F00_image008_5F00_54D1CD08.png"&gt;&lt;img title="clip_image008" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image008" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1323.clip_5F00_image008_5F00_thumb_5F00_243E4F50.png" width="240" height="104" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Rendez-vous dans la partie « &lt;strong&gt;&lt;em&gt;Layout&lt;/em&gt;&lt;/strong&gt; » et basculez le display en « &lt;strong&gt;&lt;em&gt;-ms-grid&lt;/em&gt;&lt;/strong&gt; » :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2804.clip_5F00_image009_5F00_0F4F5D8E.png"&gt;&lt;img title="clip_image009" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image009" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7585.clip_5F00_image009_5F00_thumb_5F00_50E999DA.png" width="240" height="185" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nous allons utiliser ici la spécification&lt;strong&gt; CSS Grid Layout&lt;/strong&gt; actuellement uniquement supportée par IE10 mais arrivant bientôt dans les autres navigateurs. Si vous souhaitez en savoir davantage sur le type de layout supporté en mode Metro, vous pouvez lire cet article : &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465327.aspx"&gt;Choosing a CSS3 layout for your app&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Si vous souhaitez simplement en savoir davantage sur CSS3 Grid, n’hésitez pas à lire l’article de Raphael Goetter d’Alsacréations ici : &lt;a href="http://www.alsacreations.com/article/lire/1388-css3-grid-layout.html"&gt;CSS3 Grid Layout&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Maintenant que nous avons basculé le mode d’affichage en grille, il faut définir la structure de la grille. Pour cela, rendez-vous naturellement dans la partie « &lt;strong&gt;&lt;em&gt;Grid&lt;/em&gt;&lt;/strong&gt; » et déclarer la grille suivante :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0741.clip_5F00_image010_5F00_697BC7DB.png"&gt;&lt;img title="clip_image010" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image010" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8255.clip_5F00_image010_5F00_thumb_5F00_128666D8.png" width="240" height="63" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nous aurons donc 1 seule colonne qui prendra toute la largeur de l’écran disponible (quelle que soit la résolution) et 2 lignes. La 1&lt;sup&gt;ère&lt;/sup&gt; ligne aura une taille en « dur » de 132px de haut et la suivante prendra tout le reste de l’espace disponible. Cela est alors reflété dans le designer de Blend :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7266.clip_5F00_image012_5F00_6FC52F1A.jpg"&gt;&lt;img title="clip_image012" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image012" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0333.clip_5F00_image012_5F00_thumb_5F00_1CDCAC9A.jpg" width="640" height="395" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Maintenant, nous allons placer l’élément « &lt;strong&gt;&lt;em&gt;content&lt;/em&gt;&lt;/strong&gt; » dans la 2&lt;sup&gt;ème&lt;/sup&gt; ligne. Sélectionnez-le dans le « &lt;strong&gt;&lt;em&gt;Live DOM&lt;/em&gt;&lt;/strong&gt; » et rendez-vous dans sa partie « &lt;strong&gt;&lt;em&gt;Grid&lt;/em&gt;&lt;/strong&gt; ». Mettez la propriété&lt;strong&gt; –ms-grid-row à 2&lt;/strong&gt;. Vous pouvez éventuellement positionner l’élément « &lt;strong&gt;&lt;em&gt;banner&lt;/em&gt;&lt;/strong&gt; » à la ligne 1 mais sinon cela est fait par défaut si vous ne précisez rien.&lt;/p&gt;

&lt;p&gt;Nous allons maintenant découper notre 1&lt;sup&gt;ère&lt;/sup&gt; ligne en 2 colonnes de manières à mettre les choses à leur place. Sélectionnez l’élément « &lt;strong&gt;&lt;em&gt;banner&lt;/em&gt;&lt;/strong&gt; » et basculer son display en «&lt;em&gt; -ms-grid&lt;/em&gt; » puis définissez 1 ligne en 1fr et 2 colonnes de 120px et 1fr :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2388.clip_5F00_image013_5F00_42D4EDA1.png"&gt;&lt;img title="clip_image013" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image013" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6507.clip_5F00_image013_5F00_thumb_5F00_5DA113AD.png" width="224" height="70" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Placez l’élément « &lt;strong&gt;&lt;em&gt;maintitle&lt;/em&gt;&lt;/strong&gt; » en colonne 2 et centrez le verticalement grâce à la propriété « &lt;strong&gt;&lt;em&gt;-ms-grid-row-align&lt;/em&gt;&lt;/strong&gt; » à « &lt;strong&gt;&lt;em&gt;center&lt;/em&gt;&lt;/strong&gt; » :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4861.clip_5F00_image014_5F00_342CD26D.png"&gt;&lt;img title="clip_image014" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image014" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6505.clip_5F00_image014_5F00_thumb_5F00_040587AA.png" width="240" height="187" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sélectionnez l’élément « &lt;strong&gt;&lt;em&gt;backbutton&lt;/em&gt;&lt;/strong&gt; » et dans sa partie « &lt;strong&gt;&lt;em&gt;Layout&lt;/em&gt;&lt;/strong&gt; », mettez &lt;strong&gt;54px&lt;/strong&gt; de marge en haut et &lt;strong&gt;40px&lt;/strong&gt; de marge vers la gauche. Si vous ne vous êtes pas planté, vous devriez avoir maintenant cela sur la surface de design :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7585.clip_5F00_image016_5F00_23B6F223.jpg"&gt;&lt;img title="clip_image016" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image016" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3343.clip_5F00_image016_5F00_thumb_5F00_1C2E1367.jpg" width="240" height="144" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sauvegardez l’ensemble via “&lt;em&gt;File -&amp;gt; Save All&lt;/em&gt;” puis retournez sous Visual Studio. Rendez-vous dans « &lt;em&gt;default.css&lt;/em&gt; » et vous observerez que Blend a généré du CSS « propre » :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@media &lt;/span&gt;screen and (-ms-view-state: fullscreen-landscape)
{

    &lt;span style="color: maroon"&gt;#main
    &lt;/span&gt;{
        &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
        &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
        &lt;span style="color: red"&gt;display&lt;/span&gt;: &lt;span style="color: blue"&gt;-ms-grid&lt;/span&gt;;
        &lt;span style="color: red"&gt;-ms-grid-columns&lt;/span&gt;: &lt;span style="color: blue"&gt;1fr&lt;/span&gt;;
        &lt;span style="color: red"&gt;-ms-grid-rows&lt;/span&gt;: &lt;span style="color: blue"&gt;132px 1fr&lt;/span&gt;;
    }

    &lt;span style="color: maroon"&gt;#banner
    &lt;/span&gt;{
        &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
        &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
        &lt;span style="color: red"&gt;display&lt;/span&gt;: &lt;span style="color: blue"&gt;-ms-grid&lt;/span&gt;;
        &lt;span style="color: red"&gt;-ms-grid-columns&lt;/span&gt;: &lt;span style="color: blue"&gt;120px 1fr&lt;/span&gt;;
        &lt;span style="color: red"&gt;-ms-grid-rows&lt;/span&gt;: &lt;span style="color: blue"&gt;1fr&lt;/span&gt;;
    }

    &lt;span style="color: maroon"&gt;#backbutton
    &lt;/span&gt;{
        &lt;span style="color: red"&gt;margin-top&lt;/span&gt;: &lt;span style="color: blue"&gt;54px&lt;/span&gt;;
        &lt;span style="color: red"&gt;margin-left&lt;/span&gt;: &lt;span style="color: blue"&gt;40px&lt;/span&gt;;
    }

    &lt;span style="color: maroon"&gt;#maintitle
    &lt;/span&gt;{
        &lt;span style="color: red"&gt;-ms-grid-column&lt;/span&gt;: &lt;span style="color: blue"&gt;2&lt;/span&gt;;
        &lt;span style="color: red"&gt;-ms-grid-row-align&lt;/span&gt;: &lt;span style="color: blue"&gt;center&lt;/span&gt;;
    }

    &lt;span style="color: maroon"&gt;#content
    &lt;/span&gt;{
        &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
        &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
        &lt;span style="color: red"&gt;-ms-grid-row&lt;/span&gt;: &lt;span style="color: blue"&gt;2&lt;/span&gt;;
    }
}&lt;/pre&gt;

&lt;p&gt;Vérifiez que l’application fonctionne bien en faisant F5.&lt;/p&gt;

&lt;h2 id="etape4"&gt;Etape 4 : charger les données via XHR et les associer au contrôle ListView&lt;/h2&gt;

&lt;p&gt;Bon pour l’instant, vous vous dîtes que c’est bien gentil mais que vous aimeriez rentrer dans le vif du sujet. &lt;/p&gt;

&lt;p&gt;La 1&lt;sup&gt;ère&lt;/sup&gt; chose à faire est d’insérer un contrôle qui va être chargé d’afficher de petites vignettes sur la page d’accueil contenant les images des articles de blogs qui vont être remontés. Pour cela, nous allons utiliser WinJS.&lt;/p&gt;

&lt;p&gt;La librairie WinJS ou “&lt;strong&gt;Microsoft Windows Library for JavaScript SDK&lt;/strong&gt;” est un framework conçu pour aider les développeurs JavaScript à intégrer plus simplement l’expérience Windows 8 Metro. Elle fournit ainsi un ensemble de contrôles Metro, un moteur de templating, un moteur de binding, une gestion de l’asynchronisme via l’implémentation du Promise, des helpers pour gérer des Namespaces, etc.&lt;/p&gt;

&lt;p&gt;Par exemple, si vous souhaitez en savoir davantage sur la partie contrôles, rendez-vous ici : &lt;a title="http://msdn.microsoft.com/en-us/library/windows/apps/hh465493" href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465493"&gt;Quickstart: adding WinJS controls and styles&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dans les projets Windows 8 Metro, vous retrouverez cette librairie&amp;#160; dans les références du projet dans le “&lt;strong&gt;&lt;em&gt;Solution Explorer&lt;/em&gt;&lt;/strong&gt;” :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8461.image_5F00_1E6A2512.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4251.image_5F00_thumb_5F00_5B8DE097.png" width="240" height="184" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Vous y retrouverez donc les feuilles de styles par défaut avec les 2 thèmes &lt;em&gt;dark&lt;/em&gt; et &lt;em&gt;light&lt;/em&gt; fournis ainsi que le code JavaScript. N’hésitez pas à aller y jeter un œil pour voir comment nous avons fabriqué l’ensemble. Cela peut toujours être utile en complément de la documentation MSDN.&lt;/p&gt;

&lt;p&gt;Dans notre cas, nous allons utilisé le contrôle &lt;em&gt;ListView&lt;/em&gt; qui utilise une structure en grille pour afficher une liste d’éléments.&lt;/p&gt;

&lt;p&gt;Pour cela, rendez-vous dans le fichier « &lt;strong&gt;&lt;em&gt;default.html&lt;/em&gt;&lt;/strong&gt; » et dans la partie section, tapez ce morceau d’HTML :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;articlelist&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;data-win-control&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;WinJS.UI.ListView&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Pour l’instant, cela n’est qu’un « bête » div comme un autre. Par contre, il est marqué d’un attribut &lt;strong&gt;data-win-control&lt;/strong&gt; qui indique que l’on souhaite utiliser la librairie &lt;strong&gt;WinJS&lt;/strong&gt; pour transformer ce div en contrôle de type &lt;strong&gt;ListView&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;La magie ne s’opère uniquement que grâce à une ligne de JavaScript particulière que l’on retrouve dans « &lt;em&gt;default.js&lt;/em&gt; » et se trouve être celle-ci :&lt;/p&gt;

&lt;pre class="code"&gt;WinJS.UI.processAll();&lt;/pre&gt;

&lt;p&gt;Cette opération, traitée de manière asynchrone, s’occupe de parcourir tout le DOM à la recherche de div marqués des attributs &lt;em&gt;data-win-control&lt;/em&gt; pour les transformer en réel contrôle WinJS implémentant l’expérience Metro. Si vous supprimez par mégarde cette ligne, vous rendrez à nouveau « bête » tous vos div. &lt;/p&gt;

&lt;p&gt;Ok, maintenant il faut l’alimenter en données cette &lt;em&gt;ListView&lt;/em&gt;. Pour cela, dans la fonction associée à l’évènement « &lt;strong&gt;&lt;em&gt;onactivated&lt;/em&gt;&lt;/strong&gt; », ajoutez ce code au-dessus de la ligne &lt;strong&gt;processAll()&lt;/strong&gt; :&lt;/p&gt;

&lt;pre class="code"&gt;articlesList = &lt;span style="color: blue"&gt;new &lt;/span&gt;WinJS.Binding.List();
&lt;span style="color: blue"&gt;var &lt;/span&gt;publicMembers = { ItemList: articlesList };
WinJS.Namespace.define(&lt;span style="color: maroon"&gt;&amp;quot;C9Data&amp;quot;&lt;/span&gt;, publicMembers);&lt;/pre&gt;

&lt;p&gt;Du coup, déclarez en haut de la fonction la variable « &lt;em&gt;articlesList&lt;/em&gt; », juste en dessous de la variable « &lt;em&gt;app&lt;/em&gt; » par exemple.&lt;/p&gt;

&lt;p&gt;Nous déclarons ici un type&lt;strong&gt;&lt;em&gt; Binding.List()&lt;/em&gt;&lt;/strong&gt; à utiliser pour binder des données aux contrôles WinJS. Ce type a le bon goût de disposer de méthodes qui vous permettront d’ajouter des données au fil de l’eau et de laisser la magie du binding s’opérer pour rafraîchir la vue associée. &lt;/p&gt;

&lt;p&gt;Par ailleurs, comme nous codons proprement en JavaScript, nous utilisons le « &lt;strong&gt;&lt;em&gt;module pattern&lt;/em&gt;&lt;/strong&gt; » avec une fonction JS anonyme auto-exécutée dans « &lt;em&gt;default.js&lt;/em&gt; ». Il nous donc un moyen d’exposer des données publiques vers l’extérieur. Pour cela, nous utilisons le concept de &lt;strong&gt;Namespace&lt;/strong&gt; avec un helper issu de WinJS nous permettant de facilement définir ce que nous souhaitons exposer. Dans le cas ci-dessus, nous aurons donc un objet nommé « &lt;strong&gt;&lt;em&gt;C9Data&lt;/em&gt;&lt;/strong&gt; » qui sera visible avec une propriété « &lt;strong&gt;&lt;em&gt;ItemList&lt;/em&gt;&lt;/strong&gt; » contenant nos futurs éléments à afficher.&lt;/p&gt;

&lt;p&gt;Il nous faut maintenant une fonction pour aller chercher les données du flux RSS, les analyser, créer des objets JS à la volée et les pousser dans cette fameuse liste de binding. Voici la fonction que je vous propose pour cela :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;downloadC9BlogFeed() {
    WinJS.xhr({ url: &lt;span style="color: maroon"&gt;&amp;quot;http://channel9.msdn.com/coding4fun/articles/RSS&amp;quot; &lt;/span&gt;}).then(&lt;span style="color: blue"&gt;function &lt;/span&gt;(rss) {

    });
}&lt;/pre&gt;

&lt;p&gt;Ce code effectue une requête &lt;strong&gt;XmlHttpRequest&lt;/strong&gt; vers l’url spécifiée de manière asynchrone. Le code indiqué dans la &lt;strong&gt;Promise&lt;/strong&gt; (via le .then()) sera donc exécuté uniquement qu’une fois que la requête aura reçu les données. C’est à ce moment-là que l’on peut les filtrer via ce code à insérer dans la fonction anonyme :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;items = rss.responseXML.selectNodes(&lt;span style="color: maroon"&gt;&amp;quot;//item&amp;quot;&lt;/span&gt;);

&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;n = 0; n &amp;lt; items.length; n++) {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;article = {};
    article.title = items[n].selectSingleNode(&lt;span style="color: maroon"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;).text;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;thumbs = items[n].selectNodes(&lt;span style="color: maroon"&gt;&amp;quot;media:thumbnail&amp;quot;&lt;/span&gt;);
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(thumbs.length &amp;gt; 1) {
        article.thumbnail = thumbs[1].attributes.getNamedItem(&lt;span style="color: maroon"&gt;&amp;quot;url&amp;quot;&lt;/span&gt;).text;
        article.content = items[n].text;
        articlesList.push(article);
    }
}&lt;/pre&gt;

&lt;p&gt;Ce code est je pense auto-explicite. Il sélectionne les nœuds « &lt;em&gt;item&lt;/em&gt; » et récupère les propriétés qui l’intéressent pour les mapper sur un objet « &lt;em&gt;article&lt;/em&gt; » instancié à la volée sur ses propriétés « &lt;em&gt;title&lt;/em&gt; », « &lt;em&gt;thumbs&lt;/em&gt; » &amp;amp; « &lt;em&gt;content&lt;/em&gt; ». Notez bien le nom de ces propriétés, on les retrouvera plus tard. Le code finit par ajouter ce nouvel objet à la collection de binding.&lt;/p&gt;

&lt;p&gt;Il faut maintenant indiquer que l’on souhaite exécuter le code au démarrage de l’application. Nous allons le faire une fois que l’analyse du DOM aura été faite pour fabriquer les contrôles WinJS. Du coup, utilisez cette ligne de code :&lt;/p&gt;

&lt;pre class="code"&gt;WinJS.UI.processAll().then(downloadC9BlogFeed);&lt;/pre&gt;

&lt;p&gt;Il ne reste plus qu’une chose à faire : c’est d’indiquer au contrôle quelle est sa source de données. Pour cela, rendez-vous dans le HTML et modifiez le div associé à la ListView pour changer ses options. Vous obtiendrez alors cela :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;articlelist&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;data-win-control&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;WinJS.UI.ListView&amp;quot;
    &lt;/span&gt;&lt;span style="color: red"&gt;data-win-options&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{ itemDataSource: C9Data.ItemList.dataSource }&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Pour finir, il faut indiquer un minimum la manière dont on souhaite afficher notre contrôle. Pour cela, rendez-vous bien sûr dans « &lt;em&gt;default.css&lt;/em&gt; » et ajoutez ces 2 règles :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#articlelist
&lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
}

&lt;span style="color: maroon"&gt;#articlelist .win-item
&lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;150px&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;150px&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;On indique que notre contrôle ListView devra prendre toute la place disponible et que chacun de ses éléments (via la classe &lt;strong&gt;.win-item&lt;/strong&gt;) devront faire 150 par 150 pixels.&lt;/p&gt;

&lt;p&gt;Exécutez l’ensemble en faisant F5. Vous devriez avoir quelque chose d’aussi moche que cela :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4540.clip_5F00_image018_5F00_5DC84FB3.jpg"&gt;&lt;img title="clip_image018" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image018" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8540.clip_5F00_image018_5F00_thumb_5F00_10BD017D.jpg" width="640" height="360" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;C’est normal, ne vous inquiétez pas ! &lt;img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4540.wlEmoticon_2D00_smile_5F00_5DEBF451.png" /&gt; &lt;/p&gt;

&lt;p&gt;Bon, il nous reste encore un peu de boulot. Mais on peut déjà voir que le binding fonctionne et que le contrôle fonctionne bien à la souris et au touch. Par ailleurs, le contrôle s’adapte déjà à la résolution actuelle de votre écran. Vous n’aurez donc pas forcément la même disposition que la copie d’écran précédente. &lt;/p&gt;

&lt;h2 id="etape5"&gt;Etape 5 : mise en place d’un template et revue du design sous Blend&lt;/h2&gt;

&lt;p&gt;Il faut maintenant préciser au contrôle la manière de dessiner chacun de ses éléments. Cela se fait via un mécanisme dit de templating. Un template n’est à nouveau qu’un morceau de HTML décoré par les attributs WinJS. &lt;/p&gt;

&lt;p&gt;Rendez-vous dans « &lt;em&gt;default.html&lt;/em&gt; » et ajoutez ce morceau d’HTML tout en haut juste au-dessus du « &lt;em&gt;main&lt;/em&gt; » :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;C9ItemTemplate&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;data-win-control&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;WinJS.Binding.Template&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;style&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color: red"&gt;display&lt;/span&gt;&lt;span style="color: blue"&gt;: none;&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;listItemTemplate&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;listItemImage&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;img &lt;/span&gt;&lt;span style="color: red"&gt;data-win-bind&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;src: thumbnail&amp;quot; /&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;listItemTitle&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;data-win-bind&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;innerText: title&amp;quot;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;On voit bien que c’est un template car il est décoré de la valeur « &lt;strong&gt;&lt;em&gt;WinJS.Binding.Template&lt;/em&gt;&lt;/strong&gt; » ce qui permettra à WinJS de savoir quoi en faire suite à l’exécution du &lt;strong&gt;processAll()&lt;/strong&gt;. Ensuite, le reste n’est que du HTML standard avec malgré tout une autre particularité : les expressions de binding. Pour savoir comment mapper les propriétés des objets JS actuellement en mémoire aux contrôles HTML, on passe par l’attribut « &lt;strong&gt;&lt;em&gt;data-win-bind&lt;/em&gt;&lt;/strong&gt; » puis on précise une expression de binding de la manière suivante : «&lt;em&gt; nom_de_l’attribut_html : nom_de_la_propriété_objet_JS&lt;/em&gt; ».&lt;/p&gt;

&lt;p&gt;Il nous faut maintenant dire au contrôle WinJS de ne plus de dessiner avec son template par défaut mais avec celui que nous venons juste de définir en changeant simplement ses options :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;articlelist&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;data-win-control&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;WinJS.UI.ListView&amp;quot;
    &lt;/span&gt;&lt;span style="color: red"&gt;data-win-options&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{ itemDataSource: C9Data.ItemList.dataSource, itemTemplate: C9ItemTemplate }&amp;quot;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Si vous exécutez pour voir le résultat à ce moment, vous devriez avoir cela :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4846.clip_5F00_image020_5F00_6A7FC986.jpg"&gt;&lt;img title="clip_image020" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image020" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2055.clip_5F00_image020_5F00_thumb_5F00_69405209.jpg" width="640" height="360" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;C’est mieux mais ce n’est pas encore cela. Il va falloir revoir le design sous Blend.&lt;/p&gt;

&lt;p&gt;Bah allez, c’est parti. Retournez sous Blend qui va vous demander de recharger les fichiers suite aux modifications que vous avez effectuées sous Visual Studio pour obtenir cela :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3823.clip_5F00_image022_5F00_12D93E9F.jpg"&gt;&lt;img title="clip_image022" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image022" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5001.clip_5F00_image022_5F00_thumb_5F00_01F72B60.jpg" width="640" height="341" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Rien ne vous choque ? On voit ici le même résultat que si vous faîtes F5 depuis Visual Studio. Cela signifie que &lt;strong&gt;Blend 5 exécute en « live » votre application&lt;/strong&gt; au sein du designer ! En voilà une bonne nouvelle.&lt;/p&gt;

&lt;p&gt;Du coup, on va pouvoir travailler sur le vrai jeu de données finales sans être obligé de faire ce que l’on appelle communément du « &lt;em&gt;mocking&lt;/em&gt; ». C’est un des avantages de JavaScript et de son côté interprété et dynamique. Blend a exécuté le code qui fait la requête XHR et construit les objets WinJS.&lt;/p&gt;

&lt;p&gt;Sous « &lt;em&gt;default.css&lt;/em&gt; », on va commencer par ajouter 2 règles CSS. Pour cela, cliquer sur le bouton + sur la media query principale :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5001.clip_5F00_image023_5F00_059A679F.png"&gt;&lt;img title="clip_image023" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image023" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6558.clip_5F00_image023_5F00_thumb_5F00_34EBDD29.png" width="240" height="212" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Et ajoutez les sélecteurs suivants :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;.listItemTemplate&lt;/em&gt;&lt;/strong&gt; et&lt;strong&gt;&lt;em&gt; .listItemTemplate img&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sélectionnez la règle &lt;strong&gt;&lt;em&gt;#articlelist .win-item&lt;/em&gt;&lt;/strong&gt; qui sélectionne chacun des éléments de la ListView disposant de l’ID « &lt;em&gt;articlelist&lt;/em&gt; ». &lt;/p&gt;

&lt;p&gt;Changez la taille de ces éléments pour les faire passer de 150px par 150px à &lt;strong&gt;250px par 250px&lt;/strong&gt; en vous rendant dans la partie « &lt;strong&gt;&lt;em&gt;Sizing&lt;/em&gt;&lt;/strong&gt; » sur le panneau de droite.&lt;/p&gt;

&lt;p&gt;Il faut ensuite forcer un rafraichissement de la zone de design en cliquant sur le bouton adéquat :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6175.clip_5F00_image024_5F00_0FF0AD61.png"&gt;&lt;img title="clip_image024" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image024" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0218.clip_5F00_image024_5F00_thumb_5F00_31DC0FE5.png" width="89" height="30" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Et voici le résultat :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4503.clip_5F00_image026_5F00_73E27F26.jpg"&gt;&lt;img title="clip_image026" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image026" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8132.clip_5F00_image026_5F00_thumb_5F00_492C35B8.jpg" width="640" height="391" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On va redimensionner les images du template. Pour cela, sélectionnez le pointeur « &lt;strong&gt;&lt;em&gt;Direction Selection&lt;/em&gt;&lt;/strong&gt; » et cliquez sur une des images :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3581.clip_5F00_image028_5F00_1588EABC.jpg"&gt;&lt;img title="clip_image028" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image028" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5164.clip_5F00_image028_5F00_thumb_5F00_641F97CA.jpg" width="640" height="226" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Vous pouvez alors voir la liste des règles actuellement appliquées dans la section « &lt;strong&gt;&lt;em&gt;Applied Rules&lt;/em&gt;&lt;/strong&gt; ». Cliquez sur « &lt;strong&gt;&lt;em&gt;.listItemTemplate img&lt;/em&gt;&lt;/strong&gt; » puis redimensionnez à la souris l’image que vous aviez à l’origine sélectionnée. Vous voyez alors que toutes les autres images répondant au même sélecteur sont naturellement impactées en temps réel.&lt;/p&gt;

&lt;p&gt;Finalement, rendez-vous dans la section « &lt;strong&gt;&lt;em&gt;Sizing&lt;/em&gt;&lt;/strong&gt; » et fixez la taille suivante : &lt;strong&gt;234px de large&lt;/strong&gt; par &lt;strong&gt;165px de haut&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Pour améliorer un peu plus le design, il nous reste à aérer un peu l’espace entre les éléments et aligner correctement notre ListView avec le titre.&lt;/p&gt;

&lt;p&gt;Cliquez sur le sélecteur « &lt;strong&gt;&lt;em&gt;.listItemTemplate&lt;/em&gt;&lt;/strong&gt; » puis dans la section « &lt;strong&gt;&lt;em&gt;Layout&lt;/em&gt;&lt;/strong&gt; », commencez par cliquez sur l’icône « &lt;strong&gt;&lt;em&gt;Lock&lt;/em&gt;&lt;/strong&gt; » tout à droite de la zone « &lt;strong&gt;&lt;em&gt;Margin&lt;/em&gt;&lt;/strong&gt; ». Prenez ensuite n’importe quelle marge et entrez &lt;strong&gt;8px&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Pour finir, pour décaler la grille de la ListView et l’aligner avec le titre, il faut la bouger de 120px – 8px de marge des éléments que l’on vient de mettre en place.&lt;/p&gt;

&lt;p&gt;Ajoutez donc un nouveau sélecteur en cliquant sur + et nommez le « &lt;strong&gt;&lt;em&gt;.win-surface&lt;/em&gt;&lt;/strong&gt; » puis mettez une marge à gauche de &lt;strong&gt;112px&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Revenez sous Visual Studio, acceptez les changements puis faîtes F5. Voici ce que vous devriez désormais obtenir :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3581.clip_5F00_image030_5F00_6EE21081.jpg"&gt;&lt;img title="clip_image030" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image030" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3326.clip_5F00_image030_5F00_thumb_5F00_0B14EA11.jpg" width="640" height="360" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="etape6"&gt;Etape 6 : vidéos déroulant toutes les étapes précédentes&lt;/h2&gt;

&lt;p&gt;Voici 2 petites vidéos vous montrant comment suivre toutes les étapes décrites précédemment. &lt;/p&gt;

&lt;p&gt;La 1ère correspond aux &lt;strong&gt;étapes 1, 2 et 3&lt;/strong&gt; :&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="SimpleChannel9ReaderPart1AFR" class="video-js" poster="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1AFR.jpg" preload="preload" controls="controls" width="640" height="360"&gt;&lt;source type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1AFR.mp4" /&gt;&lt;source type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1AFR.webm" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="640" type="application/x-shockwave-flash" height="360"&gt;  
 &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  
 &lt;param name="allowfullscreen" value="true" /&gt;  
 &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1AFR.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1AFR.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  
 &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   
 &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1AFR.jpg" width="512" height="288" /&gt;   
 &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt;&lt;a href="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1AFR.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1AFR.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;La 2ème correspond aux&lt;strong&gt; étapes 4 et 5 &lt;/strong&gt;:&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="SimpleChannel9ReaderPart1BFR" class="video-js" poster="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1BFR.jpg" preload="preload" controls="controls" width="640" height="360"&gt;&lt;source type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1BFR.mp4" /&gt;&lt;source type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1BFR.webm" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="640" type="application/x-shockwave-flash" height="360"&gt;  
 &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  
 &lt;param name="allowfullscreen" value="true" /&gt;  
 &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1BFR.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1BFR.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  
 &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   
 &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1BFR.jpg" width="512" height="288" /&gt;   
 &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt;&lt;a href="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1BFR.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/SimpleChannel9ReaderPart1BFR.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;Vous pouvez télécharger le code source de la solution associée à ce 1er article ici : &lt;a title="http://david.blob.core.windows.net/win8/SimpleChannel9ReaderArticle1.zip" href="http://david.blob.core.windows.net/win8/SimpleChannel9ReaderArticle1.zip"&gt;Simple Channel9 Reader Article1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voilà, on a déjà bien avancé. Il nous reste maintenant à afficher le détail de l’article, à continuer de découvrir la puissance de l’outil Blend ainsi que de nouvelles choses apportées par CSS3.&lt;/p&gt;

&lt;p&gt;Rendez-vous dans &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/04/20/comment-cr-233-er-un-petit-lecteur-de-flux-rss-pour-windows-8-metro-en-html5-et-en-30-min-partie-2-2.aspx"&gt;le second article&lt;/a&gt; pour cela !&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10295795" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Metro/">Metro</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Blend+5/">Blend 5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/WinJS/">WinJS</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Windows+8/">Windows 8</category></item><item><title>Modernisez vos jeux HTML5 canvas partie 2: Offline API, Drag’n’drop &amp; File API</title><link>http://blogs.msdn.com/b/davrous/archive/2012/04/18/modernisez-vos-jeux-html5-canvas-partie-2-offline-api-drag-n-drop-amp-file-api.aspx</link><pubDate>Wed, 18 Apr 2012 07:27:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10294848</guid><dc:creator>David Rousset</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10294848</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/04/18/modernisez-vos-jeux-html5-canvas-partie-2-offline-api-drag-n-drop-amp-file-api.aspx#comments</comments><description>&lt;!-- Include the VideoJS Library --&gt;&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;  &lt;p&gt;Nous avons vu dans l’article précédent &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/04/10/modernisez-vos-jeux-html5-canvas-partie-1-mise-224-l-233-chelle-mat-233-rielle-amp-css3.aspx"&gt;Modernisez vos jeux HTML5 canvas partie 1: mise à l’échelle matérielle &amp;amp; CSS3&lt;/a&gt; comment utiliser CSS3 3D Transform, les transitions &amp;amp; Grid Layout pour améliorer un jeu de plateforme HTML5. Nous allons maintenant voir comment utiliser &lt;strong&gt;Offline API, Drag’n’drop et File API&lt;/strong&gt; pour mettre en place de nouvelles idées que j’ai eu pendant que je développais mon jeu.&lt;/p&gt;  &lt;p&gt;Si vous n’avez pas lu le &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/04/10/modernisez-vos-jeux-html5-canvas-partie-1-mise-224-l-233-chelle-mat-233-rielle-amp-css3.aspx"&gt;premier article&lt;/a&gt;, laissez moi vous rappelez quels étaient mes objectifs. Je souhaitais voir comment jouer avec les dernières spécifications pour moderniser mon jeu HTML5 nommé &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/03/21/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx"&gt;HTML5 Platformer&lt;/a&gt;. Voici ce qui nous attend au menu de ce 2ème article.&lt;/p&gt;  &lt;h2&gt;Agenda&lt;/h2&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;&lt;font color="#0691d6"&gt;Rendre le jeu jouable en mode déconnecté&lt;/font&gt;&lt;/strong&gt;&amp;#160; &lt;ul&gt;       &lt;li&gt;&lt;font color="#95b9ea"&gt;&lt;strong&gt;Etape 1&lt;/strong&gt;: choisir les ressources que vous souhaitez &lt;strong&gt;mettre en cache&lt;/strong&gt; &lt;/font&gt;&lt;/li&gt;        &lt;li&gt;&lt;font color="#95b9ea"&gt;&lt;strong&gt;Etape 2&lt;/strong&gt;: modifier la &lt;strong&gt;logique du jeu&lt;/strong&gt; pour le chargement des niveaux &lt;/font&gt;&lt;/li&gt;        &lt;li&gt;&lt;font color="#95b9ea"&gt;&lt;strong&gt;Etape 3&lt;/strong&gt;: vérifier le statut &lt;strong&gt;en ligne/hors ligne&lt;/strong&gt; &amp;amp; afficher un logo en mode déconnecté&lt;/font&gt; &lt;/li&gt;        &lt;li&gt;&lt;font color="#95b9ea"&gt;&lt;strong&gt;Etape 4&lt;/strong&gt;: chargement conditionnel des fichiers mp3 ou ogg et stockage en &lt;strong&gt;blob dans IndexedDB&lt;/strong&gt;&lt;/font&gt;&lt;strong&gt; &lt;/strong&gt;&lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;font color="#0691d6"&gt;Glisser/Déposer des niveaux depuis votre bureau&lt;/font&gt;&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;font color="#0691d6"&gt;Vidéo, URL pour jouer avec la démo &amp;amp; code source à télécharger&lt;/font&gt;&lt;/strong&gt;&amp;#160; &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Rendre le jeu jouable en mode déconnecté&lt;/h2&gt;  &lt;p&gt;La &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/03/21/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx"&gt;version initiale&lt;/a&gt; du jeu ne fonctionne uniquement que si votre périphérique dispose d’un accès à Internet. Ainsi, imaginons qu’il vous prend la subite envie de jouer à mon superbe jeu pendant que vous êtes dans le train, dans le taxi ou dans n’importe quel endroit où l’accès au réseau est inexistant et bah… vous êtes fichu. C’est quand même dommage dans la mesure où finalement mon jeu n’a pas réellement besoin d’une connexion permanente vers le serveur web une fois que toutes les ressources ont été téléchargées. Heureusement, HTML5 peut désormais adresser ce scénario grâce aux APIs gérant la déconnection. &lt;/p&gt;  &lt;h3&gt;&lt;font color="#000000"&gt;Etape 1: choisir les ressources que vous souhaitez mettre en cache&lt;/font&gt;&lt;font color="#95b9ea"&gt; &lt;/font&gt;&lt;/h3&gt;  &lt;p&gt;C’est assez simple d’indiquer au navigateur quelles sont les ressources que vous souhaitez mettre en cache pour un usage hors connexion. Mais avant d’aller plus loin, je vous invite à lire ces 2 articles décrivant le fonctionnement de cette spécification :&lt;/p&gt;  &lt;p&gt;- &lt;a title="http://blogs.msdn.com/b/ie/archive/2011/09/27/building-offline-experiences-with-html5-appcache-and-indexeddb.aspx" href="http://blogs.msdn.com/b/ie/archive/2011/09/27/building-offline-experiences-with-html5-appcache-and-indexeddb.aspx"&gt;Building Offline Experiences with HTML5 AppCache and IndexedDB&lt;/a&gt; sur le site du blog officiel IE     &lt;br /&gt;- &lt;a title="http://msdn.microsoft.com/en-us/library/hh673545.aspx" href="http://msdn.microsoft.com/en-us/library/hh673545.aspx"&gt;Application Cache API (&amp;quot;AppCache&amp;quot;)&lt;/a&gt; présent dans la documentation MSDN&lt;/p&gt;  &lt;p&gt;Dans mon cas, j’ai construit un fichier manifeste appelé &lt;em&gt;platformer.cache&lt;/em&gt; avec ce type d’entrées :&lt;/p&gt;  &lt;pre class="code"&gt;&lt;strong&gt;CACHE MANIFEST&lt;/strong&gt;
 
# Version 1.5

&lt;strong&gt;CACHE:&lt;/strong&gt; 
index.html
modernplatformer.css
img/MonsterA.png
&lt;em&gt;&lt;font color="#008000"&gt;.. jusqu’à ..&lt;/font&gt;&lt;/em&gt;
img/MonsterD.png
img/Player.png
img/offlinelogoblack.png
img/Backgrounds/Layer0_0.png
&lt;em&gt;&lt;font color="#008000"&gt;.. jusqu’à ..&lt;/font&gt;&lt;/em&gt;
img/Backgrounds/Layer2_2.png 
img/Tiles/BlockA0.png 
&lt;em&gt;&lt;font color="#008000"&gt;.. jusqu’à ..&lt;/font&gt;&lt;/em&gt;
img/Tiles/BlockA6.png
img/Tiles/BlockB0.png
img/Tiles/BlockB1.png
img/Tiles/Gem.png
img/Tiles/Exit.png
img/Tiles/Platform.png
overlays/you_died.png
overlays/you_lose.png
overlays/you_win.png
src/dragDropLogic.js
src/main.js
src/ModernizrCSS3.js
src/easeljs/utils/UID.js
src/easeljs/geom/Matrix2D.js
src/easeljs/events/MouseEvent.js
src/easeljs/utils/SpriteSheetUtils.js
src/easeljs/display/SpriteSheet.js
src/easeljs/display/Shadow.js
src/easeljs/display/DisplayObject.js
src/easeljs/display/Container.js
src/easeljs/display/Stage.js
src/easeljs/display/Bitmap.js
src/easeljs/display/BitmapAnimation.js
src/easeljs/display/Text.js
src/easeljs/utils/Ticker.js
src/easeljs/geom/Rectangle.js
src/easeljs/geom/Point.js
src/easeljs/XNARectangle.js
src/easeljs/PlatformerHelper.js
src/easeljs/ContentManager.js
src/easeljs/Tile.js
src/easeljs/Gem.js
src/easeljs/Enemy.js
src/easeljs/Player.js
src/easeljs/Level.js
src/easeljs/PlatformerGame.js

&lt;strong&gt;NETWORK:&lt;/strong&gt;
*&lt;/pre&gt;

&lt;p&gt;J’y ai inséré l’ensemble de mes fichiers PNG contenant mes sprites, mes différents calques d’arrière plan, les fichiers JavaScript du framework EaselJS ainsi que ma propre logique de jeu et pour finir les fichiers HTML &amp;amp; CSS principaux. Une fois cela spécifié, il ne vous reste plus qu’à indiquer que ce fichier de manifeste sera la source de mise en cache au sein de la page HTML principale. C’est la page “&lt;em&gt;index.html&lt;/em&gt;” dans mon cas :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;!&lt;/span&gt;&lt;span style="color: maroon"&gt;DOCTYPE &lt;/span&gt;&lt;span style="color: red"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;html &lt;/span&gt;&lt;span style="color: red"&gt;&lt;font style="background-color: #ffff00"&gt;manifest&lt;/font&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;font style="background-color: #ffff00"&gt;=&amp;quot;platformer.cache&amp;quot;&lt;/font&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;head&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;HTML5 Platformer Game&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &lt;/span&gt;// ... 
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;head&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Il faut également faire attention à servir le fichier avec le type “&lt;strong&gt;text/cache-manifest&lt;/strong&gt;”. Dans mon cas, comme le fichier est stocké dans le blob storage de Windows Azure, j’a ajouté un nouveau “&lt;em&gt;content type&lt;/em&gt;” nommé “&lt;em&gt;.cache&amp;quot;&lt;/em&gt; mappé sur le type “&lt;em&gt;text/cache-manifest&lt;/em&gt;” donc.&lt;/p&gt;

&lt;p&gt;Par ailleurs, vous devez savoir que la spécification ne permet pas des mises à jours partielles. Ainsi, même si un seul de vos fichiers a changé et que vous souhaitez que le navigateur télécharge la nouvelle version, vous êtes obligé de forcer un nouveau téléchargement complet. Pour cela, il suffit d’effectuer un simple changement au fichier manifest lui-même. La plupart du temps, on ajoute ainsi un numéro de version, une date, un GUID – peu importe finalement – au début du fichier via un commentaire (“&lt;em&gt;Version 1.5&lt;/em&gt;” dans l’exemple précédent). En changeant simplement cette valeur, le navigateur va voir qu’un changement a été effectué au fichier et va alors procéder au téléchargement complet de toutes les ressources spécifiées au sein du même fichier.&lt;/p&gt;

&lt;h3&gt;Etape 2: modifier la logique du jeu pour le chargement des niveaux &lt;/h3&gt;

&lt;p&gt;La version initiale de mon code s’occupait de télécharger chacun des niveaux &lt;strong&gt;via un appel XHR vers le serveur web&lt;/strong&gt;. Comme mon jeu doit maintenant fonctionner hors connexion, il me faut changer cette partie là. Par ailleurs, j’aimerais indiquer à l’utilisateur qu’il joue en mode déconnecté en ajoutant le &lt;a href="http://www.w3.org/html/logo/"&gt;logo “officiel” HTML5&lt;/a&gt; au sein du canvas de jeu.&lt;/p&gt;

&lt;p&gt;Commençons par analyser les changements effectuées pour le chargement des niveaux. La première fois que vous lancerez mon jeu, mon code s’occupera de télécharger tous les niveaux (décrit au sein des fichiers {x}.txt) &lt;strong&gt;vers le local storage&lt;/strong&gt;. Cette spécification est largement supporté depuis IE8 et facile à utiliser. Encore plus important dans notre cas, cela fonctionne même en mode déconnecté.&lt;/p&gt;

&lt;p&gt;Voici le code que j’ai ajouté au sein du fichier “&lt;em&gt;PlatformerGame.js&lt;/em&gt;” :&lt;/p&gt;

&lt;pre class="code"&gt;PlatformerGame.prototype.DownloadAllLevels = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: #006400"&gt;// Searching where we are currently hosted
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;levelsUrl = window.location.href.replace(&lt;span style="color: maroon"&gt;'index.html'&lt;/span&gt;, &lt;span style="color: maroon"&gt;''&lt;/span&gt;) + &lt;span style="color: maroon"&gt;&amp;quot;levels/&amp;quot;&lt;/span&gt;;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;that = &lt;span style="color: blue"&gt;this&lt;/span&gt;;

    &lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i = 0; i &amp;lt; numberOfLevels; i++) {
        &lt;span style="color: blue"&gt;try &lt;/span&gt;{
            &lt;span style="color: blue"&gt;var &lt;/span&gt;request = &lt;span style="color: blue"&gt;new &lt;/span&gt;XMLHttpRequest();
            request.open(&lt;span style="color: maroon"&gt;'GET'&lt;/span&gt;, levelsUrl + i + &lt;span style="color: maroon"&gt;&amp;quot;.txt&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;true&lt;/span&gt;);
            request.onreadystatechange = makeStoreCallback(i, request, that);
            request.send(&lt;span style="color: blue"&gt;null&lt;/span&gt;);
        }
        &lt;span style="color: blue"&gt;catch &lt;/span&gt;(e) {
            &lt;span style="color: #006400"&gt;// Loading the hard coded error level to have at least something to play with
            //console.log(&amp;quot;Error in XHR. Are you offline?&amp;quot;); 
            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(!window.localStorage[&lt;span style="color: maroon"&gt;&amp;quot;platformer_level_0&amp;quot;&lt;/span&gt;]) {
                window.localStorage[&lt;span style="color: maroon"&gt;&amp;quot;platformer_level_0&amp;quot;&lt;/span&gt;] = hardcodedErrorTextLevel;
            }
        }
    }
};

&lt;span style="color: #006400"&gt;// Closure of the index 
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;makeStoreCallback(index, request, that) {
    &lt;span style="color: blue"&gt;return function &lt;/span&gt;() {
        storeLevel(index, request, that);
    }
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;storeLevel(index, request, that) {
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(request.readyState == 4) {
        &lt;span style="color: #006400"&gt;// If everything was OK
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(request.status == 200) {
            &lt;span style="color: #006400"&gt;// storing the level in the local storage
            // with the key &amp;quot;platformer_level_{index}
            &lt;/span&gt;window.localStorage[&lt;span style="color: maroon"&gt;&amp;quot;platformer_level_&amp;quot; &lt;/span&gt;+ index] = request.responseText.replace(/[\n\r\t]/g, &lt;span style="color: maroon"&gt;''&lt;/span&gt;);
            numberOfLevelDownloaded++;
        }
        &lt;span style="color: blue"&gt;else &lt;/span&gt;{
            &lt;span style="color: #006400"&gt;// Loading a hard coded level in case of error
            &lt;/span&gt;window.localStorage[&lt;span style="color: maroon"&gt;&amp;quot;platformer_level_&amp;quot; &lt;/span&gt;+ index] = hardcodedErrorTextLevel;
        }

        &lt;span style="color: blue"&gt;if &lt;/span&gt;(numberOfLevelDownloaded === numberOfLevels) {
            that.LoadNextLevel();
        }
    }
}&lt;/pre&gt;

&lt;p&gt;On télécharge tous les niveaux pendant la phase de construction de l’objet &lt;em&gt;PlateformerGame&lt;/em&gt; de manière asynchrone. Lorsque tous les niveaux sont téléchargés (&lt;em&gt;numberOfLevelDownloaded === numberOfLevels&lt;/em&gt;), on charge le premier niveau. Voici le code de la nouvelle fonction s’occupant de charger le prochain niveau :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Loading the next level contained into the localStorage in platformer_level_{index}
&lt;/span&gt;PlatformerGame.prototype.LoadNextLevel = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.loadNextLevel = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
    &lt;span style="color: #006400"&gt;// Setting back the initialRotation class will trigger the transition
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.className = &lt;span style="color: maroon"&gt;&amp;quot;initialRotation&amp;quot;&lt;/span&gt;;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.levelIndex = (&lt;span style="color: blue"&gt;this&lt;/span&gt;.levelIndex + 1) % numberOfLevels;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;newTextLevel = window.localStorage[&lt;span style="color: maroon"&gt;&amp;quot;platformer_level_&amp;quot; &lt;/span&gt;+ &lt;span style="color: blue"&gt;this&lt;/span&gt;.levelIndex];
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.LoadThisTextLevel(newTextLevel);
};&lt;/pre&gt;

&lt;p&gt;Le début du code s’occupe de gérer les transitions CSS3 comme déjà vu dans &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/04/10/modernisez-vos-jeux-html5-canvas-partie-1-mise-224-l-233-chelle-mat-233-rielle-amp-css3.aspx"&gt;l’article précédent&lt;/a&gt;. Ensuite, on accède simplement au “local storage” via la bonne clé pour retrouver un niveau téléchargé précédemment. &lt;/p&gt;

&lt;h3&gt;Etape 3: vérifier le statut en ligne/hors ligne &amp;amp; afficher un logo en mode déconnecté&lt;/h3&gt;

&lt;p&gt;Il y a 2 choses que vous devez savoir et vérifier pour être sûr d’être en mode déconnecté. Tout d’abord, les navigateurs les plus récents implémentent les évènements &lt;a href="http://msdn.microsoft.com/en-us/library/cc304126%28VS.85%29.aspx"&gt;offline&lt;/a&gt;/&lt;a href="http://msdn.microsoft.com/en-us/library/cc304127(v=VS.85).aspx"&gt;online&lt;/a&gt;. C’est la 1ère chose à vérifier. Si votre navigateur vous dit qu’il est hors ligne, faites lui confiance et n’allez pas plus loin en vous rendant directement dans votre logique de code gérant la déconnection. Cependant, la plupart du temps, cette simple vérification n’est pas suffisante. En effet, votre navigateur indique qu’il est en ligne ou non en vérifiant simplement l’état de votre carte réseau. Il ne sait pas si votre serveur web est toujours en ligne ou simplement accessible depuis là où vous êtes. Vous devez alors effectuer une 2ème vérification en essayant plus ou moins de toquer votre serveur pour vérifier qu’il est toujours en vie via une petite requête XHR par exemple.&lt;/p&gt;

&lt;p&gt;Voici le code que j’ai utilisé pour vérifier ces 2 points dans mon cas :&lt;/p&gt;

&lt;pre class="code"&gt;PlatformerGame.prototype.CheckIfOnline = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(!navigator.onLine) &lt;span style="color: blue"&gt;return false&lt;/span&gt;;

    &lt;span style="color: blue"&gt;var &lt;/span&gt;levelsUrl = window.location.href.replace(&lt;span style="color: maroon"&gt;'index.html'&lt;/span&gt;, &lt;span style="color: maroon"&gt;''&lt;/span&gt;) + &lt;span style="color: maroon"&gt;&amp;quot;levels/&amp;quot;&lt;/span&gt;;

    &lt;span style="color: blue"&gt;try &lt;/span&gt;{
        &lt;span style="color: blue"&gt;var &lt;/span&gt;request = &lt;span style="color: blue"&gt;new &lt;/span&gt;XMLHttpRequest();
        request.open(&lt;span style="color: maroon"&gt;'GET'&lt;/span&gt;, levelsUrl + &lt;span style="color: maroon"&gt;&amp;quot;0.txt&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
        request.send(&lt;span style="color: blue"&gt;null&lt;/span&gt;);
    }
    &lt;span style="color: blue"&gt;catch &lt;/span&gt;(e) {
        &lt;span style="color: blue"&gt;return false&lt;/span&gt;;
    }

    &lt;span style="color: blue"&gt;if &lt;/span&gt;(request.status !== 200)
        &lt;span style="color: blue"&gt;return false&lt;/span&gt;;
    &lt;span style="color: blue"&gt;else
        return true&lt;/span&gt;;
};&lt;/pre&gt;

&lt;p&gt;J’essaie simplement de télécharger le premier niveau. Si cela échoue, je bascule sur la partie “&lt;em&gt;offline&lt;/em&gt;” de mon code. Pour finir, voici le code exécuté pendant la phase de construction de &lt;em&gt;PlateformerGame.js &lt;/em&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;PlatformerGame.IsOnline = &lt;span style="color: blue"&gt;this&lt;/span&gt;.CheckIfOnline();

&lt;span style="color: #006400"&gt;// If we're online, we're downloading/updating all the levels
// from the webserver
&lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(PlatformerGame.IsOnline) {
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.DownloadAllLevels();
}
&lt;span style="color: #006400"&gt;// If we're offline, we're loading the first level
// from the cache handled by the local storage
&lt;/span&gt;&lt;span style="color: blue"&gt;else &lt;/span&gt;{
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.LoadNextLevel();
}&lt;/pre&gt;

&lt;p&gt;Et voici le code s’occupant d’afficher le logo “offline” dans la fonction &lt;em&gt;CreateAndAddRandomBackground&lt;/em&gt; du fichier &lt;em&gt;Level.js &lt;/em&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(!PlatformerGame.IsOnline) {
    offlineLogo.x = 710;
    offlineLogo.y = -1;
    offlineLogo.scaleX = 0.5;
    offlineLogo.scaleY = 0.5;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.levelStage.addChild(offlineLogo);
}&lt;/pre&gt;

&lt;p&gt;Vous devriez avoir ce résultat en lançant mon jeu sans connexion réseau :&lt;/p&gt;
&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0552.image_5F00_416F9DC8.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1134.image_5F00_thumb_5F00_48B61646.png" width="400" height="304" /&gt;&lt;/a&gt; 

&lt;p&gt;Le logo de déconnection sera affiché juste à côté du taux de rafraichissement. Cela vous indiquera que le jeu fonctionne actuellement entièrement en mode hors ligne. &lt;/p&gt;

&lt;h3&gt;Etape 4: chargement conditionnel des fichiers mp3 ou ogg et stockage en blob dans IndexedDB &lt;/h3&gt;

&lt;p&gt;C’est une partie que je n’ai pas implémentée dans cette version mais je voulais en partager avec vous le concept. Voyez donc cette section comme une section bonus. Ce sera à votre charge de l’implémenter ! &lt;img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7612.wlEmoticon_2D00_smile_5F00_5EDC42FD.png" /&gt;&lt;/p&gt;

&lt;p&gt;Peut-être aurez-vous noté que je n’ai pas inclus les effets sonores et la musique de mon jeu dans le fichier de manifeste de l’étape 1.&lt;/p&gt;

&lt;p&gt;Lorsque j’ai écrit ce jeu HTML5, mon but premier était d’être compatible avec le plus grand nombre de navigateurs pour être le plus portable possible. J’ai ainsi 2 versions des fichiers sons: &lt;strong&gt;MP3&lt;/strong&gt; pour IE et Safari, &lt;strong&gt;OGG&lt;/strong&gt; pour Chrome, Firefox &amp;amp; Opera. Dans mon gestionnaire de téléchargement, je télécharge ainsi uniquement le type de codec supporté par le navigateur lançant actuellement mon jeu. En effet, nul besoin de télécharger les versions OGG des fichiers lorsque je joue au jeu dans IE et, de la même manière, aucun intérêt à télécharger les versions MP3 pour Firefox.&lt;/p&gt;

&lt;p&gt;Le problème avec le fichier de manifeste est que vous ne pouvez pas indiquer de manière conditionnelle quelles ressources vous souhaitez charger en fonction du support du navigateur. J’ai donc réfléchi à plusieurs types de solutions pouvant contourner cette limitation :&lt;/p&gt;

&lt;p&gt;1 – &lt;strong&gt;Télécharger chacune des versions&lt;/strong&gt; en insérant toutes les références vers les fichiers .mp3 et .ogg dans le fichier de manifeste. C’est très simple à implémenter et marche bien mais vous téléchargez certains fichiers qui ne seront jamais utilisés par certains navigateurs… 

  &lt;br /&gt;2 – &lt;strong&gt;Fabriquer un fichier manifeste de manière dynamique côté serveur&lt;/strong&gt; en analysant le “user agent” envoyé et en essayant de deviner le codec supporté. Nous savons tous que c’est une mauvaise pratique ! 

  &lt;br /&gt;3 – Détecter côté client le codec supporté dans le gestionnaire de téléchargement pour ensuite &lt;strong&gt;ne télécharger uniquement que le bon format de fichier dans IndexedDB&lt;/strong&gt; ou dans le local storage pour un usage hors ligne.&lt;/p&gt;

&lt;p&gt;Selon moi, la 3ème solution est de loin la meilleure mais il y a plusieurs choses à avoir en tête pour l’implémenter :&lt;/p&gt;

&lt;p&gt;1 – Si vous utilisez le “local storage”, vous aurez besoin d’encoder en base64 les fichiers et vous serez potentiellement limité par le quota du navigateur si vous avez des fichiers trop gros ou trop nombreux 
  &lt;br /&gt;2 – Si vous utilisez IndexedDB, vous pouvez soit stocker la version base64 soit les stocker sous la forme de blob&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;L’approche du stockage blob est définitivement la plus performante &lt;/strong&gt;mais elle nécessite un navigateur très récent comme &lt;strong&gt;IE10 (PP5)&lt;/strong&gt; ou Firefox (11). Mais si ce sujet vous rend curieux (et c’est bien naturel !), vous pouvez jeter un oeil à notre démo Facebook Companion hébergée sur notre site IE Test Drive ici :&lt;/p&gt;
&lt;a href="http://ietestdrive2.com/OfflineSocialAlbums"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0552.image_5F00_22764D9F.png" width="220" height="136" /&gt;&lt;/a&gt; 

&lt;p&gt;
  &lt;br /&gt;Vous trouverez d’ailleurs davantage de détails sur cette démo au sein de cet article : &lt;a title="http://blogs.msdn.com/b/ie/archive/2012/03/21/indexeddb-updates-for-ie10-and-metro-style-apps.aspx" href="http://blogs.msdn.com/b/ie/archive/2012/03/21/indexeddb-updates-for-ie10-and-metro-style-apps.aspx"&gt;IndexedDB Updates for IE10 and Metro style apps&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pour la version disponible au sein de cet article, j’ai fait mon faignant. J’ai finalement décidé de mettre en cache tous les formats (solution 1). J’améliorais peut-être cela dans un futur article en implémentant un cache basé sur IndexedDB.&lt;/p&gt;

&lt;h2&gt;Glisser/Déposer des niveaux depuis votre bureau &lt;/h2&gt;

&lt;p&gt;Mon idée ici était de bénéficier des nouvelles API de Drag’n’drop et de manipulation de fichiers pour tester des scénarios amusants. L’utilisateur sera ainsi capable de créer/éditer ses propres niveaux via son éditeur de texte préféré. Ensuite, il glissera/déposera ses fichiers depuis l’explorateur de fichiers directement dans le jeu HTML5 pour jouer avec.&lt;/p&gt;

&lt;p&gt;Je ne rentrerais pas plus en détails sur le fonctionnement du drag’n’drop puisqu’il a été très bien décrit dans cet article : &lt;a title="http://blogs.msdn.com/b/ie/archive/2011/07/27/html5-drag-and-drop-in-ie10-ppb2.aspx" href="http://blogs.msdn.com/b/ie/archive/2011/07/27/html5-drag-and-drop-in-ie10-ppb2.aspx"&gt;HTML5 Drag and Drop in IE10&lt;/a&gt; expliquant comment la démo &lt;a href="http://ie.microsoft.com/testdrive/Graphics/MagneticPoetry/Default.html"&gt;Magnetic Poetry&lt;/a&gt; a été réalisée. Assurez vous d’avoir lu cet article avant si vous souhaitez comprendre le code ci-dessous.&lt;/p&gt;

&lt;p&gt;Dans mon cas, j’ai créé le fichier &lt;em&gt;dragDropLogic.js &lt;/em&gt;contenant le code suivant :&lt;/p&gt;

&lt;pre class="code"&gt;(&lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: maroon"&gt;&amp;quot;use strict&amp;quot;&lt;/span&gt;;

    &lt;span style="color: blue"&gt;var &lt;/span&gt;DragDropLogic = DragDropLogic || {};

    &lt;span style="color: blue"&gt;var &lt;/span&gt;_elementToMonitor;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;_platformerGameInstance;

    &lt;span style="color: #006400"&gt;// We need the canvas to monitor its drag&amp;amp;drop events
    // and the platformer game instance to trigger the loadnextlevel function
    &lt;/span&gt;DragDropLogic.monitorElement = &lt;span style="color: blue"&gt;function &lt;/span&gt;(elementToMonitor, platformerGameInstance) {
        _elementToMonitor = elementToMonitor;
        _platformerGameInstance = platformerGameInstance;

          _elementToMonitor.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;dragenter&amp;quot;&lt;/span&gt;, DragDropLogic.drag, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
          _elementToMonitor.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;dragover&amp;quot;&lt;/span&gt;, DragDropLogic.drag, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
          _elementToMonitor.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;drop&amp;quot;&lt;/span&gt;, DragDropLogic.drop, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    };

    &lt;span style="color: #006400"&gt;// We don't need to do specific actions
    // enter &amp;amp; over, we're only interested in drop
    &lt;/span&gt;DragDropLogic.drag = &lt;span style="color: blue"&gt;function &lt;/span&gt;(e) {
        e.stopPropagation();
        e.preventDefault();
    };

    DragDropLogic.drop = &lt;span style="color: blue"&gt;function &lt;/span&gt;(e) {
        e.stopPropagation();
        e.preventDefault();

        &lt;span style="color: blue"&gt;var &lt;/span&gt;dt = e.dataTransfer;
        &lt;span style="color: blue"&gt;var &lt;/span&gt;files = dt.files;

        &lt;span style="color: #006400"&gt;// Taking only the first dropped file
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;firstFileDropped = files[0];

        &lt;span style="color: #006400"&gt;// Basic check of the type of file dropped
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(firstFileDropped.type.indexOf(&lt;span style="color: maroon"&gt;&amp;quot;text&amp;quot;&lt;/span&gt;) == 0) {
            &lt;span style="color: blue"&gt;var &lt;/span&gt;reader = &lt;span style="color: blue"&gt;new &lt;/span&gt;FileReader();
            &lt;span style="color: #006400"&gt;// Callback function
            &lt;/span&gt;reader.onload = &lt;span style="color: blue"&gt;function &lt;/span&gt;(e) {
                &lt;span style="color: #006400"&gt;// get file content
                &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;text = e.target.result;
                &lt;span style="color: blue"&gt;var &lt;/span&gt;textLevel = text.replace(/[\s\n\r\t]/g, &lt;span style="color: maroon"&gt;''&lt;/span&gt;);
                &lt;span style="color: #006400"&gt;// Warning, there is no real check on the consistency
                // of the file. 
                &lt;/span&gt;_platformerGameInstance.LoadThisTextLevel(textLevel);
            }
            &lt;span style="color: #006400"&gt;// Asynchronous read
            &lt;/span&gt;reader.readAsText(firstFileDropped);
        }
    };

    window.DragDropLogic = DragDropLogic;
})();&lt;/pre&gt;

&lt;p&gt;Ce code est appelé au sein de &lt;em&gt;main.js&lt;/em&gt; dans la fonction &lt;em&gt;startGame&lt;/em&gt; :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Callback function once everything has been downloaded
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;startGame() {
    platformerGame = &lt;span style="color: blue"&gt;new &lt;/span&gt;PlatformerGame(stage, contentManager, 800, 480, window.innerWidth, window.innerHeight);
    window.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;resize&amp;quot;&lt;/span&gt;, OnResizeCalled, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    OnResizeCalled();
    &lt;font style="background-color: #ffff00"&gt;DragDropLogic.monitorElement(canvas, platformerGame);
&lt;/font&gt;    platformerGame.StartGame();
}&lt;/pre&gt;

&lt;p&gt;Et c’est tout ! Par exemple, copiez/collez ce bloc de texte dans un nouveau fichier “.txt” :&lt;/p&gt;

&lt;p&gt;&lt;font color="#008000" face="Courier New"&gt;.................... 
    &lt;br /&gt;.................... 

    &lt;br /&gt;.................... 

    &lt;br /&gt;.1.................. 

    &lt;br /&gt;######.........##### 

    &lt;br /&gt;.................... 

    &lt;br /&gt;.........###........ 

    &lt;br /&gt;.................... 

    &lt;br /&gt;.G.G.GGG.G.G.G...... 

    &lt;br /&gt;.GGG..G..GGG.G...... 

    &lt;br /&gt;.G.G..G..G.G.GGG.... 

    &lt;br /&gt;.................... 

    &lt;br /&gt;.................... 

    &lt;br /&gt;.X................C. 

    &lt;br /&gt;####################&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;Puis glissez/déposez le dans mon jeu. Un nouveau niveau devrait alors être magiquement chargé :&lt;/p&gt;
&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0361.image_5F00_3F4419F0.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1537.image_5F00_thumb_5F00_29942439.png" width="450" height="266" /&gt;&lt;/a&gt; 

&lt;br /&gt;

&lt;br /&gt;

&lt;h2&gt;&lt;strong&gt;&lt;font color="#000000"&gt;Vidéo, URL pour jouer avec la démo &amp;amp; code source à télécharger &lt;/font&gt;&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Voici une courte vidéo illustrant le résultat de cet article dans IE10 :&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="ModernHTML5PlatformerPart2FR" class="video-js" height="360" width="640" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2FR.jpg"&gt;&lt;source src="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2FR.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2FR.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="640" type="application/x-shockwave-flash" height="360"&gt;  &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  
&lt;param name="allowfullscreen" value="true" /&gt;  
&lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2FR.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2FR.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  
&lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   
&lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2FR.jpg" width="512" height="288" /&gt;   &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2FR.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2FR.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;Vous pouvez aussi jouer avec cette démo dans IE10 ou dans votre navigateur préféré ici : &lt;a href="http://david.blob.core.windows.net/modernhtml5platformer/index.html"&gt;Modern HTML5 Platformer&lt;/a&gt;&lt;/p&gt;
&lt;a href="http://david.blob.core.windows.net/modernhtml5platformer/index.html"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4382.image_5F00_7B8C1CD8.png" width="240" height="124" /&gt;&lt;/a&gt; 

&lt;br /&gt;

&lt;p&gt;
  &lt;br /&gt;Pour finir, comme vous avez été suffisamment patient et concentré pour me lire jusqu’au bout, je vous offre la possibilité de télécharger le code source complet ici : &lt;a title="http://david.blob.core.windows.net/modernhtml5platformer/ModernHTML5PlatformerSourceCode.zip" href="http://david.blob.core.windows.net/modernhtml5platformer/ModernHTML5PlatformerSourceCode.zip"&gt;HTML5 Modern Platformer Source Code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10294848" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Canvas/">Canvas</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/IE10/">IE10</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/JavaScript/">JavaScript</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Drag_2700_n_2700_drop/">Drag'n'drop</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Offline/">Offline</category></item><item><title>Modernizing your HTML5 Canvas games Part 2: Offline API, Drag’n’drop &amp; File API</title><link>http://blogs.msdn.com/b/davrous/archive/2012/04/17/modernizing-your-html5-canvas-games-part-2-offline-api-drag-n-drop-amp-file-api.aspx</link><pubDate>Tue, 17 Apr 2012 14:04:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10294464</guid><dc:creator>David Rousset</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10294464</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/04/17/modernizing-your-html5-canvas-games-part-2-offline-api-drag-n-drop-amp-file-api.aspx#comments</comments><description>&lt;!-- Include the VideoJS Library --&gt;&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;  &lt;p&gt;We’ve seen in the previous article &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/04/06/modernizing-your-html5-canvas-games-with-offline-apis-file-apis-css3-amp-hardware-scaling.aspx"&gt;Modernizing your HTML5 Canvas games Part 1: hardware scaling &amp;amp; CSS3&lt;/a&gt; how to use CSS3 3D Transform, Transitions &amp;amp; Grid Layout for a HTML5 Platformer game. We’re now going to see how to use the &lt;strong&gt;Offline API, Drag’n’drop &amp;amp; File API&lt;/strong&gt; to leverage new ideas I had while coding my game.&lt;/p&gt;  &lt;p&gt;If you haven’t read the &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/04/06/modernizing-your-html5-canvas-games-with-offline-apis-file-apis-css3-amp-hardware-scaling.aspx"&gt;first article&lt;/a&gt;, let me remind you that my objectives were to see how to use these new features to modernize my previous HTML5 game named &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/03/21/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx"&gt;HTML5 Platformer&lt;/a&gt;.&amp;#160; &lt;/p&gt;  &lt;h2&gt;Agenda&lt;/h2&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;&lt;font color="#0691d6"&gt;Playing to the game in offline mode&lt;/font&gt;&lt;/strong&gt;       &lt;ul&gt;       &lt;li&gt;&lt;font color="#95b9ea"&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: choosing the resources you’d like to &lt;strong&gt;cache&lt;/strong&gt; &lt;/font&gt;&lt;/li&gt;        &lt;li&gt;&lt;font color="#95b9ea"&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: modifying the &lt;strong&gt;logic&lt;/strong&gt; for the levels &lt;/font&gt;&lt;/li&gt;        &lt;li&gt;&lt;font color="#95b9ea"&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: checking &lt;strong&gt;online/offline&lt;/strong&gt; &amp;amp; displaying a logo when launched in offline mode &lt;/font&gt;&lt;/li&gt;        &lt;li&gt;&lt;font color="#95b9ea"&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: conditionally downloading the mp3 or ogg files and store them as &lt;strong&gt;blob in IndexedDB&lt;/strong&gt;&lt;/font&gt;&lt;strong&gt; &lt;/strong&gt;&lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;font color="#0691d6"&gt;Drag’n’dropping the levels from your desktop&lt;/font&gt;&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;font color="#0691d6"&gt;Video, URL to play this demo &amp;amp; source code&lt;/font&gt;&lt;/strong&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Playing to the game in offline mode&lt;/h2&gt;  &lt;p&gt;The &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/03/21/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx"&gt;original version&lt;/a&gt; of the game only works if your device has access to Internet. For instance, let’s imagine you’d like to play to my awesome game while you’re in the train, in a taxi or in any other scenarios where your machine can’t access to the network, you’re stuck. It’s really sad as finally nothing in my game really needs a “live” connection to the webserver once all the resources have been downloaded. Hopefully, HTML5 can now address this scenario thanks to the offline APIs. &lt;/p&gt;  &lt;h3&gt;Step 1: choosing the resources you’d like to cache&lt;/h3&gt;  &lt;p&gt;It’s pretty simple to indicate to the browser which resources you’d like to cache for an offline use. But before going further, you should first read those 2 articles:&lt;/p&gt;  &lt;p&gt;- &lt;a title="http://blogs.msdn.com/b/ie/archive/2011/09/27/building-offline-experiences-with-html5-appcache-and-indexeddb.aspx" href="http://blogs.msdn.com/b/ie/archive/2011/09/27/building-offline-experiences-with-html5-appcache-and-indexeddb.aspx"&gt;Building Offline Experiences with HTML5 AppCache and IndexedDB&lt;/a&gt; from our IE blog     &lt;br /&gt;- &lt;a title="http://msdn.microsoft.com/en-us/library/hh673545.aspx" href="http://msdn.microsoft.com/en-us/library/hh673545.aspx"&gt;Application Cache API (&amp;quot;AppCache&amp;quot;)&lt;/a&gt; from the MSDN Documentation&lt;/p&gt;  &lt;p&gt;In my case, I’ve built a file named platformer.cache with this kind of entries:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;strong&gt;CACHE MANIFEST&lt;/strong&gt;
 
# Version 1.5

&lt;strong&gt;CACHE:&lt;/strong&gt; 
index.html
modernplatformer.css
img/MonsterA.png
&lt;em&gt;&lt;font color="#008000"&gt;.. up to ..&lt;/font&gt;&lt;/em&gt;
img/MonsterD.png
img/Player.png
img/offlinelogoblack.png
img/Backgrounds/Layer0_0.png
&lt;em&gt;&lt;font color="#008000"&gt;.. up to ..&lt;/font&gt;&lt;/em&gt;
img/Backgrounds/Layer2_2.png 
img/Tiles/BlockA0.png 
&lt;em&gt;&lt;font color="#008000"&gt;.. up to ..&lt;/font&gt;&lt;/em&gt;
img/Tiles/BlockA6.png
img/Tiles/BlockB0.png
img/Tiles/BlockB1.png
img/Tiles/Gem.png
img/Tiles/Exit.png
img/Tiles/Platform.png
overlays/you_died.png
overlays/you_lose.png
overlays/you_win.png
src/dragDropLogic.js
src/main.js
src/ModernizrCSS3.js
src/easeljs/utils/UID.js
src/easeljs/geom/Matrix2D.js
src/easeljs/events/MouseEvent.js
src/easeljs/utils/SpriteSheetUtils.js
src/easeljs/display/SpriteSheet.js
src/easeljs/display/Shadow.js
src/easeljs/display/DisplayObject.js
src/easeljs/display/Container.js
src/easeljs/display/Stage.js
src/easeljs/display/Bitmap.js
src/easeljs/display/BitmapAnimation.js
src/easeljs/display/Text.js
src/easeljs/utils/Ticker.js
src/easeljs/geom/Rectangle.js
src/easeljs/geom/Point.js
src/easeljs/XNARectangle.js
src/easeljs/PlatformerHelper.js
src/easeljs/ContentManager.js
src/easeljs/Tile.js
src/easeljs/Gem.js
src/easeljs/Enemy.js
src/easeljs/Player.js
src/easeljs/Level.js
src/easeljs/PlatformerGame.js

&lt;strong&gt;NETWORK:&lt;/strong&gt;
*&lt;/pre&gt;

&lt;p&gt;I’ve inserted all my PNG files containing my sprites, background layers &amp;amp; overlays, the needed JS files from the EaselJS framework as well as my own gaming logic and the main HTML &amp;amp; CSS files. Once done, you just have to indicate you’d like to use this manifest file in your main HTML page. It’s “&lt;em&gt;index.html&lt;/em&gt;” in my case:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;!&lt;/span&gt;&lt;span style="color: maroon"&gt;DOCTYPE &lt;/span&gt;&lt;span style="color: red"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;html &lt;/span&gt;&lt;span style="color: red"&gt;&lt;font style="background-color: #ffff00"&gt;manifest&lt;/font&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;font style="background-color: #ffff00"&gt;=&amp;quot;platformer.cache&amp;quot;&lt;/font&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;head&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;HTML5 Platformer Game&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &lt;/span&gt;// ... 
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;head&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Please note also that your manifest file should be served as “&lt;strong&gt;text/cache-manifest&lt;/strong&gt;”. As it’s stored in the blob storage of Windows Azure in my case, I’ve added a new “.cache” content type mapped to “text/cache-manifest” then. &lt;/p&gt;

&lt;p&gt;Moreover, you need to understand that the specification doesn’t allow delta changes. This means that if only one of your files has changed and you’d like the browser to download the new version, you need to force a complete re-download. For that, add a simple change to your manifest file. Most of the time, we’re adding a version number, a date, a GUID - you named it - at the beginning of the file via a comment (“&lt;em&gt;Version 1.5&lt;/em&gt;” in the above example). By simply changing its value, the browser will see that a change have been done to the file and will re-download all resources specified inside it.&lt;/p&gt;

&lt;h3&gt;Step 2: modifying the logic for loading the levels&lt;/h3&gt;

&lt;p&gt;The original version of my code was downloading each level &lt;strong&gt;via a XHR call to the webserver&lt;/strong&gt;. As my game now needs to run in offline mode, I need to change that. Moreover, I’d like to indicate to the user that he’s currently playing in offline mode by adding the “&lt;em&gt;official&lt;/em&gt;” &lt;a href="http://www.w3.org/html/logo/"&gt;HTML5 associated logo&lt;/a&gt; inside the gaming canvas.&lt;/p&gt;

&lt;p&gt;Let’s first review the changes done for the levels. First time you’ll launch my game, I’ll download all the levels (described into {x}.txt files) &lt;strong&gt;into the local storage&lt;/strong&gt;. This is widely supported since IE8 and very easy to use. Even more important, it’s available in offline mode. &lt;/p&gt;

&lt;p&gt;Here is the code I’ve added inside the “&lt;em&gt;PlatformerGame.js&lt;/em&gt;”:&lt;/p&gt;

&lt;pre class="code"&gt;PlatformerGame.prototype.DownloadAllLevels = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: #006400"&gt;// Searching where we are currently hosted
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;levelsUrl = window.location.href.replace(&lt;span style="color: maroon"&gt;'index.html'&lt;/span&gt;, &lt;span style="color: maroon"&gt;''&lt;/span&gt;) + &lt;span style="color: maroon"&gt;&amp;quot;levels/&amp;quot;&lt;/span&gt;;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;that = &lt;span style="color: blue"&gt;this&lt;/span&gt;;

    &lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i = 0; i &amp;lt; numberOfLevels; i++) {
        &lt;span style="color: blue"&gt;try &lt;/span&gt;{
            &lt;span style="color: blue"&gt;var &lt;/span&gt;request = &lt;span style="color: blue"&gt;new &lt;/span&gt;XMLHttpRequest();
            request.open(&lt;span style="color: maroon"&gt;'GET'&lt;/span&gt;, levelsUrl + i + &lt;span style="color: maroon"&gt;&amp;quot;.txt&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;true&lt;/span&gt;);
            request.onreadystatechange = makeStoreCallback(i, request, that);
            request.send(&lt;span style="color: blue"&gt;null&lt;/span&gt;);
        }
        &lt;span style="color: blue"&gt;catch &lt;/span&gt;(e) {
            &lt;span style="color: #006400"&gt;// Loading the hard coded error level to have at least something to play with
            //console.log(&amp;quot;Error in XHR. Are you offline?&amp;quot;); 
            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(!window.localStorage[&lt;span style="color: maroon"&gt;&amp;quot;platformer_level_0&amp;quot;&lt;/span&gt;]) {
                window.localStorage[&lt;span style="color: maroon"&gt;&amp;quot;platformer_level_0&amp;quot;&lt;/span&gt;] = hardcodedErrorTextLevel;
            }
        }
    }
};

&lt;span style="color: #006400"&gt;// Closure of the index 
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;makeStoreCallback(index, request, that) {
    &lt;span style="color: blue"&gt;return function &lt;/span&gt;() {
        storeLevel(index, request, that);
    }
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;storeLevel(index, request, that) {
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(request.readyState == 4) {
        &lt;span style="color: #006400"&gt;// If everything was OK
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(request.status == 200) {
            &lt;span style="color: #006400"&gt;// storing the level in the local storage
            // with the key &amp;quot;platformer_level_{index}
            &lt;/span&gt;window.localStorage[&lt;span style="color: maroon"&gt;&amp;quot;platformer_level_&amp;quot; &lt;/span&gt;+ index] = request.responseText.replace(/[\n\r\t]/g, &lt;span style="color: maroon"&gt;''&lt;/span&gt;);
            numberOfLevelDownloaded++;
        }
        &lt;span style="color: blue"&gt;else &lt;/span&gt;{
            &lt;span style="color: #006400"&gt;// Loading a hard coded level in case of error
            &lt;/span&gt;window.localStorage[&lt;span style="color: maroon"&gt;&amp;quot;platformer_level_&amp;quot; &lt;/span&gt;+ index] = hardcodedErrorTextLevel;
        }

        &lt;span style="color: blue"&gt;if &lt;/span&gt;(numberOfLevelDownloaded === numberOfLevels) {
            that.LoadNextLevel();
        }
    }
}&lt;/pre&gt;

&lt;p&gt;We’re downloading all the levels in the PlateformerGame constructor in an asynchronous way. When all the levels have been downloaded (&lt;em&gt;numberOfLevelDownloaded === numberOfLevels&lt;/em&gt;), we’re loading the first level. Here is the code of the new function:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Loading the next level contained into the localStorage in platformer_level_{index}
&lt;/span&gt;PlatformerGame.prototype.LoadNextLevel = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.loadNextLevel = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
    &lt;span style="color: #006400"&gt;// Setting back the initialRotation class will trigger the transition
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.className = &lt;span style="color: maroon"&gt;&amp;quot;initialRotation&amp;quot;&lt;/span&gt;;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.levelIndex = (&lt;span style="color: blue"&gt;this&lt;/span&gt;.levelIndex + 1) % numberOfLevels;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;newTextLevel = window.localStorage[&lt;span style="color: maroon"&gt;&amp;quot;platformer_level_&amp;quot; &lt;/span&gt;+ &lt;span style="color: blue"&gt;this&lt;/span&gt;.levelIndex];
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.LoadThisTextLevel(newTextLevel);
};&lt;/pre&gt;

&lt;p&gt;The beginning of the code handles the CSS3 transitions like described in the &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/04/06/modernizing-your-html5-canvas-games-with-offline-apis-file-apis-css3-amp-hardware-scaling.aspx"&gt;previous article&lt;/a&gt;. Then, we’re simply accessing to the local storage via the appropriate key to retrieve the previously downloaded content. &lt;/p&gt;

&lt;h3&gt;Step 3: checking online/offline &amp;amp; displaying a logo when launched in offline mode&lt;/h3&gt;

&lt;p&gt;There are 2 things you need to check to know &amp;amp; confirm you’re in offline mode. First of all, the most recent browsers implement the &lt;a href="http://msdn.microsoft.com/en-us/library/cc304126%28VS.85%29.aspx"&gt;offline&lt;/a&gt;/&lt;a href="http://msdn.microsoft.com/en-us/library/cc304127(v=VS.85).aspx"&gt;online&lt;/a&gt; events. This is the first thing to check. If your browser says he’s offline, no need to go further and you should immediately switch to your offline logic. But most of the time, this simple check is not enough. Your browser says it’s online or not by simply checking the connectivity state of your network card. It doesn’t know if your webserver is still online or simply available from where you are. You then need to do a second check by trying to more or less ping your server with a simple XHR for instance.&lt;/p&gt;

&lt;p&gt;Here my code checking those 2 points in my case:&lt;/p&gt;

&lt;pre class="code"&gt;PlatformerGame.prototype.CheckIfOnline = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(!navigator.onLine) &lt;span style="color: blue"&gt;return false&lt;/span&gt;;

    &lt;span style="color: blue"&gt;var &lt;/span&gt;levelsUrl = window.location.href.replace(&lt;span style="color: maroon"&gt;'index.html'&lt;/span&gt;, &lt;span style="color: maroon"&gt;''&lt;/span&gt;) + &lt;span style="color: maroon"&gt;&amp;quot;levels/&amp;quot;&lt;/span&gt;;

    &lt;span style="color: blue"&gt;try &lt;/span&gt;{
        &lt;span style="color: blue"&gt;var &lt;/span&gt;request = &lt;span style="color: blue"&gt;new &lt;/span&gt;XMLHttpRequest();
        request.open(&lt;span style="color: maroon"&gt;'GET'&lt;/span&gt;, levelsUrl + &lt;span style="color: maroon"&gt;&amp;quot;0.txt&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
        request.send(&lt;span style="color: blue"&gt;null&lt;/span&gt;);
    }
    &lt;span style="color: blue"&gt;catch &lt;/span&gt;(e) {
        &lt;span style="color: blue"&gt;return false&lt;/span&gt;;
    }

    &lt;span style="color: blue"&gt;if &lt;/span&gt;(request.status !== 200)
        &lt;span style="color: blue"&gt;return false&lt;/span&gt;;
    &lt;span style="color: blue"&gt;else
        return true&lt;/span&gt;;
};&lt;/pre&gt;

&lt;p&gt;I’m just trying to download the first level. If it fails, I’m switching to the offline part of my code. Finally, here is the code launched in the constructor part of the &lt;em&gt;PlateformerGame.js&lt;/em&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;PlatformerGame.IsOnline = &lt;span style="color: blue"&gt;this&lt;/span&gt;.CheckIfOnline();

&lt;span style="color: #006400"&gt;// If we're online, we're downloading/updating all the levels
// from the webserver
&lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(PlatformerGame.IsOnline) {
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.DownloadAllLevels();
}
&lt;span style="color: #006400"&gt;// If we're offline, we're loading the first level
// from the cache handled by the local storage
&lt;/span&gt;&lt;span style="color: blue"&gt;else &lt;/span&gt;{
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.LoadNextLevel();
}&lt;/pre&gt;

&lt;p&gt;and here is the code displaying the offline logo in &lt;em&gt;Level.js &lt;/em&gt;in the &lt;em&gt;CreateAndAddRandomBackground&lt;/em&gt; function:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(!PlatformerGame.IsOnline) {
    offlineLogo.x = 710;
    offlineLogo.y = -1;
    offlineLogo.scaleX = 0.5;
    offlineLogo.scaleY = 0.5;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.levelStage.addChild(offlineLogo);
}&lt;/pre&gt;

&lt;p&gt;Once done, here is the result you’ll have in your browser when launching my game without network connection:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0552.image_5F00_416F9DC8.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1134.image_5F00_thumb_5F00_48B61646.png" width="400" height="304" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The offline logo will be displayed just before the frame rate. This tells you that the game is currently working purely offline. &lt;/p&gt;

&lt;h3&gt;Step 4: conditionally downloading the mp3 or ogg files and store them as blob in IndexedDB&lt;/h3&gt;

&lt;p&gt;This is something I’ve not implemented in this version but I’d like to share the concept with you. See this section as a bonus you’ll need to implement yourself! &lt;img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2742.wlEmoticon_2D00_smile_5F00_7F34D05E.png" /&gt;&lt;/p&gt;

&lt;p&gt;Maybe you’ll have noticed that I’ve not included the sound effects &amp;amp; the music of my game in the manifest file of step 1. &lt;/p&gt;

&lt;p&gt;When writing this HTML5 game, my first goal was to be compatible with the biggest number of browsers (when possible). I have then 2 versions of the sounds: &lt;strong&gt;MP3&lt;/strong&gt; for IE and Safari, &lt;strong&gt;OGG&lt;/strong&gt; for Chrome, Firefox &amp;amp; Opera. In my content download manager, I’m downloading only the type of codec supported by the current browser launching my game. Indeed, no need to download the OGG version of the files if I’m playing it inside IE as well as there is no need to download the MP3 version for Firefox. &lt;/p&gt;

&lt;p&gt;The problem with the manifest file is that you can’t conditionally indicate which resource to load based on the current browser’s support. I’ve then imagined several solutions to work-around this limitation:&lt;/p&gt;

&lt;p&gt;1 – &lt;strong&gt;Download both versions&lt;/strong&gt; by putting all files references inside the manifest file. This is very simple to implement and works fine but you’re downloading some files that will be never used by some browsers… 

  &lt;br /&gt;2 – &lt;strong&gt;Build a server-side dynamic manifest&lt;/strong&gt; file by sniffing the browser agent to guess the codec supported. This is definitely a very bad practice!&amp;#160; &lt;br /&gt;3 - Client-side feature detect the codec support in the content manager object and then &lt;strong&gt;download the appropriate file format in IndexedDB&lt;/strong&gt; or in the local storage for offline use.&lt;/p&gt;

&lt;p&gt;To my point of view, the 3rd solution is the best one but there are several things to keep in mind to do that:&lt;/p&gt;

&lt;p&gt;1 – If you’re using local storage, you’ll need to encode in base64 the files and you’ll be potentially limited by the quota if you have too big/many files 
  &lt;br /&gt;2 – If you’re using IndexedDB, you can either store the base64 encoded version of the files or store them as a blob.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;blob approach is definitely the most efficient &amp;amp; smart approach&lt;/strong&gt; but needs a very up-to-date browser like the last version of &lt;strong&gt;IE10 (PP5)&lt;/strong&gt; or Firefox (11). But if you’re curious about this one, check out our Facebook Companion demo from our IE Test Drive site here:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ietestdrive2.com/OfflineSocialAlbums"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0552.image_5F00_22764D9F.png" width="220" height="136" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You’ll find more details about this demo in this article: &lt;a title="http://blogs.msdn.com/b/ie/archive/2012/03/21/indexeddb-updates-for-ie10-and-metro-style-apps.aspx" href="http://blogs.msdn.com/b/ie/archive/2012/03/21/indexeddb-updates-for-ie10-and-metro-style-apps.aspx"&gt;IndexedDB Updates for IE10 and Metro style apps&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the version available with this article, I’ve been lazy. I’ve finally decided to cache all formats (solution 1). I’ll maybe enhance that in a future article by implementing an IndexedDB caching.&lt;/p&gt;

&lt;h2&gt;Drag’n’dropping the levels from your desktop&lt;/h2&gt;

&lt;p&gt;My idea here was to take advantage of the new Drag’n’drop &amp;amp; File APIs to implement a funny scenario. The user will be able to create/edit a level using his favorite text editor. Then, he will drag’n’drop it from his file explorer directly into the HTML5 game to play with it!&lt;/p&gt;

&lt;p&gt;I won’t go into much details about drag’n’drop as it has been very well covered in this article: &lt;a title="http://blogs.msdn.com/b/ie/archive/2011/07/27/html5-drag-and-drop-in-ie10-ppb2.aspx" href="http://blogs.msdn.com/b/ie/archive/2011/07/27/html5-drag-and-drop-in-ie10-ppb2.aspx"&gt;HTML5 Drag and Drop in IE10&lt;/a&gt; explaining how the &lt;a href="http://ie.microsoft.com/testdrive/Graphics/MagneticPoetry/Default.html"&gt;Magnetic Poetry&lt;/a&gt; demo was built. Be sure to read this article first if you’d like to understand the above code.&lt;/p&gt;

&lt;p&gt;In my case, I’ve created the &lt;em&gt;dragDropLogic.js&lt;/em&gt; file containing this code:&lt;/p&gt;

&lt;pre class="code"&gt;(&lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: maroon"&gt;&amp;quot;use strict&amp;quot;&lt;/span&gt;;

    &lt;span style="color: blue"&gt;var &lt;/span&gt;DragDropLogic = DragDropLogic || {};

    &lt;span style="color: blue"&gt;var &lt;/span&gt;_elementToMonitor;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;_platformerGameInstance;

    &lt;span style="color: #006400"&gt;// We need the canvas to monitor its drag&amp;amp;drop events
    // and the platformer game instance to trigger the loadnextlevel function
    &lt;/span&gt;DragDropLogic.monitorElement = &lt;span style="color: blue"&gt;function &lt;/span&gt;(elementToMonitor, platformerGameInstance) {
        _elementToMonitor = elementToMonitor;
        _platformerGameInstance = platformerGameInstance;

          _elementToMonitor.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;dragenter&amp;quot;&lt;/span&gt;, DragDropLogic.drag, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
          _elementToMonitor.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;dragover&amp;quot;&lt;/span&gt;, DragDropLogic.drag, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
          _elementToMonitor.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;drop&amp;quot;&lt;/span&gt;, DragDropLogic.drop, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    };

    &lt;span style="color: #006400"&gt;// We don't need to do specific actions
    // enter &amp;amp; over, we're only interested in drop
    &lt;/span&gt;DragDropLogic.drag = &lt;span style="color: blue"&gt;function &lt;/span&gt;(e) {
        e.stopPropagation();
        e.preventDefault();
    };

    DragDropLogic.drop = &lt;span style="color: blue"&gt;function &lt;/span&gt;(e) {
        e.stopPropagation();
        e.preventDefault();

        &lt;span style="color: blue"&gt;var &lt;/span&gt;dt = e.dataTransfer;
        &lt;span style="color: blue"&gt;var &lt;/span&gt;files = dt.files;

        &lt;span style="color: #006400"&gt;// Taking only the first dropped file
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;firstFileDropped = files[0];

        &lt;span style="color: #006400"&gt;// Basic check of the type of file dropped
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(firstFileDropped.type.indexOf(&lt;span style="color: maroon"&gt;&amp;quot;text&amp;quot;&lt;/span&gt;) == 0) {
            &lt;span style="color: blue"&gt;var &lt;/span&gt;reader = &lt;span style="color: blue"&gt;new &lt;/span&gt;FileReader();
            &lt;span style="color: #006400"&gt;// Callback function
            &lt;/span&gt;reader.onload = &lt;span style="color: blue"&gt;function &lt;/span&gt;(e) {
                &lt;span style="color: #006400"&gt;// get file content
                &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;text = e.target.result;
                &lt;span style="color: blue"&gt;var &lt;/span&gt;textLevel = text.replace(/[\s\n\r\t]/g, &lt;span style="color: maroon"&gt;''&lt;/span&gt;);
                &lt;span style="color: #006400"&gt;// Warning, there is no real check on the consistency
                // of the file. 
                &lt;/span&gt;_platformerGameInstance.LoadThisTextLevel(textLevel);
            }
            &lt;span style="color: #006400"&gt;// Asynchronous read
            &lt;/span&gt;reader.readAsText(firstFileDropped);
        }
    };

    window.DragDropLogic = DragDropLogic;
})();&lt;/pre&gt;

&lt;p&gt;This code is called inside &lt;em&gt;main.js&lt;/em&gt; in the &lt;em&gt;startGame&lt;/em&gt; function:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Callback function once everything has been downloaded
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;startGame() {
    platformerGame = &lt;span style="color: blue"&gt;new &lt;/span&gt;PlatformerGame(stage, contentManager, 800, 480, window.innerWidth, window.innerHeight);
    window.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;resize&amp;quot;&lt;/span&gt;, OnResizeCalled, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    OnResizeCalled();
    &lt;font style="background-color: #ffff00"&gt;DragDropLogic.monitorElement(canvas, platformerGame);
&lt;/font&gt;    platformerGame.StartGame();
}&lt;/pre&gt;

&lt;p&gt;And you’re done! For instance, copy/paste this text block into a new “.txt” file:&lt;/p&gt;

&lt;p&gt;&lt;font color="#008000" face="Courier New"&gt;.................... 
    &lt;br /&gt;.................... 

    &lt;br /&gt;.................... 

    &lt;br /&gt;.1.................. 

    &lt;br /&gt;######.........##### 

    &lt;br /&gt;.................... 

    &lt;br /&gt;.........###........ 

    &lt;br /&gt;.................... 

    &lt;br /&gt;.G.G.GGG.G.G.G...... 

    &lt;br /&gt;.GGG..G..GGG.G...... 

    &lt;br /&gt;.G.G..G..G.G.GGG.... 

    &lt;br /&gt;.................... 

    &lt;br /&gt;.................... 

    &lt;br /&gt;.X................C. 

    &lt;br /&gt;####################&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;And drag’n’drop it in my game. The new level will be normally loaded magically :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0361.image_5F00_3F4419F0.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1537.image_5F00_thumb_5F00_29942439.png" width="450" height="266" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;&lt;font color="#000000"&gt;Video, URL to play this demo &amp;amp; source code&lt;/font&gt;&lt;/strong&gt; &lt;/h2&gt;

&lt;p&gt;Here is a short video of IE10 demonstrating the features implemented in this article:&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="ModernHTML5PlatformerPart2" class="video-js" height="360" width="640" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2.jpg"&gt;&lt;source src="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="640" type="application/x-shockwave-flash" height="360"&gt;  &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  
&lt;param name="allowfullscreen" value="true" /&gt;  
&lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  
&lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   
&lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2.jpg" width="512" height="288" /&gt;   &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart2.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;You can also play with this demo in IE10 or your favorite browser here: &lt;a href="http://david.blob.core.windows.net/modernhtml5platformer/index.html"&gt;Modern HTML5 Platformer&lt;/a&gt;&lt;/p&gt;
&lt;a href="http://david.blob.core.windows.net/modernhtml5platformer/index.html"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4382.image_5F00_7B8C1CD8.png" width="240" height="124" /&gt;&lt;/a&gt; 

&lt;br /&gt;

&lt;p&gt;At last, as you’ve been kind enough to read until the end, you can download the complete source code here: &lt;a title="http://david.blob.core.windows.net/modernhtml5platformer/ModernHTML5PlatformerSourceCode.zip" href="http://david.blob.core.windows.net/modernhtml5platformer/ModernHTML5PlatformerSourceCode.zip"&gt;HTML5 Modern Platformer Source Code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10294464" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/GPU/">GPU</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/CSS3/">CSS3</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Canvas/">Canvas</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/IE10/">IE10</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Drag_2700_n_2700_drop/">Drag'n'drop</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Offline/">Offline</category></item><item><title>Modernisez vos jeux HTML5 canvas partie 1: mise à l’échelle matérielle &amp; CSS3</title><link>http://blogs.msdn.com/b/davrous/archive/2012/04/10/modernisez-vos-jeux-html5-canvas-partie-1-mise-224-l-233-chelle-mat-233-rielle-amp-css3.aspx</link><pubDate>Tue, 10 Apr 2012 18:11:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10292327</guid><dc:creator>David Rousset</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10292327</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/04/10/modernisez-vos-jeux-html5-canvas-partie-1-mise-224-l-233-chelle-mat-233-rielle-amp-css3.aspx#comments</comments><description>&lt;!-- Include the VideoJS Library --&gt;  &lt;p&gt;&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;Les dernières versions des navigateurs commencent à implémenter des versions stables de certaines spécifications HTML5 particulièrement intéressantes comme &lt;strong&gt;Offline APIs, Drag’n’drop &amp;amp; File APIs&lt;/strong&gt;. Ces nouvelles fonctionnalités offrent aux développeurs web de nouveaux scénarios de jeux et nous mène vers une nouvelle ère d’applications web. De notre côté, IE10 les implémente toutes et les mêmes fonctionnalités sont présentes également au sein des applications Windows 8 HTML5 au style Metro. D’un point de vue graphique, le moteur d’IE10 offre une couche d’accélération matérielle pouvant être bien utile pour gérer la mise à l’échelle vers différentes résolutions ainsi que pour jouer des animations de manière fluide. Nous nous concentrerons d’ailleurs en premier lieu sur la partie graphique dans cet article en utilisant &lt;strong&gt;CSS3 Grid, CSS3 Transition, CSS3 3D Transform.&lt;/strong&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;Dans ces 2 articles, nous allons voir comment j’ai utilisé ces nouvelles spécifications pour moderniser mon jeu HTML5 précédent que j’ai nommé &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/03/21/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx"&gt;HTML5 Platformer&lt;/a&gt;. J’espère que ces 2 tutoriaux vous aideront à imaginer de nouvelles choses pour vos propres jeux :&lt;/p&gt;  &lt;p&gt;- Modernisez vos jeux HTML5 canvas partie 1: mise à l’échelle matérielle &amp;amp; CSS3 (cet article)    &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/04/18/modernisez-vos-jeux-html5-canvas-partie-2-offline-api-drag-n-drop-amp-file-api.aspx"&gt;Modernisez vos jeux HTML5 canvas partie 2: Offline APIs, File APIs &amp;amp; Drag’n’drop APIs&lt;/a&gt; (prochain article)&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/strong&gt; vous trouverez l’URL de la démo complète pour la jouer au sein de votre navigateur préféré à la fin de cet article ainsi qu’une vidéo du résultat dans IE10. Le code source sera disponible au téléchargement à la fin du prochain article. Le jeu a été testé avec succès sous IE10, Firefox 11, Chrome 18 et Opera 12.&lt;/p&gt;  &lt;h2&gt;Gérer la mise à l’échelle sur tous les périphériques &lt;/h2&gt;  &lt;p&gt;Si vous développez un jeu en HTML5, c’est probablement parce que vous êtes intéressé par la nature cross-plateformes de ce standard. Mais faire tourner du code sur une grande variété de périphériques soulève rapidement la question de la gestion de leurs multiples résolutions. Or, comparé à SVG, Canvas peut apparaitre rapidement comme mal préparé à ce scénario.&lt;/p&gt;  &lt;p&gt;Heureusement, avec des jeux dit “casuals” basés sur des sprites, il y a une solution simple que vous pouvez implémenter qui apporte un niveau de qualité graphique souvent satisfaisant. Cela a d’ailleurs été très bien décrit par mon ami David Catuhe sur son blog ici: &lt;a title="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/23/lib-233-rez-la-puissance-du-canvas-de-html5-pour-vos-jeux-partie-1.aspx" href="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/23/lib-233-rez-la-puissance-du-canvas-de-html5-pour-vos-jeux-partie-1.aspx"&gt;Libérez la puissance du canvas de HTML5 pour vos jeux&lt;/a&gt; dans la section “&lt;em&gt;utilisation du redimensionnement matériel&lt;/em&gt;”. &lt;/p&gt;  &lt;p&gt;L’idée est plutôt simple et efficace. Vous travaillez dans un canvas de taille fixe avec une résolution prédictible et vous l’étirez à la résolution courante en jouant sur les propriétés de canvas.style.&lt;/p&gt;  &lt;h3&gt;Etape 1: étirer&lt;/h3&gt;  &lt;p&gt;Dans mon cas, avec mon petit jeu de plateforme HTML5, les ressources graphiques et la logique du jeu ont été pensées pour une résolution de 800x480. Donc si je veux remplir un écran 1080p ou une tablette de 1366x768, j’aurais besoin de fabriquer des sprites d’une résolution plus haute. Sinon, on peut mettre en place une opération de mise à l’échelle qui, combinée à un bon anti-crénelage, peut apporter suffisamment de qualité. Ok, testons cette solution !&lt;/p&gt;  &lt;p&gt;Cette opération peut être simplement réalisée grâce à ce code :&lt;/p&gt;  &lt;pre class="code"&gt;window.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;resize&amp;quot;&lt;/span&gt;, OnResizeCalled, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

&lt;span style="color: blue"&gt;function &lt;/span&gt;OnResizeCalled() {
    canvas.style.width = window.innerWidth + &lt;span style="color: maroon"&gt;'px'&lt;/span&gt;;
    canvas.style.height = window.innerHeight + &lt;span style="color: maroon"&gt;'px'&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Ou de manière encore plus simple via cette règle CSS :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#canvas 
&lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Mais vous comprendrez plus tard pourquoi je m’enregistre au près de l’évènement &lt;em&gt;resize&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;A part ça, c’est tout ! Grâce aux nouveaux navigateurs utilisant l’accélération matérielle, cette opération est effectuée par votre GPU gratuitement. Vous aurez même un anti-crénelage d’activé. En effet, l’opération de mise à l’échelle est simplement faite par le GPU grâce aux 100% appliqués aux propriétés &lt;em&gt;width&lt;/em&gt; &amp;amp; &lt;em&gt;height&lt;/em&gt;. Les navigateurs récents s’occuperont également d’appliquer un filtre d’anti-crénelage pour vous lors de cette mise à l’échelle. C’est pourquoi mon collègue David Catuhe en parlait dans &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/23/lib-233-rez-la-puissance-du-canvas-de-html5-pour-vos-jeux-partie-1.aspx"&gt;son article dédié aux performances de canvas&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;D’ailleurs, cela n’est pas spécifique à HTML5 au passage. La plupart des jeux tournant sur les consoles modernes ne sont pas calculés en interne en 720p ou 1080p. La quasi-totalité d’entre eux sont rendus dans des résolutions plus petites (comme 1024x600 par exemple) et ils laissent la puce vidéo faire le processus de mise à l’échelle/anti-crénelage. Cela peut vous aider à augmenter les FPS dans la plupart des cas mais baisse légèrement la qualité graphique en contre partie.&lt;/p&gt;

&lt;p&gt;Cependant, se contenter de faire cela pose un problème de ratio. En effet, quand mon canvas avait une résolution fixe de 800x480, son ratio était naturellement fixé et sous contrôle. Mais maintenant, lorsque je redimensionne la fenêtre du navigateur, je peux obtenir ce genre de résultats pour le moins étrange :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7282.image_5F00_06D2A438.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3580.image_5F00_thumb_5F00_31B48967.png" width="116" height="240" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5670.image_5F00_5151B919.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8272.image_5F00_thumb_5F00_5F9491C4.png" width="640" height="161" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Le jeu reste jouable mais l’expérience est loin d’être optimale.&lt;/p&gt;

&lt;h3&gt;Etape 2: contrôler le ratio&lt;/h3&gt;

&lt;p&gt;L’idée ici est de contrôler la manière de remplir l’écran lorsque la fenêtre du navigateur sera redimensionnée. Plutôt que d’étirer complètement sur toute la largeur et la hauteur, nous allons ajouter de l’espace à droite si la fenêtre est trop large ou en dessous si la fenêtre est trop haute. Cela est effectué grâce à ce code dans mon cas :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;gameWidth = window.innerWidth;
&lt;span style="color: blue"&gt;var &lt;/span&gt;gameHeight = window.innerHeight;
&lt;span style="color: blue"&gt;var &lt;/span&gt;scaleToFitX = gameWidth / 800;
&lt;span style="color: blue"&gt;var &lt;/span&gt;scaleToFitY = gameHeight / 480;

&lt;span style="color: blue"&gt;var &lt;/span&gt;currentScreenRatio = gameWidth / gameHeight;
&lt;span style="color: blue"&gt;var &lt;/span&gt;optimalRatio = Math.min(scaleToFitX, scaleToFitY);

&lt;span style="color: blue"&gt;if &lt;/span&gt;(currentScreenRatio &amp;gt;= 1.77 &amp;amp;&amp;amp; currentScreenRatio &amp;lt;= 1.79) {
    canvas.style.width = gameWidth + &lt;span style="color: maroon"&gt;&amp;quot;px&amp;quot;&lt;/span&gt;;
    canvas.style.height = gameHeight + &lt;span style="color: maroon"&gt;&amp;quot;px&amp;quot;&lt;/span&gt;;
}
&lt;span style="color: blue"&gt;else &lt;/span&gt;{
    canvas.style.width = 800 * optimalRatio + &lt;span style="color: maroon"&gt;&amp;quot;px&amp;quot;&lt;/span&gt;;
    canvas.style.height = 480 * optimalRatio + &lt;span style="color: maroon"&gt;&amp;quot;px&amp;quot;&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;J’ai ajouté une exception grâce au “if”. En effet, si vous pressez la touche F11 de votre navigateur pour basculer en plein écran et que vous utilisez un écran 16/9 (comme mon écran 1920x1080 de mon Vaio Z ou 1366x768 d’une tablette Samsung), le jeu sera entièrement étiré. J’ai trouvé que le résultat fournissait une expérience super cool. &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1803.wlEmoticon_2D00_winkingsmile_5F00_2D17484E.png" /&gt;&lt;/p&gt;

&lt;p&gt;A part cette exception, voici le type de résultat que vous devriez avoir:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5023.image_5F00_18BC7C84.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1614.image_5F00_thumb_5F00_23A10FDF.png" width="240" height="189" /&gt;&lt;/a&gt; &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0677.image_5F00_754A1AE2.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0576.image_5F00_thumb_5F00_40675869.png" width="359" height="189" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remarquez les bandes noires en dessous et sur la droite du jeu. Elles sont ici pour contrôler notre ratio. Mais ça serait encore plus cool si le jeu était centré pour avoir un effet type écran large/cinémascope non?&lt;/p&gt;

&lt;h3&gt;Etape 3: centrer le jeu avec CSS3 Grid&lt;/h3&gt;

&lt;p&gt;Centrer un élément HTML peut être une tâche compliquée dans certains scénarios. Il y a plusieurs façons d’opérer et vous trouverez des tas de ressources bien faites sur le web pour vous aider. J’aimerais utiliser ici une nouvelle spécification nommée &lt;a href="http://dev.w3.org/csswg/css3-grid-layout/"&gt;CSS Grid Layout&lt;/a&gt; actuellement uniquement supportée par IE10 et qui représente la base de notre nouvelle mise en page Metro dans Windows 8. Grâce à cette nouvelle spécification, centrer un élément est l’enfance de l’art. Il vous suffit de basculer le &lt;em&gt;display&lt;/em&gt; du conteneur de votre élément en &lt;em&gt;display:grid&lt;/em&gt;, de définir 1 colonne et 1 ligne puis de centrer l’élément intérieur avec les propriétés &lt;em&gt;column-align&lt;/em&gt; et &lt;em&gt;row-align&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Voici le CSS utilisé dans mon cas:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;.canvasHolder &lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;display&lt;/span&gt;: &lt;span style="color: blue"&gt;-ms-grid&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-columns&lt;/span&gt;: &lt;span style="color: blue"&gt;1fr&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-rows&lt;/span&gt;: &lt;span style="color: blue"&gt;1fr&lt;/span&gt;;
}

&lt;span style="color: maroon"&gt;#platformerCanvas &lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-grid-column&lt;/span&gt;: &lt;span style="color: blue"&gt;1&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row&lt;/span&gt;: &lt;span style="color: blue"&gt;1&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-column-align&lt;/span&gt;: &lt;span style="color: blue"&gt;center&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row-align&lt;/span&gt;: &lt;span style="color: blue"&gt;center&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Vous aurez remarqué que c’est actuellement préfixé par “-ms” pour IE10. &lt;a href="http://hacks.mozilla.org/2012/03/firefox-in-2011-firefox-plans-for-2012/"&gt;Mozilla a récemment annoncé&lt;/a&gt; qu’ils supporteront également la spécification dans Firefox en 2012. C’est une excellente nouvelle ! En attendant, cette solution ne marche que sous IE10 et voici le type de résultat que vous aurez avec ce navigateur :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6507.image_5F00_46AE7E6E.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5047.image_5F00_thumb_5F00_6FDDC8BF.png" width="208" height="180" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0702.image_5F00_21D7F9FB.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3010.image_5F00_thumb_5F00_27703756.png" width="291" height="180" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2806.image_5F00_7FCC4BDC.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2500.image_5F00_thumb_5F00_745DCAA3.png" width="360" height="180" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dans IE10, comme avec votre écran large, vous aurez ainsi des barres verticales ou horizontales en fonction de la taille de la fenêtre. Sur les autres navigateurs, vous aurez le même résultat qu’à l’étape 2 car la spécification CSS3 Grid Layout sera simplement ignorée. &lt;/p&gt;

&lt;h2&gt;Mise en place d’animations fluides &lt;/h2&gt;

&lt;p&gt;Maintenant que nous gérons de multiples résolutions possibles via une opération de mise à l’échelle, il serait aussi sympa de jouer une transition fluide lorsque l’utilisateur redimensionne la fenêtre. Il serait aussi cool d’avoir une animation sympatôche entre chaque niveau de jeu. Pour cela, nous ferons usage de CSS3 Transitions &amp;amp; CSS3 3D Transforms. Cela a le bon gout d’être à nouveau accéléré matériellement par la plupart des plateformes.&lt;/p&gt;

&lt;h3&gt;Animation des changements effectués sur chacune des propriétés du canvas&lt;/h3&gt;

&lt;p&gt;CSS3 Transitions est facile à utiliser et produit des animations efficaces &amp;amp; fluides. Si vous souhaitez découvrir comme les utiliser, vous pouvez lire l’excellente introduction de mon collègue David: &lt;a title="http://blogs.msdn.com/b/eternalcoding/archive/2011/12/06/fr-introduction-224-css3-transitions.aspx" href="http://blogs.msdn.com/b/eternalcoding/archive/2011/12/06/fr-introduction-224-css3-transitions.aspx"&gt;Introduction aux transitions CSS3&lt;/a&gt; ou jouez avec directement sur notre site IE Test Drive:&amp;#160; &lt;a title="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_transitions.htm" href="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_transitions.htm"&gt;Hands On transitions&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Dans mon cas, j’ai mis en place une transition globale sur l’ensemble des propriétés de mon canvas grâce à ces règles:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#platformerCanvas &lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-grid-column&lt;/span&gt;: &lt;span style="color: blue"&gt;1&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row&lt;/span&gt;: &lt;span style="color: blue"&gt;1&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-column-align&lt;/span&gt;: &lt;span style="color: blue"&gt;center&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row-align&lt;/span&gt;: &lt;span style="color: blue"&gt;center&lt;/span&gt;;

    &lt;span style="color: red"&gt;-ms-transition-property&lt;/span&gt;: &lt;span style="color: blue"&gt;all&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-transition-duration&lt;/span&gt;: &lt;span style="color: blue"&gt;1s&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-transition-timing-function&lt;/span&gt;: &lt;span style="color: blue"&gt;ease&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Le canvas avec l’identifiant “&lt;em&gt;platformerCanvas&lt;/em&gt;” s’occupera maintenant automatiquement de prendre en compte chacun des changements effectués à ses propriétés via une animation d’1 seconde via une fonction “d’easing”. Désormais, grâce à nette nouvelle règle, si vous redimensionnez la fenêtre du navigateur, une animation sera jouée pour réduire/agrandir la taille du canvas. J’adore l’effet que cela produit. Et tout cela en n’ajoutant finalement que 3 lignes de CSS! Les transitions CSS sont vraiment épatantes pour cela.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; j’ai également ajouté dans mon code les prefixes –moz, –webkit &amp;amp; –o pour Mozilla, Webkit &amp;amp; Opera afin d’être compatible avec le plus grand nombre de navigateurs. N’oubliez jamais de faire la même chose et ne laissez pas un navigateur sur le carreau!&lt;/p&gt;

&lt;h3&gt;Mise en place d’une animation cool entre chaque niveau&lt;/h3&gt;

&lt;p&gt;J’aimerais maintenant utiliser CSS3 3D Transform pour faire disparaitre temporairement mon canvas. Cela se fera via une animation d’une rotation de 90 degrés sur l’axe des Y. Ensuite, nous chargerons le niveau suivant une fois que l’animation aura atteinte les 90° pour finalement revenir à l’état initial de 0°. Pour mieux comprendre l’effet que j’essaie péniblement de vous décrire à l’écrit, le mieux est de jouer avec notre démo &lt;a title="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_3d-transforms.htm" href="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_3d-transforms.htm"&gt;Hands On 3D Transforms&lt;/a&gt; sur notre site IE Test Drive:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_3d-transforms.htm"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8255.image64_5F00_2757DF37.png" width="640" height="331" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nous allons également jouer avec la propriété “&lt;em&gt;scale&lt;/em&gt;” en conjonction de la propriété “&lt;em&gt;rotateY&lt;/em&gt;” pour fabriquer notre animation. Pour cela, je vous propose d’ajouter ces 2 règles CSS visant 2 classes particulières:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;.moveRotation
&lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(500px) rotateY(-90deg) scale(0.1)&lt;/span&gt;;
    &lt;span style="color: red"&gt;-webkit-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(500px) scale(0)&lt;/span&gt;;
    &lt;span style="color: red"&gt;-moz-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(500px) rotateY(-90deg) scale(0.1)&lt;/span&gt;;
    &lt;span style="color: red"&gt;-o-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;scale(0)&lt;/span&gt;;
}

&lt;span style="color: maroon"&gt;.initialRotation
&lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(500px) rotateY(0deg) scale(1)&lt;/span&gt;;
    &lt;span style="color: red"&gt;-webkit-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(500px) scale(1)&lt;/span&gt;;
    &lt;span style="color: red"&gt;-moz-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(500px) rotateY(0deg) scale(1)&lt;/span&gt;;
    &lt;span style="color: red"&gt;-o-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;scale(1)&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Mon canvas aura alors la classe &lt;em&gt;initialRotation&lt;/em&gt; en 1er lieu:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;canvas &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;platformerCanvas&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;800&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;480&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;initialRotation&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;canvas&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Maintenant l’idée est d’attendre que le joueur ait gagné le niveau courant. Une fois fait, nous allons changer la classe du canvas de &lt;em&gt;initialRotation&lt;/em&gt; à &lt;em&gt;moveRotation&lt;/em&gt;. Cela aura pour effet de déclencher automatiquement la transition CSS mise en place précédemment et travaillant sur toutes les propriétés.&lt;/p&gt;

&lt;p&gt;Afin de savoir si l’animation est terminée, il y a un évènement qui est levé. Il est nommé différemment dans chaque navigateur pour l’instant. Voici mon code s’occupant de s’enregistrer à cet évènement et visant IE10, Firefox, Webkit &amp;amp; Opera:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Registering to the various browsers vendors transition end event
&lt;/span&gt;PlatformerGame.prototype.registerTransitionEndEvents = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: #006400"&gt;// IE10, Firefox, Chrome &amp;amp; Safari, Opera
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSTransitionEnd&amp;quot;&lt;/span&gt;, onTransitionEnd(&lt;span style="color: blue"&gt;this&lt;/span&gt;));
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;transitionend&amp;quot;&lt;/span&gt;, onTransitionEnd(&lt;span style="color: blue"&gt;this&lt;/span&gt;));
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;webkitTransitionEnd&amp;quot;&lt;/span&gt;, onTransitionEnd(&lt;span style="color: blue"&gt;this&lt;/span&gt;));
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;oTransitionEnd&amp;quot;&lt;/span&gt;, onTransitionEnd(&lt;span style="color: blue"&gt;this&lt;/span&gt;));
};&lt;/pre&gt;

&lt;p&gt;Et voici le morceau de code qui sera rappelé:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Function called when the transition has ended
// We're then loading the next level
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;onTransitionEnd(instance) {
    &lt;span style="color: blue"&gt;return function &lt;/span&gt;() {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(instance.loadNextLevel === &lt;span style="color: blue"&gt;true&lt;/span&gt;) {
            instance.LoadNextLevel();
        }
    }
};&lt;/pre&gt;

&lt;p&gt;Pour finir, voici le code de mon jeu qui positionne la classe &lt;em&gt;moveRotation&lt;/em&gt; sur le canvas:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Perform the appropriate action to advance the game and
// to get the player back to playing.
&lt;/span&gt;PlatformerGame.prototype.HandleInput = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: blue"&gt;this&lt;/span&gt;.wasContinuePressed &amp;amp;&amp;amp; &lt;span style="color: blue"&gt;this&lt;/span&gt;.continuePressed) {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: blue"&gt;this&lt;/span&gt;.level.Hero.IsAlive) {
            &lt;span style="color: blue"&gt;this&lt;/span&gt;.level.StartNewLife();
        }
        &lt;span style="color: blue"&gt;else if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.level.TimeRemaining == 0) {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.level.ReachedExit) {
                &lt;span style="color: #006400"&gt;// If CSS3 Transitions is supported
                // We're using smooth &amp;amp; nice effects between each levels
                &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(Modernizr.csstransitions) {
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.loadNextLevel = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
                    &lt;span style="color: #006400"&gt;// Setting the moveRotation class will trigger the css transition
                    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.className = &lt;span style="color: maroon"&gt;&amp;quot;moveRotation&amp;quot;&lt;/span&gt;;
                }
                &lt;span style="color: #006400"&gt;// If CSS3 Transition is not supported, we're jumping directly
                // to the next level
                &lt;/span&gt;&lt;span style="color: blue"&gt;else &lt;/span&gt;{
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.LoadNextLevel();
                }
            }
            &lt;span style="color: blue"&gt;else
                this&lt;/span&gt;.ReloadCurrentLevel();
        }
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.removeChild(statusBitmap);
        overlayDisplayed = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
    }

    &lt;span style="color: blue"&gt;this&lt;/span&gt;.wasContinuePressed = &lt;span style="color: blue"&gt;this&lt;/span&gt;.continuePressed;
};&lt;/pre&gt;

&lt;p&gt;Vous remarquerez que j’utilise &lt;a href="http://modernizr.com/"&gt;Modernizr&lt;/a&gt; pour faire de la détection de fonctionnalité des transition CSS. Ensuite, nous remettons finalement en place la classe &lt;em&gt;initialRotation &lt;/em&gt;dans la fonction &lt;em&gt;LoadNextLevel&lt;/em&gt; :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Loading the next level 
&lt;/span&gt;PlatformerGame.prototype.LoadNextLevel = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.loadNextLevel = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
    &lt;span style="color: #006400"&gt;// Setting back the initialRotation class will trigger the transition
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.className = &lt;span style="color: maroon"&gt;&amp;quot;initialRotation&amp;quot;&lt;/span&gt;;
    &lt;span style="color: #006400"&gt;// ... loadNextLevel logic stuff...
&lt;/span&gt;};&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; vous aurez peut-être remarqué que je n’utilise pas la même transformation (et donc la même animation) pour WebKit que pour IE10 et Firefox dans le bloc de CSS précédent. C’est dû au fait que Chrome ne se comporte pas de la même manière qu’IE10 et Firefox 11 dans mon cas. J’ai poussé une petite repro sur jsFiddle ici: &lt;a title="http://jsfiddle.net/5H8wg/2/" href="http://jsfiddle.net/5H8wg/2/"&gt;http://jsfiddle.net/5H8wg/2/&lt;/a&gt; si vous souhaitez y jeter un œil. Opera ne supporte pas CSS3 3D Transform pour le moment.&lt;/p&gt;

&lt;h2&gt;Vidéo &amp;amp; URL pour jouer avec la démo&lt;/h2&gt;

&lt;p&gt;Voici une courte vidéo vous démontrant le résultat de toutes ces fonctionnalités au sein d’IE10:&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="ModernHTML5PlatformerPart1FR" class="video-js" height="360" width="640" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1FR.jpg"&gt;&lt;source src="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1FR.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1FR.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="640" type="application/x-shockwave-flash" height="360"&gt;  
 &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  
 &lt;param name="allowfullscreen" value="true" /&gt;  
 &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1FR.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1FR.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  
 &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   
 &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1FR.jpg" width="512" height="288" /&gt;   
 &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt;&lt;a href="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1FR.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1FR.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Vous pouvez aussi jouer avec cette démo dans IE10 ou votre navigateur préféré ici: &lt;a title="http://david.blob.core.windows.net/modernhtml5platformer/index.html" href="http://david.blob.core.windows.net/modernhtml5platformer/index.html"&gt;Modern HTML5 Platformer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://david.blob.core.windows.net/modernhtml5platformer/index.html"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4382.image_5F00_7B8C1CD8.png" width="240" height="124" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dans &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/04/18/modernisez-vos-jeux-html5-canvas-partie-2-offline-api-drag-n-drop-amp-file-api.aspx"&gt;le 2ème article&lt;/a&gt;, nous allons voir comment j’ai implémenté les API gérant le mode déconnecté pour faire fonctionner le jeu même en l’absence de connexion réseau. Nous verrons aussi comme j’ai utilisé les API de manipulation de fichiers et de la gestion du glisser/déposer pour implémenter une fonctionnalité amusante.&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10292327" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/GPU/">GPU</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Canvas/">Canvas</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/IE10/">IE10</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/EaselJS/">EaselJS</category></item><item><title>Modernizing your HTML5 Canvas games Part 1: hardware scaling &amp; CSS3</title><link>http://blogs.msdn.com/b/davrous/archive/2012/04/06/modernizing-your-html5-canvas-games-with-offline-apis-file-apis-css3-amp-hardware-scaling.aspx</link><pubDate>Fri, 06 Apr 2012 16:15:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10291483</guid><dc:creator>David Rousset</dc:creator><slash:comments>10</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10291483</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/04/06/modernizing-your-html5-canvas-games-with-offline-apis-file-apis-css3-amp-hardware-scaling.aspx#comments</comments><description>&lt;!-- Include the VideoJS Library --&gt;  &lt;p&gt;&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;&lt;/p&gt;  &lt;p&gt;Latest versions of the browsers start to implement stable version of very interesting HTML5 features like&lt;strong&gt; Offline APIs, Drag’n’drop &amp;amp; File APIs&lt;/strong&gt;. Those new features offer new gaming scenarios for the web developers and bring us to a new web application era. On our side, IE10 implements all of them and the same features are also available inside Windows 8 HTML5 Metro Style Apps. On the graphics’ side, the IE10 engine offers also a powerful hardware acceleration graphics layer than could be very useful for handling various resolutions scaling and playing smooth animations. We will concentrate first on this graphics part in this article by using &lt;strong&gt;CSS3 Grid, CSS3 Transition, CSS3 3D Transform&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;In these 2 articles, we’ll see how I’ve used these new features to modernize my previous HTML5 game named &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/03/21/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx"&gt;HTML5 Platformer&lt;/a&gt;. I hope that these 2 tutorials will bring you some new ideas for your own games.&lt;/p&gt;  &lt;p&gt;- Modernizing your HTML5 Canvas games Part 1: hardware scaling &amp;amp; CSS3 (this article)    &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/04/17/modernizing-your-html5-canvas-games-part-2-offline-api-drag-n-drop-amp-file-api.aspx"&gt;Modernizing your HTML5 Canvas games Part 2: Offline APIs, File APIs &amp;amp; Drag’n’drop APIs&lt;/a&gt; (next article)&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; You’ll find the URL of the complete demo to play with your favorite browser at the end of this article as well as a video of the result inside IE10.&amp;#160; The source code will be available for download at the end of the next article. The game has been tested with success under IE10, Firefox 11, Chrome 18 and Opera 12.&lt;/p&gt;  &lt;h2&gt;Scaling across devices&lt;/h2&gt;  &lt;p&gt;If you’re building a HTML5 game, it’s probably because you’re interested in the cross-platform nature of this standard. But running on a huge variety of devices raises the question of the variety of resolutions. Compared to SVG, Canvas could be first seen as not very well prepared for this scenario. &lt;/p&gt;  &lt;p&gt;Hopefully, with a casual-like game based on sprites, there is a simple solution to implement. It has been very well described by my friend David Catuhe on his blog here: &lt;a title="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/22/unleash-the-power-of-html-5-canvas-for-gaming-part-1.aspx" href="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/22/unleash-the-power-of-html-5-canvas-for-gaming-part-1.aspx"&gt;Unleash the power of HTML 5 Canvas for gaming – Part 1&lt;/a&gt; in the “using the hardware scaling feature” section.&lt;/p&gt;  &lt;p&gt;The idea is pretty simple &amp;amp; smart. You’re working inside a canvas at a fix &amp;amp; predictable resolution and you’re stretching it to the current displayed resolution using the canvas.style properties. &lt;/p&gt;  &lt;h3&gt;Step 1: stretch&lt;/h3&gt;  &lt;p&gt;In my case with my little HTML5 Platformer game, the assets &amp;amp; level logics have been set with a 800x480 resolution in mind. So, if I’d like to fill a complete 1080p screen or a 1366x768 tablet, I need to build higher resolution assets to match these resolutions. Otherwise, I can use a scaling operation which, combined with proper anti-aliasing, could provide enough quality. Let’s try this. &lt;/p&gt;  &lt;p&gt;This scaling operation is simply done by this code:&lt;/p&gt;  &lt;pre class="code"&gt;window.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;resize&amp;quot;&lt;/span&gt;, OnResizeCalled, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

&lt;span style="color: blue"&gt;function &lt;/span&gt;OnResizeCalled() {
    canvas.style.width = window.innerWidth + &lt;span style="color: maroon"&gt;'px'&lt;/span&gt;;
    canvas.style.height = window.innerHeight + &lt;span style="color: maroon"&gt;'px'&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Or even simpler via a CSS rule like:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#canvas 
&lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;But you’ll understand later on why I’m registering to the &lt;em&gt;resize&lt;/em&gt; event of the window.&lt;/p&gt;

&lt;p&gt;And that’s it! With hardware accelerated browsers, this operation will be done by your GPU at no cost! You will even have anti-aliasing enabled. Indeed, the scaling operation is done by the GPU thanks to the 100% applied to the width &amp;amp; height properties. Recent browsers also automatically apply an anti-aliasing algorithm for you. That’s why, David Catuhe was mentioning it in &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/22/unleash-the-power-of-html-5-canvas-for-gaming-part-1.aspx"&gt;his canvas performance article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This is not specific to HTML5 by the way. Most of the modern console games are not internally computed in 720p or 1080p. Almost all of them render the game in lower resolutions (such as 1024x600 for instance) and let the GPU doing the scaling/anti-aliasing process. This could help you boosting the FPS in most cases. &lt;/p&gt;

&lt;p&gt;But simply doing that raises a ratio problem. Indeed, when the canvas had a fix size of 800x480, the ratio was controlled. Now, I can obtain this strange output while resizing the browser’s window:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7282.image_5F00_06D2A438.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3580.image_5F00_thumb_5F00_31B48967.png" width="116" height="240" /&gt;&lt;/a&gt;&amp;#160;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5670.image_5F00_5151B919.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8272.image_5F00_thumb_5F00_5F9491C4.png" width="640" height="161" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The game is still playable but the experience is far from being optimal.&lt;/p&gt;

&lt;h3&gt;Step 2: control your ratio&lt;/h3&gt;

&lt;p&gt;The idea here is to control how to fill the screen when the browser’s window is resized. Rather than fully stretching, we’re going to add some empty space on the right if the window is too large or at the bottom if the window is too high. This is done by this code in my case:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;gameWidth = window.innerWidth;
&lt;span style="color: blue"&gt;var &lt;/span&gt;gameHeight = window.innerHeight;
&lt;span style="color: blue"&gt;var &lt;/span&gt;scaleToFitX = gameWidth / 800;
&lt;span style="color: blue"&gt;var &lt;/span&gt;scaleToFitY = gameHeight / 480;

&lt;span style="color: blue"&gt;var &lt;/span&gt;currentScreenRatio = gameWidth / gameHeight;
&lt;span style="color: blue"&gt;var &lt;/span&gt;optimalRatio = Math.min(scaleToFitX, scaleToFitY);

&lt;span style="color: blue"&gt;if &lt;/span&gt;(currentScreenRatio &amp;gt;= 1.77 &amp;amp;&amp;amp; currentScreenRatio &amp;lt;= 1.79) {
    canvas.style.width = gameWidth + &lt;span style="color: maroon"&gt;&amp;quot;px&amp;quot;&lt;/span&gt;;
    canvas.style.height = gameHeight + &lt;span style="color: maroon"&gt;&amp;quot;px&amp;quot;&lt;/span&gt;;
}
&lt;span style="color: blue"&gt;else &lt;/span&gt;{
    canvas.style.width = 800 * optimalRatio + &lt;span style="color: maroon"&gt;&amp;quot;px&amp;quot;&lt;/span&gt;;
    canvas.style.height = 480 * optimalRatio + &lt;span style="color: maroon"&gt;&amp;quot;px&amp;quot;&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;I’ve added an exception with the if statement. If you’re pressing F11 in your browser to switch in full screen and you’ve got a 16/9 screen (like my 1920x1080 Vaio Z screen or the 1366x768 Samsung BUILD tablet), the game will be completely stretched. I’ve found that this experience was quite awesome. &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1030.wlEmoticon_2D00_winkingsmile_5F00_6ED47BAE.png" /&gt;&lt;/p&gt;

&lt;p&gt;Otherwise, here is the kind of output you’ll now have:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5023.image_5F00_18BC7C84.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1614.image_5F00_thumb_5F00_23A10FDF.png" width="240" height="189" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0677.image_5F00_754A1AE2.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0576.image_5F00_thumb_5F00_40675869.png" width="359" height="189" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice the black areas below or on the right of the game. It’s here to control our ratio. But it would be better if the game was centered to have a widescreen movie effect, wouldn’t be?&lt;/p&gt;

&lt;h3&gt;Step 3: center the game with CSS3 Grid&lt;/h3&gt;

&lt;p&gt;Centering an HTML element could be painful in certain scenarios. There is several ways to do that and you’ll find plenty of resources on the web to help you. I’d like to use a new specification named &lt;a href="http://dev.w3.org/csswg/css3-grid-layout/"&gt;CSS Grid Layout&lt;/a&gt; currently only supported by IE10 and which is the base of our Metro Style layout in Windows 8. Centering an element with CSS Grid is straightforward. You just have to switch the display of the container to display:grid, define 1 column &amp;amp; 1 row and center the inner element with the colum-align &amp;amp; row-align properties.&lt;/p&gt;

&lt;p&gt;Here the the CSS used in my case:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;.canvasHolder &lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;display&lt;/span&gt;: &lt;span style="color: blue"&gt;-ms-grid&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-columns&lt;/span&gt;: &lt;span style="color: blue"&gt;1fr&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-rows&lt;/span&gt;: &lt;span style="color: blue"&gt;1fr&lt;/span&gt;;
}

&lt;span style="color: maroon"&gt;#platformerCanvas &lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-grid-column&lt;/span&gt;: &lt;span style="color: blue"&gt;1&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row&lt;/span&gt;: &lt;span style="color: blue"&gt;1&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-column-align&lt;/span&gt;: &lt;span style="color: blue"&gt;center&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row-align&lt;/span&gt;: &lt;span style="color: blue"&gt;center&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;You’ll notice it’s currently prefixed by “-ms” for IE10. &lt;a href="http://hacks.mozilla.org/2012/03/firefox-in-2011-firefox-plans-for-2012/"&gt;Mozilla has recently annonced&lt;/a&gt;&amp;#160; they will also support the specification in Firefox in 2012 which is excellent news! In the meantime, this solution currently only works with IE10 and here is the kind of output generated:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6507.image_5F00_46AE7E6E.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5047.image_5F00_thumb_5F00_6FDDC8BF.png" width="208" height="180" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0702.image_5F00_21D7F9FB.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3010.image_5F00_thumb_5F00_27703756.png" width="291" height="180" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2806.image_5F00_7FCC4BDC.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2500.image_5F00_thumb_5F00_745DCAA3.png" width="360" height="180" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In IE10, like on your TV screen, you will have vertical or horizontal black bars. On the other browsers, you will have the same result as the step 2 as the CSS3 Grid Layout will be simply ignored by them. &lt;/p&gt;

&lt;h2&gt;Using Smooth Animations &lt;/h2&gt;

&lt;p&gt;Now that we’re handling multiple resolutions via an easy scaling operation, it would be nice to play a smooth transition when the user is resizing the window. It would be nice also to play a cool animation during each level loading. For that, we’re going to use CSS3 Transitions &amp;amp; CSS3 3D Transforms. It’s hardware accelerated by the GPU on most platforms. &lt;/p&gt;

&lt;h3&gt;Animating every change done to the canvas style properties&lt;/h3&gt;

&lt;p&gt;CSS3 Transitions is easy to use and produce efficient &amp;amp; smooth animations. If you’d like to discover how to use them, you can read my colleague’s excellent introduction article: &lt;a title="http://blogs.msdn.com/b/eternalcoding/archive/2011/12/06/css3-transitions.aspx" href="http://blogs.msdn.com/b/eternalcoding/archive/2011/12/06/css3-transitions.aspx"&gt;Introduction to CSS3 Transitions&lt;/a&gt; or play with it on our IE Test Drive: &lt;a title="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_transitions.htm" href="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_transitions.htm"&gt;Hands On transitions&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In my case, I’ve setup a global transition on all my canvas’ properties thanks to these rules:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#platformerCanvas &lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-grid-column&lt;/span&gt;: &lt;span style="color: blue"&gt;1&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row&lt;/span&gt;: &lt;span style="color: blue"&gt;1&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-column-align&lt;/span&gt;: &lt;span style="color: blue"&gt;center&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row-align&lt;/span&gt;: &lt;span style="color: blue"&gt;center&lt;/span&gt;;

    &lt;span style="color: red"&gt;-ms-transition-property&lt;/span&gt;: &lt;span style="color: blue"&gt;all&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-transition-duration&lt;/span&gt;: &lt;span style="color: blue"&gt;1s&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-transition-timing-function&lt;/span&gt;: &lt;span style="color: blue"&gt;ease&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;The canvas with the id “&lt;em&gt;platformerCanvas&lt;/em&gt;” will now automatically reflect any change done to its style’s properties via a 1s animation using an easing function. Now, thanks to this new rule, if you’re resizing the browser’s window, a smooth animation will be played to reduce/grow the the size of the canvas. I love the effect produced. Just by adding only 3 lines of CSS! CSS3 transition is really awesome for that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; I’ve also added the prefixes versions –moz, –webkit &amp;amp; –o for Mozilla, Webkit &amp;amp; Opera to be compatible with the other browsers. Never forget to do the same!&lt;/p&gt;

&lt;h3&gt;Building a cool animation between each level&lt;/h3&gt;

&lt;p&gt;I’d like now to use CSS3 3D Transform to disappear temporally the canvas. This will be done via an animation of a 90 degrees rotation on the Y axis. Then, we will load the next level once the animation will reach the 90 degrees and come back to the initial state of 0 degree. To better understand the effect, you can play with our &lt;a title="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_3d-transforms.htm" href="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_3d-transforms.htm"&gt;Hands On 3D Transforms&lt;/a&gt; on the IE Test Drive site :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_3d-transforms.htm"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8255.image64_5F00_2757DF37.png" width="640" height="331" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’re going also to play with the scale property in conjunction with the rotateY property to build a fun animation. For that, I’m adding 2 CSS rules targeting 2 classes:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;.moveRotation
&lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(500px) rotateY(-90deg) scale(0.1)&lt;/span&gt;;
    &lt;span style="color: red"&gt;-webkit-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(500px) scale(0)&lt;/span&gt;;
    &lt;span style="color: red"&gt;-moz-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(500px) rotateY(-90deg) scale(0.1)&lt;/span&gt;;
    &lt;span style="color: red"&gt;-o-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;scale(0)&lt;/span&gt;;
}

&lt;span style="color: maroon"&gt;.initialRotation
&lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(500px) rotateY(0deg) scale(1)&lt;/span&gt;;
    &lt;span style="color: red"&gt;-webkit-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(500px) scale(1)&lt;/span&gt;;
    &lt;span style="color: red"&gt;-moz-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(500px) rotateY(0deg) scale(1)&lt;/span&gt;;
    &lt;span style="color: red"&gt;-o-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;scale(1)&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;And my canvas has first the &lt;em&gt;initialRotation&lt;/em&gt; class set:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;canvas &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;platformerCanvas&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;800&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;480&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;initialRotation&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;canvas&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now the idea is to wait until the player has won the current level. Once done, we’re changing the class of the canvas from &lt;em&gt;initialRotation&lt;/em&gt; to &lt;em&gt;moveRotation&lt;/em&gt;. This will then automatically triggers the CSS3 Transition set before to generate the animation.&lt;/p&gt;

&lt;p&gt;In order to know that the animation is finished, there is an event raised. It’s named differently in each browser. Here is my code registering to the event &amp;amp; targeting IE10, Firefox, Webkit &amp;amp; Opera:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Registering to the various browsers vendors transition end event
&lt;/span&gt;PlatformerGame.prototype.registerTransitionEndEvents = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: #006400"&gt;// IE10, Firefox, Chrome &amp;amp; Safari, Opera
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSTransitionEnd&amp;quot;&lt;/span&gt;, onTransitionEnd(&lt;span style="color: blue"&gt;this&lt;/span&gt;));
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;transitionend&amp;quot;&lt;/span&gt;, onTransitionEnd(&lt;span style="color: blue"&gt;this&lt;/span&gt;));
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;webkitTransitionEnd&amp;quot;&lt;/span&gt;, onTransitionEnd(&lt;span style="color: blue"&gt;this&lt;/span&gt;));
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;oTransitionEnd&amp;quot;&lt;/span&gt;, onTransitionEnd(&lt;span style="color: blue"&gt;this&lt;/span&gt;));
};&lt;/pre&gt;

&lt;p&gt;And here is the code that will be call-backed:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Function called when the transition has ended
// We're then loading the next level
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;onTransitionEnd(instance) {
    &lt;span style="color: blue"&gt;return function &lt;/span&gt;() {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(instance.loadNextLevel === &lt;span style="color: blue"&gt;true&lt;/span&gt;) {
            instance.LoadNextLevel();
        }
    }
};&lt;/pre&gt;

&lt;p&gt;At last, here is the code of my game which set the &lt;em&gt;moveRotation&lt;/em&gt; class on the canvas:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Perform the appropriate action to advance the game and
// to get the player back to playing.
&lt;/span&gt;PlatformerGame.prototype.HandleInput = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: blue"&gt;this&lt;/span&gt;.wasContinuePressed &amp;amp;&amp;amp; &lt;span style="color: blue"&gt;this&lt;/span&gt;.continuePressed) {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: blue"&gt;this&lt;/span&gt;.level.Hero.IsAlive) {
            &lt;span style="color: blue"&gt;this&lt;/span&gt;.level.StartNewLife();
        }
        &lt;span style="color: blue"&gt;else if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.level.TimeRemaining == 0) {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.level.ReachedExit) {
                &lt;span style="color: #006400"&gt;// If CSS3 Transitions is supported
                // We're using smooth &amp;amp; nice effects between each levels
                &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(Modernizr.csstransitions) {
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.loadNextLevel = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
                    &lt;span style="color: #006400"&gt;// Setting the moveRotation class will trigger the css transition
                    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.className = &lt;span style="color: maroon"&gt;&amp;quot;moveRotation&amp;quot;&lt;/span&gt;;
                }
                &lt;span style="color: #006400"&gt;// If CSS3 Transition is not supported, we're jumping directly
                // to the next level
                &lt;/span&gt;&lt;span style="color: blue"&gt;else &lt;/span&gt;{
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.LoadNextLevel();
                }
            }
            &lt;span style="color: blue"&gt;else
                this&lt;/span&gt;.ReloadCurrentLevel();
        }
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.removeChild(statusBitmap);
        overlayDisplayed = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
    }

    &lt;span style="color: blue"&gt;this&lt;/span&gt;.wasContinuePressed = &lt;span style="color: blue"&gt;this&lt;/span&gt;.continuePressed;
};&lt;/pre&gt;

&lt;p&gt;Notice that I’m using &lt;a href="http://modernizr.com/"&gt;Modernizr&lt;/a&gt; to do a feature detection of CSS Transitions. We’re finally setting back the &lt;em&gt;initialRotation&lt;/em&gt; class inside the &lt;em&gt;LoadNextLevel&lt;/em&gt; function:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Loading the next level 
&lt;/span&gt;PlatformerGame.prototype.LoadNextLevel = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.loadNextLevel = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
    &lt;span style="color: #006400"&gt;// Setting back the initialRotation class will trigger the transition
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.platformerGameStage.canvas.className = &lt;span style="color: maroon"&gt;&amp;quot;initialRotation&amp;quot;&lt;/span&gt;;
    &lt;span style="color: #006400"&gt;// ... loadNextLevel logic stuff...
&lt;/span&gt;};&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; you may have noticed that I’m not setting the same transformation (and thus animation) for WebKit as for IE10 &amp;amp; Firefox in my previous CSS block. This is because Chrome is not behaving in the same way as IE10 and Firefox 11 in my case. I’ve setup a simple repro case on jsFiddle here: &lt;a title="http://jsfiddle.net/5H8wg/2/" href="http://jsfiddle.net/5H8wg/2/"&gt;http://jsfiddle.net/5H8wg/2/&lt;/a&gt; . Opera doesn’t support CSS3 3D Transform yet. &lt;/p&gt;

&lt;h2&gt;Video &amp;amp; URL to play this demo&lt;/h2&gt;

&lt;p&gt;Here is a short video of IE10 demonstrating the features implemented in this article:&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="ModernHTML5PlatformerPart1" class="video-js" poster="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1.jpg" preload="preload" controls="controls" width="640" height="360"&gt;&lt;source type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" src="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1.mp4" /&gt;&lt;source type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" src="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1.webm" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="640" type="application/x-shockwave-flash" height="360"&gt;  &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  
&lt;param name="allowfullscreen" value="true" /&gt;  
&lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  
&lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   
&lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1.jpg" width="512" height="288" /&gt;   &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/ModernHTML5PlatformerPart1.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;You can also play with this demo in IE10 or your favorite browser here: &lt;a title="http://david.blob.core.windows.net/modernhtml5platformer/index.html" href="http://david.blob.core.windows.net/modernhtml5platformer/index.html"&gt;Modern HTML5 Platformer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://david.blob.core.windows.net/modernhtml5platformer/index.html"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4382.image_5F00_7B8C1CD8.png" width="240" height="124" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/04/17/modernizing-your-html5-canvas-games-part-2-offline-api-drag-n-drop-amp-file-api.aspx"&gt;second article&lt;/a&gt;, we’re going to see how I’ve implemented the Offline APIs to make the game works without network connections and how I’ve used File &amp;amp; Drag’n’drop APIs to implement a cool feature in my game.&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10291483" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/GPU/">GPU</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/CSS3/">CSS3</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Canvas/">Canvas</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/IE10/">IE10</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/EaselJS/">EaselJS</category></item><item><title>HTML5 Platformer: the complete port of the XNA game to &lt;canvas&gt; with EaselJS</title><link>http://blogs.msdn.com/b/davrous/archive/2012/03/21/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx</link><pubDate>Wed, 21 Mar 2012 18:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10208343</guid><dc:creator>David Rousset</dc:creator><slash:comments>16</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10208343</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/03/21/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx#comments</comments><description>&lt;p&gt;&lt;img style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: left; padding-top: 0px; padding-left: 0px; margin: 0px 10px 0px 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" align="left" src="https://david.blob.core.windows.net/html5platformer/icons/Game128.png" width="96" height="96" /&gt;After a couple of hours coding with JavaScript, I’ve finally finished porting the XNA 4.0 Platformer game sample to HTML5/Canvas with the help of the EaselJS gaming framework. This article will provide you the game and the story of some of the questions I’ve asked myself while coding it. If you’d like to know how the game works, simply read the JavaScript commented code available at the end of this article. Please note that my main goal was to better learn JavaScript by writing pure JS code (with no form of dependency to the DOM) and to write a cross-browsers working game and cross HTML5 compatible devices when possible also.&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;You can play the game directly inside this iframe (left &amp;amp; right arrows keys to move &amp;amp; W to jump). Just press the “Start” button to launch the download sequence and the game itself. &lt;/p&gt; &lt;iframe style="border-top: #ffffff 0px solid; border-right: #ffffff 0px solid; border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid" height="530" src="http://david.blob.core.windows.net/html5platformer/index.html" width="830"&gt;&lt;/iframe&gt;  &lt;p&gt;Or you can play with it in a separate window through this link: &lt;a title="http://david.blob.core.windows.net/html5platformer/index.html" href="http://david.blob.core.windows.net/html5platformer/index.html" target="_blank"&gt;HTML5 Platformer&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Note 1:&lt;/u&gt;&lt;/strong&gt; the game has been first released in September 2011 with EaselJS 0.3.2 and has been &lt;strong&gt;updated for EaselJS 0.4&lt;/strong&gt;. You can now use &lt;strong&gt;requestAnimationFrame&lt;/strong&gt; on the supported browsers to check if it’s boosting your performance or not. You just have to check/unckeck the above case to see in real time the results. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Note 2:&lt;/u&gt;&lt;/strong&gt; this game has been tested with success under IE9/10, Chrome 17, Firefox 11, IE9 on WP7 Mango and iPad 2. The game doesn’t work in Opera 11.61 due to a bug in their native Image implementation apparently: &lt;a href="http://groups.google.com/group/easeljs/browse_thread/thread/14f51b3b44ff0d44"&gt;About Issue in latest Opera&lt;/a&gt;. At last, if you really want to play to the game, an hardware accelerated browser is highly recommended. I’ve got 60 FPS in these conditions on my Sony Vaio Z13.&amp;#160; &lt;/p&gt;  &lt;p&gt;At the end of this article, you’ll find the complete non-minified source code of this game inside a ZIP archive to download. I’ve tried to comment as much as possible the code to make it self-explicit. I hope you’ll learn some interesting things while reading it. If you have any feedbacks and/or suggestions on it, feel free to add it as a comment to this blog’s post.&lt;/p&gt;  &lt;p&gt;I’ve also already written 2 articles covering the basics of the logic behind this game here:&lt;/p&gt;  &lt;p&gt;- &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/07/21/html5-gaming-animating-sprites-in-canvas-with-easeljs.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/07/21/html5-gaming-animating-sprites-in-canvas-with-easeljs.aspx"&gt;HTML5 Gaming: animating sprites in Canvas with EaselJS&lt;/a&gt;     &lt;br /&gt;- &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/07/29/html5-gaming-building-the-core-objects-amp-handling-collisions-with-easeljs.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/07/29/html5-gaming-building-the-core-objects-amp-handling-collisions-with-easeljs.aspx"&gt;HTML5 Gaming: building the core objects &amp;amp; handling collisions with EaselJS&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I’ve also written 3 others articles going further with this game:&lt;/p&gt;  &lt;p&gt;- &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/12/23/tutorial-how-to-create-html5-applications-on-windows-phone-thanks-to-phonegap.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/12/23/tutorial-how-to-create-html5-applications-on-windows-phone-thanks-to-phonegap.aspx"&gt;Tutorial: how to create HTML5 applications on Windows Phone thanks to PhoneGap&lt;/a&gt; where I’ll show you how to migrate this code to PhoneGap    &lt;br /&gt;- &lt;a title="http://blogs.msdn.com/b/davrous/archive/2012/04/06/modernizing-your-html5-canvas-games-with-offline-apis-file-apis-css3-amp-hardware-scaling.aspx" href="http://blogs.msdn.com/b/davrous/archive/2012/04/06/modernizing-your-html5-canvas-games-with-offline-apis-file-apis-css3-amp-hardware-scaling.aspx"&gt;Modernizing your HTML5 Canvas games Part 1: hardware scaling &amp;amp; CSS3&lt;/a&gt; where we’ll use CSS3 3D Transform, Transitions &amp;amp; Grid Layout    &lt;br /&gt;- &lt;a title="http://blogs.msdn.com/b/davrous/archive/2012/04/17/modernizing-your-html5-canvas-games-part-2-offline-api-drag-n-drop-amp-file-api.aspx" href="http://blogs.msdn.com/b/davrous/archive/2012/04/17/modernizing-your-html5-canvas-games-part-2-offline-api-drag-n-drop-amp-file-api.aspx"&gt;Modernizing your HTML5 Canvas games Part 2: Offline API, Drag’n’drop &amp;amp; File API&lt;/a&gt; where we will enable playing to the game in offline mode&lt;/p&gt;  &lt;h2&gt;Building the content manager&lt;/h2&gt;  &lt;p&gt;In the previous article, the download content manager wasn’t notifying the user of the progression of the download process which was very bad. Hopefully, adding this feature was pretty straight forward as you just have to have a tick() method to your object and update a text element on the stage to show the progression. You can find that by reading the &lt;em&gt;ContentManager.js&lt;/em&gt; file. &lt;/p&gt;  &lt;p&gt;Moreover, as my objective was to be compatible with all browsers, I’ve then encoded the music &amp;amp; audio elements both in MP3 and OGG. If you’d like to know more about this HTML5 Audio tag codecs story, I recommend you having a look to my colleague’s article: &lt;a href="http://blogs.msdn.com/b/nigel/archive/2011/04/14/5-things-you-need-to-know-to-start-using-video-and-audio-today.aspx"&gt;5 Things You Need to Know to Start Using Video and Audio Today&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Then, I’m downloading either the MP3 or OGG version using the following code:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;canPlayMp3, canPlayOgg;
&lt;span style="color: blue"&gt;var &lt;/span&gt;audioExtension = &lt;span style="color: maroon"&gt;&amp;quot;.none&amp;quot;&lt;/span&gt;;

&lt;span style="color: #006400"&gt;// Need to check the canPlayType first or an exception
// will be thrown for those browsers that don't support it      
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;myAudio = document.createElement(&lt;span style="color: maroon"&gt;'audio'&lt;/span&gt;);

&lt;span style="color: blue"&gt;if &lt;/span&gt;(myAudio.canPlayType) {
    &lt;span style="color: #006400"&gt;// Currently canPlayType(type) returns: &amp;quot;&amp;quot;, &amp;quot;maybe&amp;quot; or &amp;quot;probably&amp;quot; 
    &lt;/span&gt;canPlayMp3 = !!myAudio.canPlayType &amp;amp;&amp;amp; &lt;span style="color: maroon"&gt;&amp;quot;&amp;quot; &lt;/span&gt;!= myAudio.canPlayType(&lt;span style="color: maroon"&gt;'audio/mpeg'&lt;/span&gt;);
    canPlayOgg = !!myAudio.canPlayType &amp;amp;&amp;amp; &lt;span style="color: maroon"&gt;&amp;quot;&amp;quot; &lt;/span&gt;!= myAudio.canPlayType(&lt;span style="color: maroon"&gt;'audio/ogg; codecs=&amp;quot;vorbis&amp;quot;'&lt;/span&gt;);
}

&lt;span style="color: blue"&gt;if &lt;/span&gt;(canPlayMp3)
    audioExtension = &lt;span style="color: maroon"&gt;&amp;quot;.mp3&amp;quot;&lt;/span&gt;;
&lt;span style="color: blue"&gt;else if &lt;/span&gt;(canPlayOgg) {
    audioExtension = &lt;span style="color: maroon"&gt;&amp;quot;.ogg&amp;quot;&lt;/span&gt;;
}

&lt;span style="color: #006400"&gt;// If the browser supports either MP3 or OGG
&lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(audioExtension !== &lt;span style="color: maroon"&gt;&amp;quot;.none&amp;quot;&lt;/span&gt;) {
    SetAudioDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.globalMusic, &lt;span style="color: maroon"&gt;&amp;quot;sounds/Music&amp;quot; &lt;/span&gt;+ audioExtension);
    SetAudioDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.playerKilled, &lt;span style="color: maroon"&gt;&amp;quot;sounds/PlayerKilled&amp;quot; &lt;/span&gt;+ audioExtension);
    SetAudioDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.playerJump, &lt;span style="color: maroon"&gt;&amp;quot;sounds/PlayerJump&amp;quot; &lt;/span&gt;+ audioExtension);
    SetAudioDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.playerFall, &lt;span style="color: maroon"&gt;&amp;quot;sounds/PlayerFall&amp;quot; &lt;/span&gt;+ audioExtension);
    SetAudioDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.exitReached, &lt;span style="color: maroon"&gt;&amp;quot;sounds/ExitReached&amp;quot; &lt;/span&gt;+ audioExtension);
}&lt;/pre&gt;

&lt;p&gt;I’ve spent more time trying to figure out what was the best way to preload or download the audio files before starting the game. In the case of the image elements, we can’t start the game at all if we don’t have downloaded all the images locally. Otherwise, trying to draw on the canvas with non-yet downloaded images will fail. &lt;/p&gt;

&lt;p&gt;For the audio elements, my wish was to be sure to play it exactly when I will need it. If the player dies, I don’t want the sound to be played 2 sec after the fatal event. Unfortunately, there is no real way to do that properly in all browsers. The HTML5 Audio element has been made to stream the audio file and plays it as soon as enough data is available. We don’t have an event saying: “&lt;em&gt;the audio file has been completely downloaded&lt;/em&gt;”. My idea was then to download a base64 version of the file using an XMLHTTPRequest and to pass it to the audio tag using &lt;em&gt;&amp;lt;source src=&amp;quot;data:audio/mp3;base64,{base64_string}&amp;quot; /&amp;gt;&lt;/em&gt; for instance. But I didn’t have the time to test if this is working or not. If you have done some similar tests, I’m interested in the results.&lt;/p&gt;

&lt;p&gt;So finally, the only thing I’m doing is calling the load() method to start loading as much data as possible before using it. But on slow network, this won’t prevent the case where the audio won’t be ready while the game asks it. This won’t generate an error, but the sound won’t be synchronized with the action. &lt;/p&gt;

&lt;h2&gt;Working around HTML5 Audio tag limitations&lt;/h2&gt;

&lt;p&gt;While coding and testing the game, I’ve found another issue using the HTML5 &amp;lt;audio&amp;gt; tag (I didn’t expect spending so much time on the audio part!). If the player takes several gems too quickly, the audio element associated to this event can’t handle it. For instance, at the beginning, when the player was taking 8 gems on the same line, I was able to hear only 1 to 3 times the sound “GemCollected.mp3/ogg”. This means that no sound was emitted for the 5 remaining gems. &lt;/p&gt;

&lt;p&gt;I’ve then started several experiments and I’ve finally discover that I’ve done everything already related in this article: &lt;a title="http://www.phoboslab.org/log/2011/03/multiple-channels-for-html5-audio" href="http://www.phoboslab.org/log/2011/03/multiple-channels-for-html5-audio"&gt;Multiple Channels for HTML5 Audio&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;On my side, I’ve finished by using another workaround. In the content manager object, I’m downloading 8 times the same GemCollected sound into an array of Audio() objects:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Used to simulate multi-channels audio 
// As HTML5 Audio in browsers is today too limited
// Yes, I know, we're forced to download N times to same file...
&lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;a = 0; a &amp;lt; 8; a++) {
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.gemCollected[a] = &lt;span style="color: blue"&gt;new &lt;/span&gt;Audio();
    SetAudioDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.gemCollected[a], &lt;span style="color: maroon"&gt;&amp;quot;sounds/GemCollected&amp;quot; &lt;/span&gt;+ audioExtension);
}&lt;/pre&gt;

&lt;p&gt;And during the game, I’m cycling inside this array to be able to “simulate” multichannels sound. You can find this trick in the &lt;em&gt;UpdateGems()&lt;/em&gt; method of &lt;em&gt;Level.js&lt;/em&gt;:&amp;#160; &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color: #006400"&gt;Animates each gem and checks to allows the player to collect them.
&lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
&lt;/span&gt;Level.prototype.UpdateGems = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i = 0; i &amp;lt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.Gems.length; i++) {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.Gems[i].BoundingRectangle().Intersects(&lt;span style="color: blue"&gt;this&lt;/span&gt;.Hero.BoundingRectangle())) {
            &lt;span style="color: #006400"&gt;// We remove it from the drawing surface
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.levelStage.removeChild(&lt;span style="color: blue"&gt;this&lt;/span&gt;.Gems[i]);
            &lt;span style="color: blue"&gt;this&lt;/span&gt;.Score += &lt;span style="color: blue"&gt;this&lt;/span&gt;.Gems[i].PointValue;
            &lt;span style="color: #006400"&gt;// We then remove it from the in memory array
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.Gems.splice(i, 1);
&lt;font style="background-color: #ffff00"&gt;            &lt;/font&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span style="color: #006400"&gt;// And we finally play the gem collected sound using a multichannels trick
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.levelContentManager.gemCollected[audioGemIndex % 8].play();
            audioGemIndex++;&lt;/font&gt;
        }
    }
};&lt;/pre&gt;

&lt;p&gt;I know this is not efficient at all. Maybe some Audio APIs will help us in the future to better handle the audio in our games. I know Mozilla and Google are working on some good suggestions but this is far from being mainstream for the moment. &lt;/p&gt;

&lt;h2&gt;The mono-threaded JavaScript nature&lt;/h2&gt;

&lt;p&gt;I’ve already covered this topic inside one of my previous articles: &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/07/15/introduction-to-the-html5-web-workers-the-javascript-multithreading-approach.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/07/15/introduction-to-the-html5-web-workers-the-javascript-multithreading-approach.aspx"&gt;Introduction to the HTML5 Web Workers: the JavaScript multithreading approach&lt;/a&gt; . Without WebWorkers, JavaScript is by nature mono-threaded. Even if setInterval() and setTimetout() try to make the illusions that multiple things occur at the same time, this is not the case. Everything is serialized.&lt;/p&gt;

&lt;p&gt;In my gaming scenario, this leads to problems while handling the animations. We don’t have the guarantee of being call-backed every xxx milliseconds in our update logic. To avoid that, XNA provides 2 different separate loops: the drawing loop and the update loop. In my case, they are more or less merged. And this is where the problem is. For instance, if the elapsed time between 2 ticks is too important (due to the single threading processing), I could miss an update call that would prevent one of my enemies to hit testing properly its environment. This then leads to very weird results. This is why in some parts of the code, I’ve hard-coded the expected elapsed time to 17 milliseconds. In the XNA version, the elapsed time is compute and often equal to approximately 16 ms (60 FPS). The solution to better handle the update loop (the tick() method in EaselJS) could be to use some WebWorkers. &lt;/p&gt;

&lt;p&gt;On the other side, the solution for HTML5 gaming to properly handle animations could come in the future with requestAnimationFrame(). This is now supported by Internet Explorer 10 and can be used in EaselJS 0.4. But there are some interesting debates around it on the web. If you’re interested in this topic, I suggest you reading these 3 articles:&lt;/p&gt;

&lt;p&gt;- &lt;a title="http://www.phoboslab.org/log/2011/08/are-we-fast-yet" href="http://www.phoboslab.org/log/2011/08/are-we-fast-yet"&gt;Are We Fast Yet?&lt;/a&gt; by Dominic Szablewski, the author of &lt;a href="http://html5-benchmark.com/"&gt;HTML5 Benchmark&lt;/a&gt; (using ImpactJS) : “&lt;em&gt;At the moment &lt;code&gt;requestAnimationFrame()&lt;/code&gt; is truly worthless for games.&lt;/em&gt;”&amp;#160; &lt;br /&gt;- &lt;a href="http://paulirish.com/2011/requestanimationframe-for-smart-animating/"&gt;requestAnimationFrame for smart animating&lt;/a&gt; from Paul Irish. 

  &lt;br /&gt;- &lt;a title="http://ie.microsoft.com/testdrive/Graphics/RequestAnimationFrame/Default.html" href="http://ie.microsoft.com/testdrive/Graphics/RequestAnimationFrame/Default.html"&gt;requestAnimationFrame API&lt;/a&gt; from our IE Test Drive site to show our current IE10 implementation.&lt;/p&gt;

&lt;p&gt;I let you experiment its usage on my game to check if it’s interesting or not in your case.&lt;/p&gt;

&lt;h2&gt;Special Kudos for IE9 &amp;amp; IE10&lt;/h2&gt;

&lt;p&gt;I’ve added 2 Kudos for IE users browsing my little game:&lt;/p&gt;

&lt;p&gt;- pinned mode with a high resolution favicon and a jumplist to resources linked to the game 
  &lt;br /&gt;- thumbnail buttons to play the game in an original way! &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6888.wlEmoticon_2D00_winkingsmile_5F00_49A9717D.png" /&gt;&lt;/p&gt;

&lt;p&gt;You can then drag’n’drop the tab into your Windows 7 taskbar. IE9 will then reflect the theme of the game:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1122.image_5F00_1AD9B931.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5824.image_5F00_thumb_5F00_697AA903.png" width="850" height="96" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will also have a jumplist available:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2043.image_5F00_09895FDE.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5657.image_5F00_thumb_5F00_0C6E9EC4.png" width="339" height="415" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The game will then be available on the user’s taskbar as if it was a native application.&lt;/p&gt;

&lt;p&gt;At last, you can discretely continue playing the game via the preview mode of Windows7!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3362.image_5F00_309A1F76.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4338.image_5F00_thumb_5F00_358C3758.png" width="309" height="286" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are 3 thumbnails buttons to move left/right and jump even in preview mode. &lt;img class="wlEmoticon wlEmoticon-openmouthedsmile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Rire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4010.wlEmoticon_2D00_openmouthedsmile_5F00_4CC715FC.png" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; there is another more or less hidden kudos to IE in one of the levels. Will you find it?&lt;/p&gt;

&lt;h2&gt;Adding new levels to the game&lt;/h2&gt;

&lt;p&gt;The levels are stored inside the “/levels” directory inside .txt files. You’ll find 4 levels by default: 0.txt, 1.txt, 2.txt &amp;amp; 3.txt. They are simply downloaded via an asynchronous XMLHTTPRequest call and they parsed to build the appropriate rendering &amp;amp; collisions system.&lt;/p&gt;

&lt;p&gt;For instance, here is the 2nd level:&lt;/p&gt;

&lt;pre&gt;&lt;font color="#008000" size="1"&gt;....................
....................
..........X.........
.......######.......
..G..............G..
####..G.G.G.G....###
.......G.G.GCG......
......--------......
...--...........--..
......GGGG.GGGG.....
.G.G...GG..G....G.G.
####...GG..GGGG.####
.......GG..G........
.1....GGGG.GGGG.....
####################&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;And here is the output in the game:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6332.image_5F00_6D528E8D.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6567.image_5F00_thumb_5F00_2B8F1D02.png" width="320" height="216" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1&lt;/strong&gt; is where the player will start the game, &lt;strong&gt;X&lt;/strong&gt; is the exit, &lt;strong&gt;G&lt;/strong&gt; is a Gem, &lt;strong&gt;#&lt;/strong&gt; is a platform block, &lt;strong&gt;-&lt;/strong&gt; is a passable block, &lt;strong&gt;C&lt;/strong&gt; one of the monsters/enemies, etc. &lt;/p&gt;

&lt;p&gt;So, if you’d like to add levels to the game, simply add a new text file and edit the level yourself with… Notepad! You’ll need also to modify the value of the &lt;em&gt;numberOfLevel&lt;/em&gt; variable inside &lt;em&gt;PlatformerGame.js&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;Non-minified source code&lt;/h2&gt;

&lt;p&gt;As promised, you can download the source code and all the assets of the game here: &lt;a href="http://david.blob.core.windows.net/html5platformer/HTML5Platformer.zip"&gt;HTML5 Platformer Non-minified&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I hope you’ve enjoyed this series of 3 articles around HTML5 Gaming. Maybe this will help you transforming your gaming ideas into an HTML5 reality!&lt;/p&gt;

&lt;p&gt;If you’re ready to go even further, I’ve made a 4th tutorial on how to port the &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/12/23/tutorial-how-to-create-html5-applications-on-windows-phone-thanks-to-phonegap.aspx"&gt;very same HTML5 game on Windows Phone using PhoneGap&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10208343" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Internet+Explorer+9/">Internet Explorer 9</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/XNA/">XNA</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Platformer/">Platformer</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/EaselJS/">EaselJS</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Game/">Game</category></item><item><title>HTML5 Platformer: portage complet du jeu XNA vers &lt;canvas&gt; grâce à EaselJS</title><link>http://blogs.msdn.com/b/davrous/archive/2012/03/21/html5-platformer-portage-complet-du-jeu-xna-vers-lt-canvas-gt-gr-226-ce-224-easeljs.aspx</link><pubDate>Wed, 21 Mar 2012 10:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10208530</guid><dc:creator>David Rousset</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10208530</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/03/21/html5-platformer-portage-complet-du-jeu-xna-vers-lt-canvas-gt-gr-226-ce-224-easeljs.aspx#comments</comments><description>&lt;p&gt;&lt;img width="96" height="96" align="left" style="background-image: none; float: left; padding-top: 0px; padding-left: 0px; margin: 0px 10px 0px 0px; display: inline; padding-right: 0px; border-width: 0px;" src="https://david.blob.core.windows.net/html5platformer/icons/Game128.png" border="0" /&gt;Apr&amp;egrave;s quelques heures pass&amp;eacute;es sur le clavier &amp;agrave; coder en JavaScript, j&amp;rsquo;ai finalement compl&amp;egrave;tement port&amp;eacute; l&amp;rsquo;exemple de jeu Platformer issu des samples XNA 4.0 vers HTML5/Canvas &amp;agrave; l&amp;rsquo;aide du framework EaselJS. Vous trouverez dans cet article le jeu en lui-m&amp;ecirc;me ainsi qu&amp;rsquo;un petit retour d&amp;rsquo;exp&amp;eacute;rience sur les parties qui m&amp;rsquo;ont fait me poser le plus de questions. Si vous cherchez &amp;agrave; savoir comment fonctionne le jeu en interne, le mieux est de tout simplement en lire le code. Il est disponible au t&amp;eacute;l&amp;eacute;chargement &amp;agrave; la fin de cet article. Avant de rentrer dans le vif du sujet, j&amp;rsquo;aimerais attirer votre attention sur mes motivations principales &amp;agrave; l&amp;rsquo;&amp;eacute;criture de ce jeu. Je cherchais tout simplement &amp;agrave; mieux apprendre JavaScript en &amp;eacute;crivant du code purement JS (sans aucune forme de d&amp;eacute;pendance avec le DOM). Je cherchais &amp;eacute;galement &amp;agrave; &amp;eacute;crire un jeu fonctionnant sur tous les navigateurs ainsi que sur les p&amp;eacute;riph&amp;eacute;riques &amp;ldquo;compatible&amp;rdquo; HTML5 lorsque cela est possible. Cela vous aidera peut-&amp;ecirc;tre &amp;agrave; mieux comprendre certains choix que j&amp;rsquo;ai effectu&amp;eacute;s.&lt;/p&gt;
&lt;p&gt;Vous pouvez jouer au jeu directement au sein de cette iframe (avec les fl&amp;egrave;ches droite et gauche &amp;amp; W pour sauter). Il vous suffit d&amp;rsquo;appuyer sur le bouton &amp;ldquo;Start&amp;rdquo; pour lancer la s&amp;eacute;quence de t&amp;eacute;l&amp;eacute;chargement des ressources puis du jeu lui-m&amp;ecirc;me.&lt;/p&gt;
&lt;p&gt;&lt;iframe width="830" height="530" src="http://david.blob.core.windows.net/html5platformer/index.html" style="border: #ffffff 0px solid;"&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;p&gt;Vous pouvez &amp;eacute;galement jouer au jeu dans une fen&amp;ecirc;tre s&amp;eacute;par&amp;eacute;e en suivant ce lien : &lt;a title="http://david.blob.core.windows.net/html5platformer/index.html" href="http://david.blob.core.windows.net/html5platformer/index.html" target="_blank"&gt;HTML5 Platformer&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Note&amp;nbsp; 1:&lt;/span&gt;&lt;/strong&gt; ce jeu a d'abord &amp;eacute;t&amp;eacute; publi&amp;eacute; en septembre 2011 avec EaselJS 0.3.2 et a &amp;eacute;t&amp;eacute; &lt;strong&gt;mis &amp;agrave; jour pour EaselJS 0.4&lt;/strong&gt;. Vous pouvez d&amp;eacute;sormais tester l&amp;rsquo;usage de requestAnimationFrame avec les navigateurs le supportant pour v&amp;eacute;rifier si cela augmente vos performances ou non. Il vous suffit de cocher/d&amp;eacute;cocher la case ci-dessus pour voir le r&amp;eacute;sultat en temps r&amp;eacute;el.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Note 2:&lt;/span&gt;&lt;/strong&gt; ce jeu a &amp;eacute;t&amp;eacute; test&amp;eacute; avec succ&amp;egrave;s sous IE9/10, Chrome 17, Firefox 11, IE9 sur Windows Phone et sous iPad 2. Le jeu ne fonctionne pas sous Opera 11.61 &amp;agrave; cause d&amp;rsquo;un bug sur leur impl&amp;eacute;mentation native de l&amp;rsquo;objet Image apparemment: &lt;a href="http://groups.google.com/group/easeljs/browse_thread/thread/14f51b3b44ff0d44"&gt;About Issue in latest Opera&lt;/a&gt;. Pour finir, pour pouvoir bien jouer au jeu, un navigateur disposant d&amp;rsquo;une bonne couche d&amp;rsquo;acc&amp;eacute;l&amp;eacute;ration mat&amp;eacute;rielle est conseill&amp;eacute;. J&amp;rsquo;ai ainsi 60 images/seconde sous IE9/10 sur mon Sony Vaio Z13.&lt;/p&gt;
&lt;p&gt;Vous trouverez &amp;agrave; la fin de cet article le code source complet non compress&amp;eacute; (minified) au sein d&amp;rsquo;une archive ZIP &amp;agrave; t&amp;eacute;l&amp;eacute;charger. J&amp;rsquo;ai essay&amp;eacute; de commenter le code autant que possible pour le rendre le plus explicite possible. J&amp;rsquo;esp&amp;egrave;re que vous apprendrez des choses int&amp;eacute;ressantes en le lisant. Si vous avez d&amp;rsquo;ailleurs des retours ou suggestions &amp;agrave; faire dessus, n&amp;rsquo;h&amp;eacute;sitez pas &amp;agrave; les faire &amp;agrave; travers les commentaires de ce billet de blog.&lt;/p&gt;
&lt;p&gt;Pour rappel, j&amp;rsquo;ai &amp;eacute;galement d&amp;eacute;j&amp;agrave; &amp;eacute;crit 2 articles abordant les bases de la logique se trouvant derri&amp;egrave;re ce jeu:&lt;/p&gt;
&lt;p&gt;- &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/07/22/jeux-html5-animation-de-sprites-dans-l-233-l-233-ment-canvas-gr-226-ce-224-easeljs.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/07/22/jeux-html5-animation-de-sprites-dans-l-233-l-233-ment-canvas-gr-226-ce-224-easeljs.aspx"&gt;Jeux HTML5: animation de sprites dans l&amp;rsquo;&amp;eacute;l&amp;eacute;ment Canvas gr&amp;acirc;ce &amp;agrave; EaselJS&lt;/a&gt;&amp;nbsp; &lt;br /&gt;- &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/08/22/jeux-html5-construction-des-objets-principaux-amp-gestion-des-collisions-avec-easeljs.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/08/22/jeux-html5-construction-des-objets-principaux-amp-gestion-des-collisions-avec-easeljs.aspx"&gt;Jeux HTML5: construction des objets principaux &amp;amp; gestion des collisions avec EaselJS&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Et je suis ensuite all&amp;eacute; plus loin avec le m&amp;ecirc;me jeu &amp;agrave; travers 3 autres articles :&lt;/p&gt;
&lt;p&gt;- &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/12/23/tutorial-cr-233-ez-des-applications-avec-html5-sur-windows-phone-gr-226-ce-224-phonegap.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/12/23/tutorial-cr-233-ez-des-applications-avec-html5-sur-windows-phone-gr-226-ce-224-phonegap.aspx"&gt;Tutorial: cr&amp;eacute;ez des applications avec HTML5 sur Windows Phone gr&amp;acirc;ce &amp;agrave; PhoneGap&lt;/a&gt; o&amp;ugrave; je vous montre comment porter ce jeu sous PhoneGap &lt;br /&gt;- &lt;a title="http://blogs.msdn.com/b/davrous/archive/2012/04/10/modernisez-vos-jeux-html5-canvas-partie-1-mise-224-l-233-chelle-mat-233-rielle-amp-css3.aspx" href="http://blogs.msdn.com/b/davrous/archive/2012/04/10/modernisez-vos-jeux-html5-canvas-partie-1-mise-224-l-233-chelle-mat-233-rielle-amp-css3.aspx"&gt;Modernisez vos jeux HTML5 canvas partie 1: mise &amp;agrave; l&amp;rsquo;&amp;eacute;chelle mat&amp;eacute;rielle &amp;amp; CSS3&lt;/a&gt; o&amp;ugrave; j&amp;rsquo;utilise CSS3 3D Transform, Transition &amp;amp; Grid Layout pour am&amp;eacute;liorer l&amp;rsquo;exp&amp;eacute;rience de jeu &lt;br /&gt;- &lt;a title="http://blogs.msdn.com/b/davrous/archive/2012/04/18/modernisez-vos-jeux-html5-canvas-partie-2-offline-api-drag-n-drop-amp-file-api.aspx" href="http://blogs.msdn.com/b/davrous/archive/2012/04/18/modernisez-vos-jeux-html5-canvas-partie-2-offline-api-drag-n-drop-amp-file-api.aspx"&gt;Modernisez vos jeux HTML5 canvas partie 2: Offline API, Drag&amp;rsquo;n&amp;rsquo;drop &amp;amp; File API&lt;/a&gt; o&amp;ugrave; je rend le jeu fonctionnel m&amp;ecirc;me en mode d&amp;eacute;connect&amp;eacute;&lt;/p&gt;
&lt;h2&gt;Construction du gestionnaire de t&amp;eacute;l&amp;eacute;chargements&lt;/h2&gt;
&lt;p&gt;Dans mon article pr&amp;eacute;c&amp;eacute;dent, le gestionnaire de t&amp;eacute;l&amp;eacute;chargements ne notifiait pas l&amp;rsquo;utilisateur du niveau de progression globale des t&amp;eacute;l&amp;eacute;chargements. C&amp;rsquo;&amp;eacute;tait tr&amp;egrave;s mal. Heureusement, l&amp;rsquo;ajout de cette fonctionnalit&amp;eacute; fut un jeu d&amp;rsquo;enfant. Vous n&amp;rsquo;avez en effet qu&amp;rsquo;&amp;agrave; ajouter une m&amp;eacute;thode tick() &amp;agrave; votre objet and mettre &amp;agrave; jour un &amp;eacute;l&amp;eacute;ment de type Text pr&amp;eacute;sent dans le Stage d&amp;rsquo;EaselJS pour afficher la progression. Vous pouvez le voir en lisant le code du fichier &lt;em&gt;ContentManager.js&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Par ailleurs, mon objectif &amp;eacute;tant de rendre le jeu compatible avec tous les navigateurs, j&amp;rsquo;ai encod&amp;eacute; la musique et les &amp;eacute;l&amp;eacute;ments sonores au format MP3 et OGG. Si vous souhaitez en savoir davantage sur cette histoire de codec autour de la balise audio d&amp;rsquo;HTML5, je vous recommande chaudement la lecture de l&amp;rsquo;article de mon coll&amp;egrave;gue Stanislas: &lt;a title="http://blogs.technet.com/b/stanislas/archive/2010/11/22/html5-ce-qu-il-faut-savoir-sur-la-balise-audio.aspx" href="http://blogs.technet.com/b/stanislas/archive/2010/11/22/html5-ce-qu-il-faut-savoir-sur-la-balise-audio.aspx"&gt;HTML5 - ce qu il faut savoir sur la balise Audio&lt;/a&gt; et &amp;eacute;galement son cahier de vacances HTML5 sur audio/video: &lt;a title="http://msdn.microsoft.com/fr-fr/ie/hh237531" href="http://msdn.microsoft.com/fr-fr/ie/hh237531"&gt;Cahiers de vacances HTML5&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Bon du coup, de mon c&amp;ocirc;t&amp;eacute;, je t&amp;eacute;l&amp;eacute;charge soit la version MP3 soit la version OGG en utilisant le code suivant :&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue;"&gt;var &lt;/span&gt;canPlayMp3, canPlayOgg;
&lt;span style="color: blue;"&gt;var &lt;/span&gt;audioExtension = &lt;span style="color: maroon;"&gt;".none"&lt;/span&gt;;

&lt;span style="color: #006400;"&gt;// Need to check the canPlayType first or an exception // will be thrown for those browsers that don't support it &lt;/span&gt;&lt;span style="color: blue;"&gt;var &lt;/span&gt;myAudio = document.createElement(&lt;span style="color: maroon;"&gt;'audio'&lt;/span&gt;);

&lt;span style="color: blue;"&gt;if &lt;/span&gt;(myAudio.canPlayType) {
    &lt;span style="color: #006400;"&gt;// Currently canPlayType(type) returns: "", "maybe" or "probably" &lt;/span&gt;canPlayMp3 = !!myAudio.canPlayType &amp;amp;&amp;amp; &lt;span style="color: maroon;"&gt;"" &lt;/span&gt;!= myAudio.canPlayType(&lt;span style="color: maroon;"&gt;'audio/mpeg'&lt;/span&gt;);
    canPlayOgg = !!myAudio.canPlayType &amp;amp;&amp;amp; &lt;span style="color: maroon;"&gt;"" &lt;/span&gt;!= myAudio.canPlayType(&lt;span style="color: maroon;"&gt;'audio/ogg; codecs="vorbis"'&lt;/span&gt;);
}

&lt;span style="color: blue;"&gt;if &lt;/span&gt;(canPlayMp3)
    audioExtension = &lt;span style="color: maroon;"&gt;".mp3"&lt;/span&gt;;
&lt;span style="color: blue;"&gt;else if &lt;/span&gt;(canPlayOgg) {
    audioExtension = &lt;span style="color: maroon;"&gt;".ogg"&lt;/span&gt;;
}

&lt;span style="color: #006400;"&gt;// If the browser supports either MP3 or OGG &lt;/span&gt;&lt;span style="color: blue;"&gt;if &lt;/span&gt;(audioExtension !== &lt;span style="color: maroon;"&gt;".none"&lt;/span&gt;) {
    SetAudioDownloadParameters(&lt;span style="color: blue;"&gt;this&lt;/span&gt;.globalMusic, &lt;span style="color: maroon;"&gt;"sounds/Music" &lt;/span&gt;+ audioExtension);
    SetAudioDownloadParameters(&lt;span style="color: blue;"&gt;this&lt;/span&gt;.playerKilled, &lt;span style="color: maroon;"&gt;"sounds/PlayerKilled" &lt;/span&gt;+ audioExtension);
    SetAudioDownloadParameters(&lt;span style="color: blue;"&gt;this&lt;/span&gt;.playerJump, &lt;span style="color: maroon;"&gt;"sounds/PlayerJump" &lt;/span&gt;+ audioExtension);
    SetAudioDownloadParameters(&lt;span style="color: blue;"&gt;this&lt;/span&gt;.playerFall, &lt;span style="color: maroon;"&gt;"sounds/PlayerFall" &lt;/span&gt;+ audioExtension);
    SetAudioDownloadParameters(&lt;span style="color: blue;"&gt;this&lt;/span&gt;.exitReached, &lt;span style="color: maroon;"&gt;"sounds/ExitReached" &lt;/span&gt;+ audioExtension);
}&lt;/pre&gt;
&lt;p&gt;J&amp;rsquo;ai pass&amp;eacute; un peu plus de temps &amp;agrave; essayer de trouver la meilleure fa&amp;ccedil;on de pr&amp;eacute;charger ou de t&amp;eacute;l&amp;eacute;charger les fichiers audio avant de d&amp;eacute;marrer le jeu. Dans le cas des &amp;eacute;l&amp;eacute;ments de type image, on ne peut tout simplement pas d&amp;eacute;marrer le jeu si nous n&amp;rsquo;avons pas enti&amp;egrave;rement t&amp;eacute;l&amp;eacute;charg&amp;eacute; toutes les images localement. Sinon, tenter dessiner sur le canvas avec des images non encore enti&amp;egrave;rement pr&amp;eacute;sentes g&amp;eacute;n&amp;eacute;ra une belle exception.&lt;/p&gt;
&lt;p&gt;Pour les &amp;eacute;l&amp;eacute;ments audio, mon souhait &amp;eacute;tait d&amp;rsquo;avoir &amp;eacute;galement enti&amp;egrave;rement le fichier son pour &amp;ecirc;tre s&amp;ucirc;r de bien le jouer le moment venu. Si le joueur meurt, je ne veux pas que le son soit soit jou&amp;eacute; 2 secondes apr&amp;egrave;s sa mort. Il faut pas louper l&amp;rsquo;heure du son de sa mort. Malheureusement, il n&amp;rsquo;y a pas de r&amp;eacute;elle mani&amp;egrave;re de faire cela dans tous les navigateurs &amp;agrave; l&amp;rsquo;heure actuelle. L&amp;rsquo;&amp;eacute;l&amp;eacute;ment audio d&amp;rsquo;HTML5 a plut&amp;ocirc;t &amp;eacute;t&amp;eacute; con&amp;ccedil;u manifestement pour lire un flux audio en streaming. Il joue donc le son d&amp;egrave;s qu&amp;rsquo;il y a suffisamment de donn&amp;eacute;es disponibles. Nous n&amp;rsquo;avons pas par exemple un &amp;eacute;v&amp;egrave;nement qui nous indiquerait : &amp;ldquo;&lt;em&gt;le fichier audio a enti&amp;egrave;rement &amp;eacute;t&amp;eacute; t&amp;eacute;l&amp;eacute;charg&amp;eacute;&lt;/em&gt;&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Ma derni&amp;egrave;re id&amp;eacute;e fut alors de t&amp;eacute;l&amp;eacute;charger une vesion encod&amp;eacute;e en base64 du fichier via un appel &amp;agrave; XMLHTTPRequest et de passer le r&amp;eacute;sultat &amp;agrave; la balise audio ainsi par exemple : &lt;em&gt;&amp;lt;source src="data:audio/mp3;base64,{base64_string}" /&amp;gt;. &lt;/em&gt;Mais j&amp;rsquo;avoue ne pas avoir eu le courage/temps de tester si cela fonctionnait ou pas. Si de votre c&amp;ocirc;t&amp;eacute;, vous avez fait des tests similaires, je suis tr&amp;egrave;s curieux du r&amp;eacute;sultat. N&amp;rsquo;h&amp;eacute;sitez pas &amp;agrave; les partager !&lt;/p&gt;
&lt;p&gt;Finalement, la seule chose que je fais est d&amp;rsquo;appeler la m&amp;eacute;thode load() pour tenter de charger autant de donn&amp;eacute;es que possible avant de les utiliser. Sur un r&amp;eacute;seau lent, on pourrait alors tomber dans le cas o&amp;ugrave; le jeu demande &amp;agrave; jouer un son avant qu&amp;rsquo;il ne soit encore tout &amp;agrave; fait disponible. Cela ne g&amp;eacute;n&amp;eacute;ra par d&amp;rsquo;erreurs mais le son ne sera tout simplement pas synchronis&amp;eacute; avec l&amp;rsquo;action en cours.&lt;/p&gt;
&lt;h2&gt;Ruses autour des limitations de la balise audio HTML5&lt;/h2&gt;
&lt;p&gt;Pendant que je codais et testais le jeu, j&amp;rsquo;ai trouv&amp;eacute; un autre souci avec l&amp;rsquo;&amp;eacute;lement &amp;lt;audio&amp;gt; d&amp;rsquo;HTML5 (j&amp;rsquo;avoue que je n&amp;rsquo;avais pas pens&amp;eacute; passer autant de temps sur la partie audio du jeu!). Si le joueur prenais trop vite plusieurs diamants d&amp;rsquo;affil&amp;eacute;, l&amp;rsquo;&amp;eacute;l&amp;eacute;ment audio associ&amp;eacute; &amp;agrave; cet &amp;eacute;v&amp;egrave;nement n&amp;rsquo;&amp;eacute;tait pas capable de le g&amp;eacute;rer. Par exemple, au d&amp;eacute;but, quand le joueur prenais 8 diamants d&amp;rsquo;affil&amp;eacute; sur la m&amp;ecirc;me ligne, je ne pouvais entendre le son &amp;ldquo;GemCollected.mp3/ogg&amp;rdquo; qu&amp;rsquo;une &amp;agrave; 3 fois. Il n&amp;rsquo;y avait pas de son de jou&amp;eacute; pour les 5 derniers &amp;eacute;l&amp;eacute;ments restant. Ensuite, apr&amp;egrave;s une certaine attente, le son fonctionnait &amp;agrave; nouveau pour un nouveau diamant.&lt;/p&gt;
&lt;p&gt;Apr&amp;egrave;s plusieurs exp&amp;eacute;rimentations, je me suis finalement aper&amp;ccedil;u que tous les tests que j&amp;rsquo;effectuais &amp;eacute;taient d&amp;eacute;taill&amp;eacute;s dans cet article : &lt;a title="http://www.phoboslab.org/log/2011/03/multiple-channels-for-html5-audio" href="http://www.phoboslab.org/log/2011/03/multiple-channels-for-html5-audio"&gt;Multiple Channels for HTML5 Audio&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;De mon c&amp;ocirc;t&amp;eacute;, j&amp;rsquo;ai fini par utiliser une autre m&amp;eacute;thode de contournement. Dans l&amp;rsquo;objet ContentManager, je t&amp;eacute;l&amp;eacute;charge 8 fois le m&amp;ecirc;me son GemCollected au sein d&amp;rsquo;un tableau contenant des &amp;eacute;l&amp;eacute;ments de type Audio() :&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: #006400;"&gt;// Used to simulate multi-channels audio // As HTML5 Audio in browsers is today too limited // Yes, I know, we're forced to download N times to same file... &lt;/span&gt;&lt;span style="color: blue;"&gt;for &lt;/span&gt;(&lt;span style="color: blue;"&gt;var &lt;/span&gt;a = 0; a &amp;lt; 8; a++) {
    &lt;span style="color: blue;"&gt;this&lt;/span&gt;.gemCollected[a] = &lt;span style="color: blue;"&gt;new &lt;/span&gt;Audio();
    SetAudioDownloadParameters(&lt;span style="color: blue;"&gt;this&lt;/span&gt;.gemCollected[a], &lt;span style="color: maroon;"&gt;"sounds/GemCollected" &lt;/span&gt;+ audioExtension);
}&lt;/pre&gt;
&lt;p&gt;Puis pendant le jeu, je tourne de mani&amp;egrave;re cyclique au sein de ce tableau pour simuler plusieurs canaux audio. Vous pouvez trouver cette astuce dans la m&amp;eacute;thode &lt;em&gt;UpdateGems()&lt;/em&gt; dans le fichier &lt;em&gt;Level.js&lt;/em&gt; :&amp;nbsp;&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: gray;"&gt;/// &amp;lt;summary&amp;gt; /// &lt;/span&gt;&lt;span style="color: #006400;"&gt;Animates each gem and checks to allows the player to collect them. &lt;/span&gt;&lt;span style="color: gray;"&gt;/// &amp;lt;/summary&amp;gt; &lt;/span&gt;Level.prototype.UpdateGems = &lt;span style="color: blue;"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue;"&gt;for &lt;/span&gt;(&lt;span style="color: blue;"&gt;var &lt;/span&gt;i = 0; i &amp;lt; &lt;span style="color: blue;"&gt;this&lt;/span&gt;.Gems.length; i++) {
        &lt;span style="color: blue;"&gt;if &lt;/span&gt;(&lt;span style="color: blue;"&gt;this&lt;/span&gt;.Gems[i].BoundingRectangle().Intersects(&lt;span style="color: blue;"&gt;this&lt;/span&gt;.Hero.BoundingRectangle())) {
            &lt;span style="color: #006400;"&gt;// We remove it from the drawing surface &lt;/span&gt;&lt;span style="color: blue;"&gt;this&lt;/span&gt;.levelStage.removeChild(&lt;span style="color: blue;"&gt;this&lt;/span&gt;.Gems[i]);
            &lt;span style="color: blue;"&gt;this&lt;/span&gt;.Score += &lt;span style="color: blue;"&gt;this&lt;/span&gt;.Gems[i].PointValue;
            &lt;span style="color: #006400;"&gt;// We then remove it from the in memory array &lt;/span&gt;&lt;span style="color: blue;"&gt;this&lt;/span&gt;.Gems.splice(i, 1);
&lt;/pre&gt;
&lt;p&gt;&lt;span style="background-color: #ffff00;"&gt; &lt;/span&gt;&lt;span style="background-color: #ffff00;"&gt;&lt;span style="color: #006400;"&gt;// And we finally play the gem collected sound using a multichannels trick &lt;/span&gt;&lt;span style="color: blue;"&gt;this&lt;/span&gt;.levelContentManager.gemCollected[audioGemIndex % 8].play(); audioGemIndex++;&lt;/span&gt;&lt;/p&gt;
&lt;pre class="code"&gt;        }
    }
};&lt;/pre&gt;
&lt;p&gt;Je sais, je sais&amp;hellip; Cela n&amp;rsquo;est pas joli, joli. Peut-&amp;ecirc;tre que les nouvelles APIs Audio nous aideront dans le futur &amp;agrave; mieux g&amp;eacute;rer la partie audio de nos jeux. Je sais que Mozilla et Google travaillent sur de bonnes id&amp;eacute;es &amp;agrave; ce sujet mais c&amp;rsquo;est pour l&amp;rsquo;instant loin d&amp;rsquo;&amp;ecirc;tre finalis&amp;eacute; et adopt&amp;eacute; par tout le monde.&lt;/p&gt;
&lt;h2&gt;La nature mono-thread&amp;eacute;e de JavaScript&lt;/h2&gt;
&lt;p&gt;J&amp;rsquo;ai d&amp;eacute;j&amp;agrave; abord&amp;eacute; ce sujet &amp;agrave; travers l&amp;rsquo;un de mes articles pr&amp;eacute;c&amp;eacute;dents : &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/07/08/introduction-aux-web-workers-d-html5-le-multithreading-version-javascript.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/07/08/introduction-aux-web-workers-d-html5-le-multithreading-version-javascript.aspx"&gt;Introduction aux Web Workers d&amp;rsquo;HTML5 : le multithreading version JavaScript&lt;/a&gt; . Sans les WebWorkers, JavaScript est par nature mono-thread&amp;eacute;. M&amp;ecirc;me si les fonctions setInterval() et setTimeout() essaient de nous faire croire que plusieurs choses peuvent arriver en m&amp;ecirc;me temps, ce n&amp;rsquo;est pas le cas. Tout est s&amp;eacute;rialis&amp;eacute;.&lt;/p&gt;
&lt;p&gt;Dans mon contexte de jeu, cela engendre des probl&amp;egrave;mes sur la gestion des animations. Nous n&amp;rsquo;avons pas la garantie d&amp;rsquo;&amp;ecirc;tre appel&amp;eacute; toutes les xxx millisecondes dans notre logique de mise &amp;agrave; jour de nos &amp;eacute;l&amp;eacute;ments de jeu. Pour &amp;eacute;viter cela, XNA fournit 2 boucles s&amp;eacute;par&amp;eacute;es : la boucle de dessin (Draw) et la boucle de mise &amp;agrave; jour (Update). Dans mon cas, elles sont plus ou moins m&amp;eacute;lang&amp;eacute;es. Et c&amp;rsquo;est bien cela le probl&amp;egrave;me. Imaginez par exemple que le temps &amp;eacute;coul&amp;eacute; entre 2 ticks est trop important (&amp;agrave; cause du traitement mono-thread&amp;eacute; global). Je pourrais alors louper un appel &amp;agrave; ma m&amp;eacute;thode Update() qui devait normalement emp&amp;ecirc;cher l&amp;rsquo;un de mes ennemies de sortir de son environnement. Les tests de collisions deviennent donc non pr&amp;eacute;dictibles dans le temps et cela g&amp;eacute;n&amp;egrave;re des probl&amp;egrave;mes tr&amp;egrave;s &amp;eacute;tranges&amp;hellip; C&amp;rsquo;est pourquoi dans certaines parties du code, j&amp;rsquo;ai cod&amp;eacute; en dur le temps esp&amp;eacute;r&amp;eacute; entre 2 appels &amp;agrave; 17 ms. Dans la version XNA, le temps &amp;eacute;coul&amp;eacute; est bien calcul&amp;eacute; et &amp;eacute;quivaut souvent &amp;agrave; 16 ms environ (60 FPS). Une solution envisageable pour mieux g&amp;eacute;rer cette boucle de mise &amp;agrave; jour (la m&amp;eacute;thode tick() dans EaselJS) serait d&amp;rsquo;utiliser des WebWorkers.&lt;/p&gt;
&lt;p&gt;Du c&amp;ocirc;t&amp;eacute; boucle de dessin, la solution pour g&amp;eacute;rer correctement les animations dans le jeux HTML5 pourrait venir dans le futur avec requestAnimationFrame(). Cependant, la sp&amp;eacute;cification est aujourd&amp;rsquo;hui dans un &amp;eacute;tat trop brouillonne et son impl&amp;eacute;mentation varie d&amp;rsquo;un navigateur &amp;agrave; l&amp;rsquo;autre. Par ailleurs, il y a actuellement des d&amp;eacute;bats int&amp;eacute;ressants sur son utilisation ou non sur le web. Si le sujet vous int&amp;eacute;resse, je vous conseille la lecture de ces 3 articles :&lt;/p&gt;
&lt;p&gt;- &lt;a title="http://www.phoboslab.org/log/2011/08/are-we-fast-yet" href="http://www.phoboslab.org/log/2011/08/are-we-fast-yet"&gt;Are We Fast Yet?&lt;/a&gt; de Dominic Szablewski, l&amp;rsquo;auteur du test &lt;a href="http://html5-benchmark.com/"&gt;HTML5 Benchmark&lt;/a&gt; (utilisant ImpactJS) : &amp;ldquo;&lt;em&gt;At the moment &lt;code&gt;requestAnimationFrame()&lt;/code&gt; is truly worthless for games.&lt;/em&gt;&amp;rdquo;&amp;nbsp; &lt;br /&gt;- &lt;a href="http://paulirish.com/2011/requestanimationframe-for-smart-animating/"&gt;requestAnimationFrame for smart animating&lt;/a&gt; de Paul Irish. &lt;br /&gt;- &lt;a title="http://ie.microsoft.com/testdrive/Graphics/RequestAnimationFrame/Default.html" href="http://ie.microsoft.com/testdrive/Graphics/RequestAnimationFrame/Default.html"&gt;requestAnimationFrame API&lt;/a&gt; de notre site IE Test Drive d&amp;eacute;montrant notre impl&amp;eacute;mentation courante dans IE10.&lt;/p&gt;
&lt;h2&gt;Bonus sp&amp;eacute;ciaux pour IE9&lt;/h2&gt;
&lt;p&gt;J&amp;rsquo;ai ajout&amp;eacute; 2 petits bonus pour les utilisateurs d&amp;rsquo;IE9 venant tester mon petit jeu :&lt;/p&gt;
&lt;p&gt;- un mode &amp;eacute;pingl&amp;eacute; avec une ic&amp;ocirc;ne haute r&amp;eacute;solution et une jump list vers des ressources tournant autour du jeu &lt;br /&gt;- des boutons pr&amp;eacute;sents dans le mode &amp;ldquo;preview&amp;rdquo; de Windows 7 pour jouer au jeu d&amp;rsquo;une mani&amp;egrave;re originale ! &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" alt="Clignement d'&amp;oelig;il" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2768.wlEmoticon_2D00_winkingsmile_5F00_1B180398.png" /&gt;&lt;/p&gt;
&lt;p&gt;Vous pouvez ainsi glisser/d&amp;eacute;poser l&amp;rsquo;onglet contenant le jeu dans la barre des t&amp;acirc;ches Windows 7. IE9 prendra alors les couleurs du th&amp;egrave;me du jeu :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5824.image_5F00_thumb_5F00_697AA903.png" /&gt;&lt;/p&gt;
&lt;p&gt;Vous disposerez &amp;eacute;galement d&amp;rsquo;une liste de raccourcis :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5657.image_5F00_thumb_5F00_0C6E9EC4.png" /&gt;&lt;/p&gt;
&lt;p&gt;Le jeu sera donc pr&amp;eacute;sent au sein de la barre des t&amp;acirc;ches de l&amp;rsquo;utilisateur comme si c&amp;rsquo;&amp;eacute;tait une application native.&lt;/p&gt;
&lt;p&gt;Pour finir, vous pouvez m&amp;ecirc;me jouer discr&amp;egrave;tement au jeu en utilisant la fonction de pr&amp;eacute;visualisation d&amp;rsquo;une fen&amp;ecirc;tre de Windows 7 !&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4338.image_5F00_thumb_5F00_358C3758.png" /&gt;&lt;/p&gt;
&lt;p&gt;Il y a 3 petits boutons pour bouger &amp;agrave; gauche/droite et m&amp;ecirc;me sauter dans ce mode particulier. &lt;img class="wlEmoticon wlEmoticon-openmouthedsmile" style="border-style: none;" alt="Rire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8463.wlEmoticon_2D00_openmouthedsmile_5F00_1A3F9DAE.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;Note :&lt;/span&gt;&lt;/strong&gt; il y a une autre d&amp;eacute;dicace &amp;agrave; IE plus ou moins cach&amp;eacute; dans l&amp;rsquo;un des niveaux. La trouverez-vous ?&lt;/p&gt;
&lt;h2&gt;Ajoutez de nouveaux niveaux au jeu&lt;/h2&gt;
&lt;p&gt;Les niveaux sont stock&amp;eacute;s dans le r&amp;eacute;pertoire &amp;ldquo;/levels&amp;rdquo; dans des fichiers de type .TXT. Vous aurez 4 niveaux par d&amp;eacute;faut: 0.txt, 1.txt, 2.txt &amp;amp; 3.txt. Ils sont tout simplement t&amp;eacute;l&amp;eacute;charg&amp;eacute;s via une requ&amp;ecirc;te XMLHTTPRequest en mode asynchrone et ils sont pars&amp;eacute;s afin de construire le syst&amp;egrave;me de rendu et de collisions du jeu.&lt;/p&gt;
&lt;p&gt;Voici par exemple le 2&amp;egrave;me niveau du jeu :&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #008000; font-size: xx-small;" color="#008000" size="1"&gt;.................... .................... ..........X......... .......######....... ..G..............G.. ####..G.G.G.G....### .......G.G.GCG...... ......--------...... ...--...........--.. ......GGGG.GGGG..... .G.G...GG..G....G.G. ####...GG..GGGG.#### .......GG..G........ .1....GGGG.GGGG..... ####################&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Et voici le r&amp;eacute;sultat de son interpr&amp;eacute;tation dans le jeu :&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6567.image_5F00_thumb_5F00_2B8F1D02.png" /&gt;&lt;/p&gt;
&lt;p&gt;Le caract&amp;egrave;re &lt;strong&gt;1&lt;/strong&gt; indique o&amp;ugrave; commence le joueur, &lt;strong&gt;X&lt;/strong&gt; la sortie, &lt;strong&gt;G&lt;/strong&gt; un diamant, &lt;strong&gt;#&lt;/strong&gt; un bloc d&amp;rsquo;une plateforme, &lt;strong&gt;-&lt;/strong&gt; un block que l&amp;rsquo;on peut traverser, &lt;strong&gt;C&lt;/strong&gt; l&amp;rsquo;un des monstres, etc.&lt;/p&gt;
&lt;p&gt;Donc si vous souhaitez ajouter un nouveau niveau au jeu, ajoutez simplement un nouveau fichier de type texte dans le r&amp;eacute;pertoire et &amp;eacute;ditez le niveau vous-m&amp;ecirc;me avec&amp;hellip; Notepad ! Vous devrez aussi modifier la valeur de la variable &lt;em&gt;numberOfLevel&lt;/em&gt; contenue dans le fichier &lt;em&gt;PlateformerGame.js&lt;/em&gt;.&lt;/p&gt;
&lt;h2&gt;Code source non compress&amp;eacute; &amp;agrave; t&amp;eacute;l&amp;eacute;charger&lt;/h2&gt;
&lt;p&gt;Chose promise, chose due, vous pouvez t&amp;eacute;l&amp;eacute;charger le code source ainsi que tous les &amp;eacute;l&amp;eacute;ments du jeu ici : &lt;a href="http://david.blob.core.windows.net/html5platformer/HTML5Platformer.zip"&gt;HTML5 Platformer Non-minified&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;J&amp;rsquo;esp&amp;egrave;re que vous aurez appr&amp;eacute;ci&amp;eacute; cette s&amp;eacute;rie de 3 articles autour du jeu HTML5. Cela vous aidera peut-&amp;ecirc;tre &amp;agrave; transformer vos id&amp;eacute;es de jeux en une r&amp;eacute;alit&amp;eacute; HTML5 ! N&amp;rsquo;h&amp;eacute;sitez pas &amp;agrave; aller jeter un &amp;oelig;il aux 3 autres articles qui ont suivi.&lt;/p&gt;
&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10208530" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Internet+Explorer+9/">Internet Explorer 9</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/XNA/">XNA</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Platformer/">Platformer</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/EaselJS/">EaselJS</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Game/">Game</category></item><item><title>HTML5 Gaming: building the core objects &amp; handling collisions with EaselJS</title><link>http://blogs.msdn.com/b/davrous/archive/2012/03/19/html5-gaming-building-the-core-objects-amp-handling-collisions-with-easeljs.aspx</link><pubDate>Mon, 19 Mar 2012 18:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10191168</guid><dc:creator>David Rousset</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10191168</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/03/19/html5-gaming-building-the-core-objects-amp-handling-collisions-with-easeljs.aspx#comments</comments><description>&lt;p&gt;We’ve seen in the previous article how to animate our sprites using EaselJS: &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/07/21/html5-gaming-animating-sprites-in-canvas-with-easeljs.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/07/21/html5-gaming-animating-sprites-in-canvas-with-easeljs.aspx"&gt;HTML5 Gaming: animating sprites in Canvas with EaselJS&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;We’re now going to see how to create some of our game objects like ennemies and our platformer hero. We will also see how to implement a simple collision mechanism between them. This time, these tutorials will be mainly based on this sample: &lt;a title="http://easeljs.com/examples/game/game.html" href="http://easeljs.com/examples/game/game.html"&gt;EaselJS Game sample&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You’ll find &lt;strong&gt;a live working sample at the end of this article&lt;/strong&gt;. It’s the base of a simple game.&lt;/p&gt;  &lt;p&gt;&lt;a title="PlatformerTutorial2 by Internet Explorer 9, on Flickr" href="http://www.flickr.com/photos/60699397@N08/5987662759/"&gt;&lt;img style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="PlatformerTutorial2" src="http://farm7.static.flickr.com/6013/5987662759_94c799e39a.jpg" width="500" height="353" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Pour ceux qui pratiquent la langue de Molière, vous trouverez une version française ici : &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/08/22/jeux-html5-construction-des-objets-principaux-amp-gestion-des-collisions-avec-easeljs.aspx"&gt;Jeux HTML5: construction des objets principaux &amp;amp; gestion des collisions avec EaselJS&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;This article is the 2nd of a serie of 3:&lt;/p&gt;  &lt;p&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/07/21/html5-gaming-animating-sprites-in-canvas-with-easeljs.aspx"&gt;HTML5 Gaming: animating sprites in Canvas with EaselJS&lt;/a&gt;     &lt;br /&gt;- HTML5 Gaming: building the core objects &amp;amp; handling collisions with EaselJS     &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx"&gt;HTML5 Platformer: the complete port of the XNA game to &amp;lt;canvas&amp;gt; with EaselJS&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;Building the Monster object&lt;/h2&gt;  &lt;p&gt;A monster object has 2 states: &lt;/p&gt;  &lt;p&gt;1 - Running along all the width of the screen    &lt;br /&gt;2 – Being idle once one of the side is reached during a certain amount of time before running again&lt;/p&gt;  &lt;p&gt;It’s very stupid. But if you touch it, you’re dead. This time I’ve merged the sprites coming from the XNA Platformer sample defining the running &amp;amp; the idle sequence inside a unique PNG file. For instance, here is the PNG file for MonsterC:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px" border="0" src="http://david.blob.core.windows.net/easeljstutorial2/img/MonsterB.png" width="950" height="45" /&gt;&lt;/p&gt;  &lt;p&gt;Our Monster object is defined inside &lt;strong&gt;&lt;em&gt;Monster.js&lt;/em&gt;&lt;/strong&gt; and takes the &lt;a href="http://easeljs.com/docs/BitmapAnimation.html"&gt;BitmapAnimation&lt;/a&gt; object as its prototype which has to be used indeed for such scenarios. It contains everything we need: a &lt;em&gt;tick()&lt;/em&gt; method, some hit testing mechanism for our collisions and a way to handle our sprites into several animations. &lt;/p&gt;  &lt;p&gt;We just need to add some specific logic of our monster like the timing part to handle the idle state and we’re done. Here is the code of our &lt;strong&gt;&lt;em&gt;Monster.js &lt;/em&gt;&lt;/strong&gt;file defining our enemies object:&lt;/p&gt;  &lt;pre class="code"&gt;(&lt;span style="color: blue"&gt;function &lt;/span&gt;(window) {
    &lt;span style="color: blue"&gt;function &lt;/span&gt;Monster(monsterName, imgMonster, x_end) {
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.initialize(monsterName, imgMonster, x_end);
    }
    Monster.prototype = &lt;span style="color: blue"&gt;new &lt;/span&gt;BitmapAnimation();

    &lt;span style="color: #006400"&gt;// public properties:
    &lt;/span&gt;Monster.prototype.IDLEWAITTIME = 40;
    Monster.prototype.bounds = 0; &lt;span style="color: #006400"&gt;//visual radial size
    &lt;/span&gt;Monster.prototype.hit = 0;     &lt;span style="color: #006400"&gt;//average radial disparity

    // constructor:
    &lt;/span&gt;Monster.prototype.BitmapAnimation_initialize = Monster.prototype.initialize; &lt;span style="color: #006400"&gt;//unique to avoid overiding base class
&lt;/span&gt;&lt;span style="color: #006400"&gt;
    // variable members to handle the idle state
    // and the time to wait before walking again
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.isInIdleMode = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.idleWaitTicker = 0;

    &lt;span style="color: blue"&gt;var &lt;/span&gt;quaterFrameSize;

    Monster.prototype.initialize = &lt;span style="color: blue"&gt;function &lt;/span&gt;(monsterName, imgMonster, x_end) {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;localSpriteSheet = &lt;span style="color: blue"&gt;new &lt;/span&gt;SpriteSheet({
            images: [imgMonster], &lt;span style="color: #006400"&gt;//image to use
            &lt;/span&gt;frames: {width: 64, height: 64, regX: 32, regY: 32},
            animations: {
                walk: [0, 9, &lt;span style="color: maroon"&gt;&amp;quot;walk&amp;quot;&lt;/span&gt;, 4],
                idle: [10, 20, &lt;span style="color: maroon"&gt;&amp;quot;idle&amp;quot;&lt;/span&gt;, 4]
            }
        });

        SpriteSheetUtils.addFlippedFrames(localSpriteSheet, &lt;span style="color: blue"&gt;true&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

        &lt;span style="color: blue"&gt;this&lt;/span&gt;.BitmapAnimation_initialize(localSpriteSheet);
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.x_end = x_end;

        quaterFrameSize = &lt;span style="color: blue"&gt;this&lt;/span&gt;.spriteSheet.getFrame(0).rect.width / 4;

        &lt;span style="color: #006400"&gt;// start playing the first sequence:
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;walk_h&amp;quot;&lt;/span&gt;);     &lt;span style="color: #006400"&gt;//animate

        // set up a shadow. Note that shadows are ridiculously expensive. You could display hundreds
        // of animated monster if you disabled the shadow.
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.shadow = &lt;span style="color: blue"&gt;new &lt;/span&gt;Shadow(&lt;span style="color: maroon"&gt;&amp;quot;#000&amp;quot;&lt;/span&gt;, 3, 2, 2);

        &lt;span style="color: blue"&gt;this&lt;/span&gt;.name = monsterName;
        &lt;span style="color: #006400"&gt;// 1 = right &amp;amp; -1 = left
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.direction = 1;
        &lt;span style="color: #006400"&gt;// velocity
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.vX = 1;
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.vY = 0;
        &lt;span style="color: #006400"&gt;// starting directly at the first frame of the walk_h sequence
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentFrame = 21;
    }

    Monster.prototype.tick = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: blue"&gt;this&lt;/span&gt;.isInIdleMode) {
            &lt;span style="color: #006400"&gt;// Moving the sprite based on the direction &amp;amp; the speed
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.x += &lt;span style="color: blue"&gt;this&lt;/span&gt;.vX * &lt;span style="color: blue"&gt;this&lt;/span&gt;.direction;
            &lt;span style="color: blue"&gt;this&lt;/span&gt;.y += &lt;span style="color: blue"&gt;this&lt;/span&gt;.vY * &lt;span style="color: blue"&gt;this&lt;/span&gt;.direction;

            &lt;span style="color: #006400"&gt;// Hit testing the screen width, otherwise our sprite would disappear
            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.x &amp;gt;= &lt;span style="color: blue"&gt;this&lt;/span&gt;.x_end - (quaterFrameSize + 1) || &lt;span style="color: blue"&gt;this&lt;/span&gt;.x &amp;lt; (quaterFrameSize + 1)) {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;idle&amp;quot;&lt;/span&gt;);
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.idleWaitTicker = &lt;span style="color: blue"&gt;this&lt;/span&gt;.IDLEWAITTIME;
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.isInIdleMode = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
            }
        }
        &lt;span style="color: blue"&gt;else &lt;/span&gt;{
            &lt;span style="color: blue"&gt;this&lt;/span&gt;.idleWaitTicker--;

            &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.idleWaitTicker == 0) {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.isInIdleMode = &lt;span style="color: blue"&gt;false&lt;/span&gt;;

                &lt;span style="color: #006400"&gt;// Hit testing the screen width, otherwise our sprite would disappear
                &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.x &amp;gt;= &lt;span style="color: blue"&gt;this&lt;/span&gt;.x_end - (quaterFrameSize + 1)) {
                    &lt;span style="color: #006400"&gt;// We've reached the right side of our screen
                    // We need to walk left now to go back to our initial position
                    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.direction = -1;
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;walk&amp;quot;&lt;/span&gt;);
                }

                &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.x &amp;lt; (quaterFrameSize + 1)) {
                    &lt;span style="color: #006400"&gt;// We've reached the left side of our screen
                    // We need to walk right now
                    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.direction = 1;
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;walk_h&amp;quot;&lt;/span&gt;);
                }
            }
        }
    }

    Monster.prototype.hitPoint = &lt;span style="color: blue"&gt;function &lt;/span&gt;(tX, tY) {
        &lt;span style="color: blue"&gt;return this&lt;/span&gt;.hitRadius(tX, tY, 0);
    }

    Monster.prototype.hitRadius = &lt;span style="color: blue"&gt;function &lt;/span&gt;(tX, tY, tHit) {
        &lt;span style="color: #006400"&gt;//early returns speed it up
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(tX - tHit &amp;gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.x + &lt;span style="color: blue"&gt;this&lt;/span&gt;.hit) { &lt;span style="color: blue"&gt;return&lt;/span&gt;; }
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(tX + tHit &amp;lt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.x - &lt;span style="color: blue"&gt;this&lt;/span&gt;.hit) { &lt;span style="color: blue"&gt;return&lt;/span&gt;; }
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(tY - tHit &amp;gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.y + &lt;span style="color: blue"&gt;this&lt;/span&gt;.hit) { &lt;span style="color: blue"&gt;return&lt;/span&gt;; }
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(tY + tHit &amp;lt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.y - &lt;span style="color: blue"&gt;this&lt;/span&gt;.hit) { &lt;span style="color: blue"&gt;return&lt;/span&gt;; }

        &lt;span style="color: #006400"&gt;//now do the circle distance test
        &lt;/span&gt;&lt;span style="color: blue"&gt;return this&lt;/span&gt;.hit + tHit &amp;gt; Math.sqrt(Math.pow(Math.abs(&lt;span style="color: blue"&gt;this&lt;/span&gt;.x - tX), 2) + Math.pow(Math.abs(&lt;span style="color: blue"&gt;this&lt;/span&gt;.y - tY), 2));
    }

    window.Monster = Monster;
} (window));&lt;/pre&gt;


&lt;p&gt;The collision part is handled via the &lt;em&gt;&lt;strong&gt;hitPoint()&lt;/strong&gt;&lt;/em&gt; and &lt;em&gt;&lt;strong&gt;hitRadius()&lt;/strong&gt;&lt;/em&gt; functions. The hit testing is done via circle which is a bit less accurate than a boxing mode. &lt;/p&gt;

&lt;h2&gt;Building the Player object&lt;/h2&gt;

&lt;p&gt;The logic of the player object is a bit different than the monsters. The x &amp;amp; y position are normally controlled by the user moving the character with the keyboard. Our hero has more animations than the monsters as he can die, jump, move, celebrate and be in the idle mode. &lt;/p&gt;

&lt;p&gt;Here is the PNG associated to him:&lt;/p&gt;

&lt;p&gt;&lt;img style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px" border="0" src="http://david.blob.core.windows.net/easeljstutorial2/img/Player.png" width="950" height="130" /&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we’ll keep it simple. We will only handle the walk, idle &amp;amp; die sequence. Still, let’s load all the animations for a futur potential usage. Here is the code available in the &lt;strong&gt;&lt;em&gt;Player.js&lt;/em&gt;&lt;/strong&gt; file. Reading the code and its comments should provide enough details:&lt;/p&gt;

&lt;pre class="code"&gt;(&lt;span style="color: blue"&gt;function &lt;/span&gt;(window) {
    &lt;span style="color: blue"&gt;function &lt;/span&gt;Player(imgPlayer, x_start, x_end) {
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.initialize(imgPlayer, x_start, x_end);
    }
    Player.prototype = &lt;span style="color: blue"&gt;new &lt;/span&gt;BitmapAnimation();

    &lt;span style="color: #006400"&gt;// public properties:
    &lt;/span&gt;Player.prototype.bounds = 0;
    Player.prototype.hit = 0;
    Player.prototype.alive = &lt;span style="color: blue"&gt;true&lt;/span&gt;;

    &lt;span style="color: #006400"&gt;// constructor:
    &lt;/span&gt;Player.prototype.BitmapAnimation_initialize = Player.prototype.initialize; &lt;span style="color: #006400"&gt;//unique to avoid overiding base class
&lt;/span&gt;&lt;span style="color: #006400"&gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;quaterFrameSize;
   
    Player.prototype.initialize = &lt;span style="color: blue"&gt;function &lt;/span&gt;(imgPlayer, x_end) {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;localSpriteSheet = &lt;span style="color: blue"&gt;new &lt;/span&gt;SpriteSheet({
            images: [imgPlayer], &lt;span style="color: #006400"&gt;//image to use
            &lt;/span&gt;frames: { width:64, height:64, regX:32, regY: 32 },
            animations: {
                walk: [0, 9, &lt;span style="color: maroon"&gt;&amp;quot;walk&amp;quot;&lt;/span&gt;, 4],
                die: [10, 21, &lt;span style="color: blue"&gt;false&lt;/span&gt;, 4],
                jump: [22, 32],
                celebrate: [33, 43],
                idle: [44, 44]
            }
        });

        SpriteSheetUtils.addFlippedFrames(localSpriteSheet, &lt;span style="color: blue"&gt;true&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

        &lt;span style="color: blue"&gt;this&lt;/span&gt;.BitmapAnimation_initialize(localSpriteSheet);
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.x_end = x_end;

        quaterFrameSize = &lt;span style="color: blue"&gt;this&lt;/span&gt;.spriteSheet.getFrame(0).rect.width / 4;

        &lt;span style="color: #006400"&gt;// start playing the first sequence:
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;idle&amp;quot;&lt;/span&gt;);     &lt;span style="color: #006400"&gt;//animate
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.isInIdleMode = &lt;span style="color: blue"&gt;true&lt;/span&gt;;

        &lt;span style="color: #006400"&gt;// set up a shadow. Note that shadows are ridiculously expensive. You could display hundreds
        // of animated monster if you disabled the shadow.
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.shadow = &lt;span style="color: blue"&gt;new &lt;/span&gt;Shadow(&lt;span style="color: maroon"&gt;&amp;quot;#000&amp;quot;&lt;/span&gt;, 3, 2, 2);
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.name = &lt;span style="color: maroon"&gt;&amp;quot;Hero&amp;quot;&lt;/span&gt;;
        &lt;span style="color: #006400"&gt;// 1 = right &amp;amp; -1 = left
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.direction = 1;

        &lt;span style="color: #006400"&gt;// velocity
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.vX = 1;
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.vY = 0;
        &lt;span style="color: #006400"&gt;// starting directly at the first frame of the walk_h sequence
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentFrame = 66;

        &lt;span style="color: #006400"&gt;//Size of the Bounds for the collision's tests
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.bounds = 28;
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.hit = &lt;span style="color: blue"&gt;this&lt;/span&gt;.bounds;
    }

    Player.prototype.tick = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.alive &amp;amp;&amp;amp; !&lt;span style="color: blue"&gt;this&lt;/span&gt;.isInIdleMode) {
            &lt;span style="color: #006400"&gt;// Hit testing the screen width, otherwise our sprite would disappear
            // The player is blocked at each side but we keep the walk_right or walk_animation running
            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;((&lt;span style="color: blue"&gt;this&lt;/span&gt;.x + &lt;span style="color: blue"&gt;this&lt;/span&gt;.direction &amp;gt; quaterFrameSize) &amp;amp;&amp;amp; (&lt;span style="color: blue"&gt;this&lt;/span&gt;.x + (&lt;span style="color: blue"&gt;this&lt;/span&gt;.direction * 2) &amp;lt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.x_end - quaterFrameSize + 1)) {
                &lt;span style="color: #006400"&gt;// Moving the sprite based on the direction &amp;amp; the speed
                &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.x += &lt;span style="color: blue"&gt;this&lt;/span&gt;.vX * &lt;span style="color: blue"&gt;this&lt;/span&gt;.direction;
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.y += &lt;span style="color: blue"&gt;this&lt;/span&gt;.vY * &lt;span style="color: blue"&gt;this&lt;/span&gt;.direction;
            }
        }
    }

    window.Player = Player;
} (window));&lt;/pre&gt;


&lt;p&gt;The player will be remotely controlled into the main page.&lt;/p&gt;

&lt;h2&gt;Building the Content Manager object&lt;/h2&gt;

&lt;p&gt;Usually, the first step of a HTML5 game is to download all the needed resources before starting the game. In my case, you’ll find a very basic ContentManager available in the &lt;strong&gt;&lt;em&gt;ContentManager.js&lt;/em&gt;&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;Here is the code: &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Used to download all needed resources from our
// webserver
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;ContentManager() {
    &lt;span style="color: #006400"&gt;// Method called back once all elements
    // have been downloaded
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;ondownloadcompleted;
    &lt;span style="color: #006400"&gt;// Number of elements to download
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;NUM_ELEMENTS_TO_DOWNLOAD = 15;

    &lt;span style="color: #006400"&gt;// setting the callback method
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.SetDownloadCompleted = &lt;span style="color: blue"&gt;function &lt;/span&gt;(callbackMethod) {
        ondownloadcompleted = callbackMethod;
    };

    &lt;span style="color: #006400"&gt;// We have 4 type of enemies, 1 hero &amp;amp; 1 type of tile
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterA = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image();
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterB = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image(); 
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterC = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image(); 
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterD = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image();
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgTile = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image();
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgPlayer = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image();

    &lt;span style="color: #006400"&gt;// the background can be created with 3 different layers
    // those 3 layers exist in 3 versions
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgBackgroundLayers = &lt;span style="color: blue"&gt;new &lt;/span&gt;Array();
    &lt;span style="color: blue"&gt;var &lt;/span&gt;numImagesLoaded = 0;

    &lt;span style="color: #006400"&gt;// public method to launch the download process
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.StartDownload = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
        SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgPlayer, &lt;span style="color: maroon"&gt;&amp;quot;img/Player.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);
        SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterA, &lt;span style="color: maroon"&gt;&amp;quot;img/MonsterA.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);
        SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterB, &lt;span style="color: maroon"&gt;&amp;quot;img/MonsterB.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);
        SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterC, &lt;span style="color: maroon"&gt;&amp;quot;img/MonsterC.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);
        SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterD, &lt;span style="color: maroon"&gt;&amp;quot;img/MonsterD.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);
        SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgTile, &lt;span style="color: maroon"&gt;&amp;quot;img/Tiles/BlockA0.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);

        &lt;span style="color: #006400"&gt;// download the 3 layers * 3 versions
        &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i = 0; i &amp;lt; 3; i++) {
            &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgBackgroundLayers[i] = &lt;span style="color: blue"&gt;new &lt;/span&gt;Array();
            &lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;j = 0; j &amp;lt; 3; j++) {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgBackgroundLayers[i][j] = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image();
                SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgBackgroundLayers[i][j], &lt;span style="color: maroon"&gt;&amp;quot;img/Backgrounds/Layer&amp;quot; &lt;/span&gt;+ i &lt;br /&gt;                                      + &lt;span style="color: maroon"&gt;&amp;quot;_&amp;quot; &lt;/span&gt;+ j + &lt;span style="color: maroon"&gt;&amp;quot;.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);
            }
        }
    }

    &lt;span style="color: blue"&gt;function &lt;/span&gt;SetDownloadParameters(imgElement, url, loadedHandler, errorHandler) {
        imgElement.src = url;
        imgElement.onload = loadedHandler;
        imgElement.onerror = errorHandler;
    }

    &lt;span style="color: #006400"&gt;// our global handler 
    &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;handleImageLoad(e) {
        numImagesLoaded++

        &lt;span style="color: #006400"&gt;// If all elements have been downloaded
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(numImagesLoaded == NUM_ELEMENTS_TO_DOWNLOAD) {
            numImagesLoaded = 0;
            &lt;span style="color: #006400"&gt;// we're calling back the method set by SetDownloadCompleted
            &lt;/span&gt;ondownloadcompleted();
        }
    }

    &lt;span style="color: #006400"&gt;//called if there is an error loading the image (usually due to a 404)
    &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;handleImageError(e) {
        console.log(&lt;span style="color: maroon"&gt;&amp;quot;Error Loading Image : &amp;quot; &lt;/span&gt;+ e.target.src);
    }
}&lt;/pre&gt;

&lt;p&gt;It lacks several things to be a good content manager: a download progress indicator, a better error handler, localStorage usage, a more generic code, etc. But I’ve tried to build a basic &amp;amp; easy to understand game. &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5466.wlEmoticon_2D00_winkingsmile_5F00_621EDBCD.png" /&gt;&lt;/p&gt;

&lt;h2&gt;Setting up all the pieces inside the main page&lt;/h2&gt;

&lt;p&gt;Now that we have the core parts of our game, we can start to use them to build a very basic platformer game. Let’s review each part of our main page hosting our game. In the&lt;em&gt; init()&lt;/em&gt; method, we’re creating the stage and we’re using the &lt;em&gt;ContentManager&lt;/em&gt; object to download our PNG files:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;init() {
    &lt;span style="color: #006400"&gt;//find canvas and load images, wait for last image to load
    &lt;/span&gt;canvas = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;testCanvas&amp;quot;&lt;/span&gt;);

    &lt;span style="color: #006400"&gt;// create a new stage and point it at our canvas:
    &lt;/span&gt;stage = &lt;span style="color: blue"&gt;new &lt;/span&gt;Stage(canvas);
    &lt;span style="color: #006400"&gt;// grab canvas width and height for later calculations:
    &lt;/span&gt;screen_width = canvas.width;
    screen_height = canvas.height;

    contentManager = &lt;span style="color: blue"&gt;new &lt;/span&gt;ContentManager();
    contentManager.SetDownloadCompleted(startGame);
    contentManager.StartDownload();
}&lt;/pre&gt;

&lt;p&gt;Once done, the &lt;em&gt;startGame()&lt;/em&gt; function is called. It first uses the &lt;em&gt;CreateAndAddRandomBackground()&lt;/em&gt; function which create a random background based on 3 different layers. Then, it creates our &lt;em&gt;Hero&lt;/em&gt; and set its Y position in a random place. Just under the hero, we’re building a very basic platform where our hero will be able to walk on to. Finally, we’re building 4 &lt;em&gt;Monster()&lt;/em&gt; objects inside the &lt;em&gt;Monsters&lt;/em&gt; array and we add them also to the stage. &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;startGame() {
    &lt;span style="color: #006400"&gt;// Random number to set the Y position
    // of our Hero &amp;amp; Enemies
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;randomY;
    
    CreateAndAddRandomBackground();

    &lt;span style="color: #006400"&gt;// Our hero can be moved with the arrow keys (left, right)
    &lt;/span&gt;document.onkeydown = handleKeyDown;
    document.onkeyup = handleKeyUp;

    &lt;span style="color: #006400"&gt;// Creating the Hero
    &lt;/span&gt;randomY = 32 + (Math.floor(Math.random() * 7) * 64);
    Hero = &lt;span style="color: blue"&gt;new &lt;/span&gt;Player(contentManager.imgPlayer, screen_width);
    Hero.x = 400;
    Hero.y = randomY;

    &lt;span style="color: #006400"&gt;//Tile where the hero &amp;amp; the ennemies will be able to walk on to
    &lt;/span&gt;bmpSeqTile = &lt;span style="color: blue"&gt;new &lt;/span&gt;Bitmap(contentManager.imgTile);
    bmpSeqTile.regX = bmpSeqTile.frameWidth / 2 | 0;
    bmpSeqTile.regY = bmpSeqTile.frameHeight / 2 | 0;

    &lt;span style="color: #006400"&gt;// Taking the same tile all over the width of the game
    &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i = 0; i &amp;lt; 20; i++) {
        &lt;span style="color: #006400"&gt;// clone the original tile, so we don't need to set shared properties:
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;bmpSeqTileCloned = bmpSeqTile.clone();

        &lt;span style="color: #006400"&gt;// set display properties:
        &lt;/span&gt;bmpSeqTileCloned.x = 0 + (i * 40);
        bmpSeqTileCloned.y = randomY + 32;

        &lt;span style="color: #006400"&gt;// add to the display list:
        &lt;/span&gt;stage.addChild(bmpSeqTileCloned);
    }

    &lt;span style="color: #006400"&gt;// Our Monsters collection
    &lt;/span&gt;Monsters = &lt;span style="color: blue"&gt;new &lt;/span&gt;Array();

    &lt;span style="color: #006400"&gt;// Creating the first type of monster
    &lt;/span&gt;randomY = 32 + (Math.floor(Math.random() * 7) * 64);
    Monsters[0] = &lt;span style="color: blue"&gt;new &lt;/span&gt;Monster(&lt;span style="color: maroon"&gt;&amp;quot;MonsterA&amp;quot;&lt;/span&gt;, contentManager.imgMonsterA, screen_width);
    Monsters[0].x = 20;
    Monsters[0].y = randomY;

    &lt;span style="color: #006400"&gt;// Creating the second type of monster
    &lt;/span&gt;randomY = 32 + (Math.floor(Math.random() * 7) * 64);
    Monsters[1] = &lt;span style="color: blue"&gt;new &lt;/span&gt;Monster(&lt;span style="color: maroon"&gt;&amp;quot;MonsterB&amp;quot;&lt;/span&gt;, contentManager.imgMonsterB, screen_width);
    Monsters[1].x = 750;
    Monsters[1].y = randomY;

    &lt;span style="color: #006400"&gt;// Creating the third type of monster
    &lt;/span&gt;randomY = 32 + (Math.floor(Math.random() * 7) * 64);
    Monsters[2] = &lt;span style="color: blue"&gt;new &lt;/span&gt;Monster(&lt;span style="color: maroon"&gt;&amp;quot;MonsterC&amp;quot;&lt;/span&gt;, contentManager.imgMonsterC, screen_width);
    Monsters[2].x = 100;
    Monsters[2].y = randomY;

    &lt;span style="color: #006400"&gt;// Creating the forth type of monster
    &lt;/span&gt;randomY = 32 + (Math.floor(Math.random() * 7) * 64);
    Monsters[3] = &lt;span style="color: blue"&gt;new &lt;/span&gt;Monster(&lt;span style="color: maroon"&gt;&amp;quot;MonsterD&amp;quot;&lt;/span&gt;, contentManager.imgMonsterD, screen_width);
    Monsters[3].x = 650;
    Monsters[3].y = randomY;

    &lt;span style="color: #006400"&gt;// Adding all the monsters to the stage
    &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i=0; i&amp;lt;Monsters.length;i++){
        stage.addChild(Monsters[i]);
    }
    stage.addChild(Hero);
        
    &lt;span style="color: #006400"&gt;// we want to do some work before we update the canvas,
    // otherwise we could use Ticker.addListener(stage);
    &lt;/span&gt;Ticker.addListener(window);
    &lt;span style="color: #006400"&gt;// Best Framerate targeted (60 FPS)
    &lt;/span&gt;Ticker.useRAF = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
    Ticker.setFPS(60);
}&lt;/pre&gt;


&lt;p&gt;And the end, there are 2 obvious keyboard handler that simply play the walk_left or walk_right animation of our hero based on the arrows keys. And finally, the core logic of our game is contained in a few line of code inside the tick() method of course:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;tick() {
    &lt;span style="color: #006400"&gt;// looping inside the Monsters collection
    &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(monster &lt;span style="color: blue"&gt;in &lt;/span&gt;Monsters) {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;m = Monsters[monster];
        &lt;span style="color: #006400"&gt;// Calling explicitly each tick method 
        // to launch the update logic of each monster
        &lt;/span&gt;m.tick();
        
        &lt;span style="color: #006400"&gt;// If the Hero is still alive and if he's too near
        // from one of the monster...
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(Hero.alive &amp;amp;&amp;amp; m.hitRadius(Hero.x, Hero.y, Hero.hit)) {
            &lt;span style="color: #006400"&gt;//...he must die unfortunately!
            &lt;/span&gt;Hero.alive = &lt;span style="color: blue"&gt;false&lt;/span&gt;;

            &lt;span style="color: #006400"&gt;// Playing the proper animation based on
            // the current direction of our hero
            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(Hero.direction == 1) {
                Hero.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;die_h&amp;quot;&lt;/span&gt;);
            }
            &lt;span style="color: blue"&gt;else &lt;/span&gt;{
                Hero.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;die&amp;quot;&lt;/span&gt;);
            }

            &lt;span style="color: blue"&gt;continue&lt;/span&gt;;
        }
    }

    &lt;span style="color: #006400"&gt;// Update logic of the hero
    &lt;/span&gt;Hero.tick();

    &lt;span style="color: #006400"&gt;// update the stage:
    &lt;/span&gt;stage.update();
}&lt;/pre&gt;


&lt;p&gt;We’re just checking during each tick if one of the monsters is not currently hitting our hero based on their collision parameters. If one monster is too near of our hero, our poor hero must die.&lt;/p&gt;

&lt;h2&gt;Play with the live sample&lt;/h2&gt;

&lt;p&gt;You can now play with the live sample just below. Every time you’ll press the start button a new background will be generated and each character (enemies &amp;amp; hero) will be placed at a different position. You can also move right or left using the keyboard. By the way, don’t panic. As you can’t jump, there is currently no way to win in this game. This is a 100% looser game (first of genre?). &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5466.wlEmoticon_2D00_winkingsmile_5F00_621EDBCD.png" /&gt;&lt;/p&gt;
&lt;iframe style="border-top: #ffffff 0px solid; border-right: #ffffff 0px solid; border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid" height="525" src="http://david.blob.core.windows.net/easeljstutorial2/easelJSCoreObjectsAndCollision.html" width="830"&gt;&lt;/iframe&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; as there is no progress bar, you need to wait a bit before playing after pressing the “Start” button.&lt;/p&gt;

&lt;p&gt;You can play it also via this link: &lt;a title="http://david.blob.core.windows.net/easeljstutorial2/easelJSCoreObjectsAndCollision.html" href="http://david.blob.core.windows.net/easeljstutorial2/easelJSCoreObjectsAndCollision.html"&gt;easelJSCoreObjectsAndCollision&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next part will be to handle the jump sequence using a simple physics engine, loading the music &amp;amp; sound effects and finally loading the levels. But the core is here if you’d like to create your own simple game, you now have all the cards in your hand! &lt;img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1157.wlEmoticon_2D00_smile_5F00_1A5D52E6.png" /&gt;&lt;/p&gt;

&lt;p&gt;But if you’d like to review the full game with all its source code, jump to the next article : &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx"&gt;HTML5 Platformer: the complete port of the XNA game to &amp;lt;canvas&amp;gt; with EaselJS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/strong&gt; this tutorial has originally been written for &lt;strong&gt;EaselJS 0.3.2&lt;/strong&gt; in July 2010 and has been updated for &lt;strong&gt;EaselJS 0.4&lt;/strong&gt;. For those of you who read the version 0.3.2, here are the main changes for this tutorial to be aware of:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;BitmapSequence is not available anymore in 0.4 and has been replaced by BitmapAnimation &lt;/li&gt;

  &lt;li&gt;You can now slow down the animation loop of the sprites natively while building the SpriteSheet object &lt;/li&gt;

  &lt;li&gt;EaselJS 0.4 can now use requestAnimationFrame for more efficient animations on supported browsers (like IE10+, Firefox 4.0+ &amp;amp; Chrome via the appropriate vendors’ prefixes). &lt;/li&gt;

  &lt;li&gt;You have to explicitly call the tick() method of each object in a global handler rather than having a global Ticker automatically calling your tick implementation. &lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10191168" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Tutorial/">Tutorial</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/EaselJS/">EaselJS</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Game/">Game</category></item><item><title>Jeux HTML5: construction des objets principaux &amp; gestion des collisions avec EaselJS</title><link>http://blogs.msdn.com/b/davrous/archive/2012/03/19/jeux-html5-construction-des-objets-principaux-amp-gestion-des-collisions-avec-easeljs.aspx</link><pubDate>Mon, 19 Mar 2012 17:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10198571</guid><dc:creator>David Rousset</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10198571</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/03/19/jeux-html5-construction-des-objets-principaux-amp-gestion-des-collisions-avec-easeljs.aspx#comments</comments><description>&lt;p&gt;Nous avons vu dans l’article précédent comment animer des sprites avec EaselJS : &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/07/22/jeux-html5-animation-de-sprites-dans-l-233-l-233-ment-canvas-gr-226-ce-224-easeljs.aspx"&gt;Jeux HTML5: animation de sprites dans l’élément Canvas grâce à EaselJS&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Nous allons maintenant voir comment créer certains des objets de base de notre jeu comme les ennemies ou le héro de notre jeu de plateforme. Nous verrons aussi comment implémenter un mécanisme basique de collision entre les 2. Cette fois-ci ce tutoriel sera principalement basé sur l’exemple suivant: &lt;a title="http://easeljs.com/examples/game/game.html" href="http://easeljs.com/examples/game/game.html"&gt;EaselJS Game sample&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Vous trouverez également &lt;strong&gt;un exemple fonctionnel à la fin de cet article&lt;/strong&gt;. C’est la base d’un petit jeu.&lt;/p&gt;  &lt;p&gt;&lt;a title="PlatformerTutorial2 by Internet Explorer 9, on Flickr" href="http://www.flickr.com/photos/60699397@N08/5987662759/"&gt;&lt;img style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="PlatformerTutorial2" src="http://farm7.static.flickr.com/6013/5987662759_94c799e39a.jpg" width="500" height="353" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Cette article est le 2ème d’une série de 3 articles :&lt;/p&gt;  &lt;p&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/07/22/jeux-html5-animation-de-sprites-dans-l-233-l-233-ment-canvas-gr-226-ce-224-easeljs.aspx"&gt;Jeux HTML5: animation de sprites dans l’élément Canvas grâce à EaselJS&lt;/a&gt;     &lt;br /&gt;- Jeux HTML5: construction des objets principaux &amp;amp; gestion des collisions avec EaselJS     &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-portage-complet-du-jeu-xna-vers-lt-canvas-gt-gr-226-ce-224-easeljs.aspx"&gt;HTML5 Platformer: portage complet du jeu XNA vers &amp;lt;canvas&amp;gt; grâce à EaselJS&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;Construction de l’objet Monster&lt;/h2&gt;  &lt;p&gt;Cet objet dispose de 2 états :&lt;/p&gt;  &lt;p&gt;1 – En train de courir sur la longueur de l’écran    &lt;br /&gt;2 – Etre en état de repos une fois l’un des bords de l’écran atteint avant de courir à nouveau.&lt;/p&gt;  &lt;p&gt;Oui, je sais, la vie d’un monstre n’est pas palpitante. Mais c’est comme ça ! Attention, aussi stupide soit-il, si vous le touchez vous mourrez.&lt;/p&gt;  &lt;p&gt;Cette fois-ci, j’ai fusionné en un unique fichier PNG les sprites venant de l’exemple XNA Platformer définissant les séquences où le personnage court et où il reste immobile. Voici par exemple le PNG associé au monstre MonsterC :&lt;/p&gt;  &lt;p&gt;&lt;img style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px" border="0" src="http://david.blob.core.windows.net/easeljstutorial2/img/MonsterB.png" width="950" height="45" /&gt;&lt;/p&gt;  &lt;p&gt;Notre objet monstre est défini au sein du fichier &lt;strong&gt;&lt;em&gt;Monster.js&lt;/em&gt; &lt;/strong&gt;et utilise l’objet &lt;a href="http://easeljs.com/docs/BitmapAnimation.html"&gt;BitmapAnimation&lt;/a&gt; comme prototype qui se prête en effet très bien à ce genre de scénarios. Il contient tout ce dont nous avons besoin: une méthode &lt;em&gt;tick()&lt;/em&gt;, un mécanisme de “hit testing” pour vérifier les collisions et une manière de gérer nos sprites sous la forme de plusieurs animations séparées.&lt;/p&gt;  &lt;p&gt;Il nous faut juste y ajouter de la logique spécifique à notre monstre comme la gestion d’un timer gérant l’état “au repos” et cela devrait faire l’affaire. Voici ainsi le code du fichier &lt;strong&gt;&lt;em&gt;Monster.js&lt;/em&gt; &lt;/strong&gt;définissant donc nos ennemies dans le jeu :&lt;/p&gt;  &lt;pre class="code"&gt;(&lt;span style="color: blue"&gt;function &lt;/span&gt;(window) {
    &lt;span style="color: blue"&gt;function &lt;/span&gt;Monster(monsterName, imgMonster, x_end) {
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.initialize(monsterName, imgMonster, x_end);
    }
    Monster.prototype = &lt;span style="color: blue"&gt;new &lt;/span&gt;BitmapAnimation();

    &lt;span style="color: #006400"&gt;// propriétés publiques &lt;br /&gt;    &lt;/span&gt;Monster.prototype.IDLEWAITTIME = 40;
    Monster.prototype.bounds = 0; &lt;br /&gt;    &lt;span style="color: #006400"&gt;//taille du cercle visible &lt;br /&gt;    &lt;/span&gt;Monster.prototype.hit = 0;

    &lt;span style="color: #006400"&gt;// constructeur: &lt;br /&gt;    // unique pour éviter d'écraser celui de la classe de base &lt;br /&gt;    &lt;/span&gt;Monster.prototype.BitmapAnimation_initialize = Monster.prototype.initialize;

    &lt;span style="color: #006400"&gt;// variables membres pour gérer l’état au repos &lt;br /&gt;    // et le temps à attendre avant de courir à nouveau &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.isInIdleMode = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.idleWaitTicker = 0;

    &lt;span style="color: blue"&gt;var &lt;/span&gt;quaterFrameSize;

    Monster.prototype.initialize = &lt;span style="color: blue"&gt;function &lt;/span&gt;(monsterName, imgMonster, x_end) {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;localSpriteSheet = &lt;span style="color: blue"&gt;new &lt;/span&gt;SpriteSheet({
            images: [imgMonster], &lt;span style="color: #006400"&gt;//image à utiliser &lt;br /&gt;            &lt;/span&gt;frames: {width: 64, height: 64, regX: 32, regY: 32},
            animations: {
                walk: [0, 9, &lt;span style="color: maroon"&gt;&amp;quot;walk&amp;quot;&lt;/span&gt;, 4],
                idle: [10, 20, &lt;span style="color: maroon"&gt;&amp;quot;idle&amp;quot;&lt;/span&gt;, 4]
            }
        });

        SpriteSheetUtils.addFlippedFrames(localSpriteSheet, &lt;span style="color: blue"&gt;true&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

        &lt;span style="color: blue"&gt;this&lt;/span&gt;.BitmapAnimation_initialize(localSpriteSheet);
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.x_end = x_end;

        quaterFrameSize = &lt;span style="color: blue"&gt;this&lt;/span&gt;.spriteSheet.getFrame(0).rect.width / 4;

        &lt;span style="color: #006400"&gt;// on commence à jouer la 1ère séquence &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;walk_h&amp;quot;&lt;/span&gt;);

        &lt;span style="color: #006400"&gt;// mise en place d’une ombre portée. Attention, gros impact sur les performances &lt;br /&gt;        // en fonction des navigateurs/plateformes matérielles. &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.shadow = &lt;span style="color: blue"&gt;new &lt;/span&gt;Shadow(&lt;span style="color: maroon"&gt;&amp;quot;#000&amp;quot;&lt;/span&gt;, 3, 2, 2);

        &lt;span style="color: blue"&gt;this&lt;/span&gt;.name = monsterName;
        &lt;span style="color: #006400"&gt;// 1 = droite &amp;amp; -1 = gauche &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.direction = 1;
        &lt;span style="color: #006400"&gt;// vitesse &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.vX = 1;
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.vY = 0;
        &lt;span style="color: #006400"&gt;// on saute directement à la 1ère frame de la séquence walk_h &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentFrame = 21;
    }

    Monster.prototype.tick = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: blue"&gt;this&lt;/span&gt;.isInIdleMode) {
            &lt;span style="color: #006400"&gt;// On bouge le sprite en fonction de la direction et de la vitesse &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.x += &lt;span style="color: blue"&gt;this&lt;/span&gt;.vX * &lt;span style="color: blue"&gt;this&lt;/span&gt;.direction;
            &lt;span style="color: blue"&gt;this&lt;/span&gt;.y += &lt;span style="color: blue"&gt;this&lt;/span&gt;.vY * &lt;span style="color: blue"&gt;this&lt;/span&gt;.direction;

            &lt;span style="color: #006400"&gt;// On teste les bords de l’écran sinon notre sprite partirait vivre ailleurs (dans le cloud?) &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.x &amp;gt;= &lt;span style="color: blue"&gt;this&lt;/span&gt;.x_end - (quaterFrameSize + 1) || &lt;span style="color: blue"&gt;this&lt;/span&gt;.x &amp;lt; (quaterFrameSize + 1)) {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;idle&amp;quot;&lt;/span&gt;);
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.idleWaitTicker = &lt;span style="color: blue"&gt;this&lt;/span&gt;.IDLEWAITTIME;
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.isInIdleMode = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
            }
        }
        &lt;span style="color: blue"&gt;else &lt;/span&gt;{
            &lt;span style="color: blue"&gt;this&lt;/span&gt;.idleWaitTicker--;

            &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.idleWaitTicker == 0) {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.isInIdleMode = &lt;span style="color: blue"&gt;false&lt;/span&gt;;

                &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.x &amp;gt;= &lt;span style="color: blue"&gt;this&lt;/span&gt;.x_end - (quaterFrameSize + 1)) {
                    &lt;span style="color: #006400"&gt;// Nous avons atteint le côté droit de l'écran &lt;br /&gt;                    // Nous devons maintenant marcher vers la gauche &lt;br /&gt;                    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.direction = -1;
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;walk&amp;quot;&lt;/span&gt;);
                }

                &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.x &amp;lt; (quaterFrameSize + 1)) {
                    &lt;span style="color: #006400"&gt;// Nous avons atteint le côté gauche de l'écran &lt;br /&gt;                    // Nous devons maintenant marcher vers la droite &lt;br /&gt;                    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.direction = 1;
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;walk_h&amp;quot;&lt;/span&gt;);
                }
            }
        }
    }

    Monster.prototype.hitPoint = &lt;span style="color: blue"&gt;function &lt;/span&gt;(tX, tY) {
        &lt;span style="color: blue"&gt;return this&lt;/span&gt;.hitRadius(tX, tY, 0);
    }

    Monster.prototype.hitRadius = &lt;span style="color: blue"&gt;function &lt;/span&gt;(tX, tY, tHit) {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(tX - tHit &amp;gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.x + &lt;span style="color: blue"&gt;this&lt;/span&gt;.hit) { &lt;span style="color: blue"&gt;return&lt;/span&gt;; }
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(tX + tHit &amp;lt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.x - &lt;span style="color: blue"&gt;this&lt;/span&gt;.hit) { &lt;span style="color: blue"&gt;return&lt;/span&gt;; }
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(tY - tHit &amp;gt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.y + &lt;span style="color: blue"&gt;this&lt;/span&gt;.hit) { &lt;span style="color: blue"&gt;return&lt;/span&gt;; }
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(tY + tHit &amp;lt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.y - &lt;span style="color: blue"&gt;this&lt;/span&gt;.hit) { &lt;span style="color: blue"&gt;return&lt;/span&gt;; }

        &lt;span style="color: #006400"&gt;//test basé sur une distance à base de cercle &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;return this&lt;/span&gt;.hit + tHit &amp;gt; Math.sqrt(Math.pow(Math.abs(&lt;span style="color: blue"&gt;this&lt;/span&gt;.x - tX), 2) + Math.pow(Math.abs(&lt;span style="color: blue"&gt;this&lt;/span&gt;.y - tY), 2));
    }

    window.Monster = Monster;
} (window));&lt;/pre&gt;

&lt;p&gt;La collision est gérée par les méthodes &lt;em&gt;&lt;strong&gt;hitPoint()&lt;/strong&gt;&lt;/em&gt; et &lt;strong&gt;&lt;em&gt;hitRadius()&lt;/em&gt;&lt;/strong&gt;. Le “hit testing” est fait via des cercles ce qui est moins précis qu’un modèle de boites.&lt;/p&gt;

&lt;h2&gt;Construction de l’objet Player&lt;/h2&gt;

&lt;p&gt;En tant que digne représentant du joueur humain qui l’anime, la logique associée au personnage principal du jeu est un peu différente des monstres et bien entendu plus évoluée (quoique…) !&lt;/p&gt;

&lt;p&gt;Par exemple, les positions x &amp;amp; y sont normalement contrôlées par l’utilisateur souhaitant bouger son personnage avec son clavier. Par ailleurs, notre héro dispose de plus d’animations que nos monstres puisqu’il peut mourir, sauter, bouger, célébrer sa victoire et être immobile.&lt;/p&gt;

&lt;p&gt;Voici ainsi le PNG qui lui est dédié :&lt;/p&gt;

&lt;p&gt;&lt;img style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px" border="0" src="http://david.blob.core.windows.net/easeljstutorial2/img/Player.png" width="950" height="130" /&gt;&lt;/p&gt;

&lt;p&gt;Bon, dans ce tutoriel, on va rester simple. Nous allons uniquement gérer les séquence où il court, il meurt et où il reste immobile. Cependant, chargeons malgré tout toutes les animations pour un potentiel usage futur. Voici le code du fichier &lt;strong&gt;&lt;em&gt;Player.js&lt;/em&gt;&lt;/strong&gt;. La lecture du code et de ses commentaires devraient vous fournir suffisamment de détails pour en comprendre son fonctionnement :&lt;/p&gt;

&lt;pre class="code"&gt;(&lt;span style="color: blue"&gt;function &lt;/span&gt;(window) {
    &lt;span style="color: blue"&gt;function &lt;/span&gt;Player(imgPlayer, x_start, x_end) {
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.initialize(imgPlayer, x_start, x_end);
    }
    Player.prototype = &lt;span style="color: blue"&gt;new &lt;/span&gt;BitmapAnimation();

    &lt;span style="color: #006400"&gt;// propriétés publiques &lt;br /&gt;    &lt;/span&gt;Player.prototype.bounds = 0;
    Player.prototype.hit = 0;
    Player.prototype.alive = &lt;span style="color: blue"&gt;true&lt;/span&gt;;

    &lt;span style="color: #006400"&gt;// constructeur: &lt;br /&gt;    // unique pour éviter d'écraser celui de la classe de base &lt;br /&gt;    &lt;/span&gt;Player.prototype.BitmapAnimation_initialize = Player.prototype.initialize;&lt;br /&gt; &lt;br /&gt;    &lt;span style="color: #006400"&gt;//unique to avoid overiding base class &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;quaterFrameSize;
   
    Player.prototype.initialize = &lt;span style="color: blue"&gt;function &lt;/span&gt;(imgPlayer, x_end) {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;localSpriteSheet = &lt;span style="color: blue"&gt;new &lt;/span&gt;SpriteSheet({
            images: [imgPlayer], &lt;span style="color: #006400"&gt;// image à utiliser &lt;br /&gt;            &lt;/span&gt;frames: { width:64, height:64, regX:32, regY: 32 },
            animations: {
                walk: [0, 9, &lt;span style="color: maroon"&gt;&amp;quot;walk&amp;quot;&lt;/span&gt;, 4],
                die: [10, 21, &lt;span style="color: blue"&gt;false&lt;/span&gt;, 4],
                jump: [22, 32],
                celebrate: [33, 43],
                idle: [44, 44]
            }
        });

        SpriteSheetUtils.addFlippedFrames(localSpriteSheet, &lt;span style="color: blue"&gt;true&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

        &lt;span style="color: blue"&gt;this&lt;/span&gt;.BitmapAnimation_initialize(localSpriteSheet);
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.x_end = x_end;

        quaterFrameSize = &lt;span style="color: blue"&gt;this&lt;/span&gt;.spriteSheet.getFrame(0).rect.width / 4;

        &lt;span style="color: #006400"&gt;// La 1ère séquence jouée est celle &amp;quot;au repos&amp;quot; &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;idle&amp;quot;&lt;/span&gt;);     
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.isInIdleMode = &lt;span style="color: blue"&gt;true&lt;/span&gt;;

        &lt;span style="color: #006400"&gt;// mise en place des ombres &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.shadow = &lt;span style="color: blue"&gt;new &lt;/span&gt;Shadow(&lt;span style="color: maroon"&gt;&amp;quot;#000&amp;quot;&lt;/span&gt;, 3, 2, 2);
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.name = &lt;span style="color: maroon"&gt;&amp;quot;Hero&amp;quot;&lt;/span&gt;;
        &lt;span style="color: #006400"&gt;// 1 = droite &amp;amp; -1 = gauche &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.direction = 1;

        &lt;span style="color: #006400"&gt;// vitesse &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.vX = 4;
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.vY = 0;
        &lt;span style="color: #006400"&gt;// on commence directement à la 1ère frame de la séquence walk_h (droite) &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentFrame = 66;

        &lt;span style="color: #006400"&gt;// Taille des bords du cercle pour les tests de collisions &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.bounds = 28;
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.hit = &lt;span style="color: blue"&gt;this&lt;/span&gt;.bounds;
    }

    Player.prototype.tick = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.alive &amp;amp;&amp;amp; !&lt;span style="color: blue"&gt;this&lt;/span&gt;.isInIdleMode) {
            &lt;span style="color: #006400"&gt;// Test sur les bords de l’écran &lt;br /&gt;            // Le joueur est bloqué sur chacun des bords mais on souhaite qu'il continue &lt;br /&gt;            // de courir quand même &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;((&lt;span style="color: blue"&gt;this&lt;/span&gt;.x + &lt;span style="color: blue"&gt;this&lt;/span&gt;.direction &amp;gt; quaterFrameSize) &amp;amp;&amp;amp; (&lt;span style="color: blue"&gt;this&lt;/span&gt;.x + (&lt;span style="color: blue"&gt;this&lt;/span&gt;.direction * 2) &amp;lt; &lt;span style="color: blue"&gt;this&lt;/span&gt;.x_end - quaterFrameSize + 1)) {
                &lt;span style="color: #006400"&gt;// On bouge le sprite en fonction de sa direction et sa vitesse &lt;br /&gt;                &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.x += &lt;span style="color: blue"&gt;this&lt;/span&gt;.vX * &lt;span style="color: blue"&gt;this&lt;/span&gt;.direction;
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.y += &lt;span style="color: blue"&gt;this&lt;/span&gt;.vY * &lt;span style="color: blue"&gt;this&lt;/span&gt;.direction;
            }
        }
    }

    window.Player = Player;
} (window));&lt;/pre&gt;

&lt;p&gt;Le héro sera contrôlé à distance depuis la page principale.&lt;/p&gt;

&lt;h2&gt;Construction de l’objet Content Manager&lt;/h2&gt;

&lt;p&gt;En général, la première étape d’un jeu HTML5 est de tout simplement télécharger les ressources dont il a besoin avant de démarrer le jeu. Dans mon cas, vous trouverez un gestionnaire de téléchargements et de ressources très basique au sein du fichier &lt;strong&gt;&lt;em&gt;ContentManager.js&lt;/em&gt;&lt;/strong&gt; :&lt;/p&gt;

&lt;p&gt;En voici le code :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Utilisé pour télécharger toutes les ressources utiles &lt;br /&gt;// hébergées sur le serveur web &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;ContentManager() {
    &lt;span style="color: #006400"&gt;// fonction qui sera rappelée une fois que tous les éléments &lt;br /&gt;    // auront été téléchargés (fonction de callback) &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;ondownloadcompleted;&lt;br /&gt;
    &lt;span style="color: #006400"&gt;// Nombre d'éléments à télécharger &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;NUM_ELEMENTS_TO_DOWNLOAD = 15;

    &lt;span style="color: #006400"&gt;// Pour l'affectation de la méthode de callback &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.SetDownloadCompleted = &lt;span style="color: blue"&gt;function &lt;/span&gt;(callbackMethod) {
        ondownloadcompleted = callbackMethod;
    };

    &lt;span style="color: #006400"&gt;// Nous avons 4 types d’ennemies, 1 héro &amp;amp; 1 type de bloc &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterA = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image();
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterB = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image(); 
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterC = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image(); 
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterD = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image();
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgTile = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image();
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgPlayer = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image();

    &lt;span style="color: #006400"&gt;// le fond du jeu peut être créé à partir de 3 claques différents &lt;br /&gt;    // ces 3 calques existent en 3 versions &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgBackgroundLayers = &lt;span style="color: blue"&gt;new &lt;/span&gt;Array();&lt;br /&gt;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;numImagesLoaded = 0;

    &lt;span style="color: #006400"&gt;// méthode publique pour lancer le téléchargement &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.StartDownload = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
        SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgPlayer, &lt;span style="color: maroon"&gt;&amp;quot;img/Player.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);
        SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterA, &lt;span style="color: maroon"&gt;&amp;quot;img/MonsterA.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);
        SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterB, &lt;span style="color: maroon"&gt;&amp;quot;img/MonsterB.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);
        SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterC, &lt;span style="color: maroon"&gt;&amp;quot;img/MonsterC.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);
        SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgMonsterD, &lt;span style="color: maroon"&gt;&amp;quot;img/MonsterD.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);
        SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgTile, &lt;span style="color: maroon"&gt;&amp;quot;img/Tiles/BlockA0.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);

        &lt;span style="color: #006400"&gt;// téléchargement des 3 claques * 3 versions &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i = 0; i &amp;lt; 3; i++) {
            &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgBackgroundLayers[i] = &lt;span style="color: blue"&gt;new &lt;/span&gt;Array();
            &lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;j = 0; j &amp;lt; 3; j++) {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.imgBackgroundLayers[i][j] = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image();
                SetDownloadParameters(&lt;span style="color: blue"&gt;this&lt;/span&gt;.imgBackgroundLayers[i][j], &lt;span style="color: maroon"&gt;&amp;quot;img/Backgrounds/Layer&amp;quot; &lt;/span&gt;+ i &lt;br /&gt;                                      + &lt;span style="color: maroon"&gt;&amp;quot;_&amp;quot; &lt;/span&gt;+ j + &lt;span style="color: maroon"&gt;&amp;quot;.png&amp;quot;&lt;/span&gt;, handleImageLoad, handleImageError);
            }
        }
    }

    &lt;span style="color: blue"&gt;function &lt;/span&gt;SetDownloadParameters(imgElement, url, loadedHandler, errorHandler) {
        imgElement.src = url;
        imgElement.onload = loadedHandler;
        imgElement.onerror = errorHandler;
    }

    &lt;span style="color: #006400"&gt;// notre gestionnaire d'évènement en cas de succès &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;handleImageLoad(e) {
        numImagesLoaded++

        &lt;span style="color: #006400"&gt;// Si tous les éléments ont été téléchargés avec succès &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(numImagesLoaded == NUM_ELEMENTS_TO_DOWNLOAD) {
            numImagesLoaded = 0;
            &lt;span style="color: #006400"&gt;// On rappelle la méthode de callback mise en place par SetDownloadCompleted &lt;br /&gt;            &lt;/span&gt;ondownloadcompleted();
        }
    }

    &lt;span style="color: #006400"&gt;// appelée si une erreur survient pendant le téléchargement (une 404 par exemple) &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;handleImageError(e) {
        console.log(&lt;span style="color: maroon"&gt;&amp;quot;Error Loading Image : &amp;quot; &lt;/span&gt;+ e.target.src);
    }
}&lt;/pre&gt;

&lt;p&gt;Je sais. Il manque pas mal de choses pour en faire un vrai bon gestionnaire de contenu : une barre de progression sur l’état des téléchargements, un meilleur gestionnaire d’erreurs, l’utilisation éventuelle du localStorage, un code peut-être plus générique, etc. Mais bon, j’ai essayé d’en faire un le plus simple et facile à comprendre. &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0458.wlEmoticon_2D00_winkingsmile_5F00_0495477E.png" /&gt;&lt;/p&gt;

&lt;h2&gt;Rassemblons toutes les pièces dans la page principale&lt;/h2&gt;

&lt;p&gt;Maintenant que nous avons les blocs de base de notre jeu, on peut commencer à s’amuser à les assembler pour construire un jeu de plateforme extrêmement simple. Pour cela, je vous propose de revoir chacune des parties de la page principale hébergeant notre petit jeu.&lt;/p&gt;

&lt;p&gt;Dans la méthode &lt;em&gt;init()&lt;/em&gt;, nous instancions l’objet &lt;a href="http://easeljs.com/docs/Stage.html"&gt;Stage&lt;/a&gt; d’EaselJS puis nous utilisons l’objet &lt;em&gt;ContentManager&lt;/em&gt; vu juste précédemment pour télécharger l’ensemble de nos fichier PNG:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;init() {
    &lt;span style="color: #006400"&gt;// on récupère l’instance du canvas puis on charge les images &lt;br /&gt;    &lt;/span&gt;canvas = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;testCanvas&amp;quot;&lt;/span&gt;);

    &lt;span style="color: #006400"&gt;// création de l’objet Stage que l’on fait pointer vers notre canvas &lt;br /&gt;    &lt;/span&gt;stage = &lt;span style="color: blue"&gt;new &lt;/span&gt;Stage(canvas);&lt;br /&gt;
    &lt;span style="color: #006400"&gt;// on récupère la largeur et la hauteur du canvas pour de futurs calculs savants &lt;br /&gt;    &lt;/span&gt;screen_width = canvas.width;
    screen_height = canvas.height;

    contentManager = &lt;span style="color: blue"&gt;new &lt;/span&gt;ContentManager();
    contentManager.SetDownloadCompleted(startGame);
    contentManager.StartDownload();
}&lt;/pre&gt;

&lt;p&gt;Une fois le téléchargement fini, la fonction &lt;em&gt;startGame()&lt;/em&gt; est appelée. La 1ère chose qu’elle fait est d’appeler la fonction &lt;em&gt;CreateAndAddRandomBackground()&lt;/em&gt;. Cette fonction créée simplement un arrière-plan aléatoire en utilisant les possibilités offertes par les 3 claques. Puis, notre héro est créé et sa position verticale Y est déterminée de manière aléatoire. Juste en dessous du héro, on construit une plateforme très simple sur laquelle notre héro pourra faire son petit jogging. Pour finir, on construit les 4 objets de type &lt;em&gt;Monster()&lt;/em&gt; à l’intérieur du tableau &lt;em&gt;Monsters&lt;/em&gt; et on ajoute l’ensemble au jeu/au stage : &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;startGame() {
    &lt;span style="color: #006400"&gt;// Nombre aléatoire pour positionner verticalement notre &lt;br /&gt;    // Héro &amp;amp; ses méchants ennemies sur 8 paliers possibles &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;randomY;
    
    CreateAndAddRandomBackground();

    &lt;span style="color: #006400"&gt;// Notre héro peut être déplacé avec les flèches (gauche, droite) &lt;br /&gt;    &lt;/span&gt;document.onkeydown = handleKeyDown;
    document.onkeyup = handleKeyUp;

    &lt;span style="color: #006400"&gt;// On créé le héro &lt;br /&gt;    &lt;/span&gt;randomY = 32 + (Math.floor(Math.random() * 7) * 64);
    Hero = &lt;span style="color: blue"&gt;new &lt;/span&gt;Player(contentManager.imgPlayer, screen_width);
    Hero.x = 400;
    Hero.y = randomY;

    &lt;span style="color: #006400"&gt;// Bloc sur lequel notre héro et éventuellement quelques ennemies pourront marcher &lt;br /&gt;    &lt;/span&gt;bmpSeqTile = &lt;span style="color: blue"&gt;new &lt;/span&gt;Bitmap(contentManager.imgTile);
    bmpSeqTile.regX = bmpSeqTile.frameWidth / 2 | 0;
    bmpSeqTile.regY = bmpSeqTile.frameHeight / 2 | 0;

    &lt;span style="color: #006400"&gt;// On prends le même motif que l'on duplique sur toute la largeur de l'écran &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i = 0; i &amp;lt; 20; i++) {
        &lt;span style="color: #006400"&gt;// On clone le motif original &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;bmpSeqTileCloned = bmpSeqTile.clone();

        &lt;span style="color: #006400"&gt;// On positionne ses propriétés d’affichage &lt;br /&gt;        &lt;/span&gt;bmpSeqTileCloned.x = 0 + (i * 40);
        bmpSeqTileCloned.y = randomY + 32;

        &lt;span style="color: #006400"&gt;// puis on l'ajoute dans les objets à afficher &lt;br /&gt;        &lt;/span&gt;stage.addChild(bmpSeqTileCloned);
    }

    &lt;span style="color: #006400"&gt;// Notre collection personnelle de monstres &lt;br /&gt;    &lt;/span&gt;Monsters = &lt;span style="color: blue"&gt;new &lt;/span&gt;Array();

    &lt;span style="color: #006400"&gt;// Création du 1er type de monstres &lt;br /&gt;    &lt;/span&gt;randomY = 32 + (Math.floor(Math.random() * 7) * 64);
    Monsters[0] = &lt;span style="color: blue"&gt;new &lt;/span&gt;Monster(&lt;span style="color: maroon"&gt;&amp;quot;MonsterA&amp;quot;&lt;/span&gt;, contentManager.imgMonsterA, screen_width);
    Monsters[0].x = 20;
    Monsters[0].y = randomY;

    &lt;span style="color: #006400"&gt;// Création du 2nd type de monstres &lt;br /&gt;    &lt;/span&gt;randomY = 32 + (Math.floor(Math.random() * 7) * 64);
    Monsters[1] = &lt;span style="color: blue"&gt;new &lt;/span&gt;Monster(&lt;span style="color: maroon"&gt;&amp;quot;MonsterB&amp;quot;&lt;/span&gt;, contentManager.imgMonsterB, screen_width);
    Monsters[1].x = 750;
    Monsters[1].y = randomY;

    &lt;span style="color: #006400"&gt;// Création du 3eme type de monstres &lt;br /&gt;    &lt;/span&gt;randomY = 32 + (Math.floor(Math.random() * 7) * 64);
    Monsters[2] = &lt;span style="color: blue"&gt;new &lt;/span&gt;Monster(&lt;span style="color: maroon"&gt;&amp;quot;MonsterC&amp;quot;&lt;/span&gt;, contentManager.imgMonsterC, screen_width);
    Monsters[2].x = 100;
    Monsters[2].y = randomY;

    &lt;span style="color: #006400"&gt;// Alors d'après vous, on fait quoi là ? :) &lt;br /&gt;    &lt;/span&gt;randomY = 32 + (Math.floor(Math.random() * 7) * 64);
    Monsters[3] = &lt;span style="color: blue"&gt;new &lt;/span&gt;Monster(&lt;span style="color: maroon"&gt;&amp;quot;MonsterD&amp;quot;&lt;/span&gt;, contentManager.imgMonsterD, screen_width);
    Monsters[3].x = 650;
    Monsters[3].y = randomY;

    &lt;span style="color: #006400"&gt;// On ajoute tous les monstres à l'écran &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i=0; i&amp;lt;Monsters.length;i++){
        stage.addChild(Monsters[i]);
    }
    &lt;span style="color: #006400"&gt;// Puis on ajoute la compagnie &lt;br /&gt;    &lt;/span&gt;stage.addChild(Hero);

    Ticker.addListener(window);
    &lt;span style="color: #006400"&gt;// On vise le meilleur taux possible (60 FPS) &lt;br /&gt;    // Et on utiliser requestAnimationFrame si disponible &lt;br /&gt;    &lt;/span&gt;Ticker.useRAF = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
    Ticker.setFPS(60);
}&lt;/pre&gt;

&lt;p&gt;A la fin de la page, vous trouverez 2 gestionnaires de clavier évident qui s’occupe de jouer les animations walk ou walk_h de notre héro en fonction des touches sur lesquelles vous presserez. Pour finir, la logique principale de notre jeu n’est finalement contenue que dans les quelques lignes de code présentes au sein de la méthode &lt;em&gt;tick()&lt;/em&gt; :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;tick() {
    &lt;span style="color: #006400"&gt;// on parcourt notre collection de monstres &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(monster &lt;span style="color: blue"&gt;in &lt;/span&gt;Monsters) {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;m = Monsters[monster];
        &lt;span style="color: #006400"&gt;// On appelle explicitement la méthode tick &lt;br /&gt;        // de chacun des monstres pour appeler leur logique de mise à jour &lt;br /&gt;        &lt;/span&gt;m.tick();

        &lt;span style="color: #006400"&gt;// Si notre héro est toujours vivant mais s'il est trop proche &lt;br /&gt;        // de l'un des monstres... &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(Hero.alive &amp;amp;&amp;amp; m.hitRadius(Hero.x, Hero.y, Hero.hit)) {
            &lt;span style="color: #006400"&gt;//...il doit mourir malheureusement! (la morale des jeux est ignoble) &lt;br /&gt;            &lt;/span&gt;Hero.alive = &lt;span style="color: blue"&gt;false&lt;/span&gt;;

            &lt;span style="color: #006400"&gt;// On joue alors l'animation de mort en fonction de &lt;br /&gt;            // la direction dans laquelle le héro courait &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(Hero.direction == 1) {
                Hero.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;die_h&amp;quot;&lt;/span&gt;);
            }
            &lt;span style="color: blue"&gt;else &lt;/span&gt;{
                Hero.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;die&amp;quot;&lt;/span&gt;);
            }

            &lt;span style="color: blue"&gt;continue&lt;/span&gt;;
        }
    }

    &lt;span style="color: #006400"&gt;// Mise à jour du héro &lt;br /&gt;    &lt;/span&gt;Hero.tick();

    &lt;span style="color: #006400"&gt;// Et on met le tout à jour &lt;br /&gt;    &lt;/span&gt;stage.update();
}&lt;/pre&gt;

&lt;p&gt;Ainsi, on vérifie à chaque tick (donc potentiellement toutes les 17 ms) si l’un des monstres ne serait pas en train de toucher notre héro à partir des paramètres de collisions que nous avons vu plus tôt. Si l’un des monstres est trop proche, notre malheureux héro doit alors mourir.&lt;/p&gt;

&lt;h2&gt;Jouez avec l’exemple complet !&lt;/h2&gt;

&lt;p&gt;Si vous avez tout lu jusque ici, je pense que vous avez amplement mérité de pouvoir jouer avec l’exemple qui est juste en dessous. A chaque fois que vous presserez le bouton “Start”, un nouvel arrière-plan sera généré et chacun des personnages (ennemies comme héro) seront placés à des positions différentes de manière aléatoire. Vous pouvez également faire bouger le héro avec les flèches gauche et droite de votre clavier.&lt;/p&gt;

&lt;p&gt;Au fait, ne vous inquiétez pas. Comme vous ne pouvez pas sauter, il y a actuellement aucun moyen de gagner dans ce jeu. C’est donc un jeu 100% looser (le premier du genre ? &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0458.wlEmoticon_2D00_winkingsmile_5F00_0495477E.png" /&gt;). Ce jeu est donc vivement déconseillé aux mauvais perdants.&lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-top: #ffffff 0px solid; border-right: #ffffff 0px solid; border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid" height="525" src="http://david.blob.core.windows.net/easeljstutorial2/easelJSCoreObjectsAndCollision.html" width="830"&gt;&lt;/iframe&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;span style="text-decoration: underline"&gt;Note :&lt;/span&gt;&lt;/strong&gt; comme je vous l’ai indiqué plus haut, il n’y a pas de barre de progression sur l’état du téléchargement. Vous devrez donc attendre un “certain temps” avant de pouvoir jouer après avoir appuyé sur le bouton “Start”. C’est ce que l’on appelle communément une EUP (expérience utilisateur pourrie). &lt;img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7651.wlEmoticon_2D00_smile_5F00_2F5A53FD.png" /&gt; Mais cela sera ensuite immédiat une fois le tout présent dans le cache du navigateur.&lt;/p&gt;

&lt;p&gt;Vous pouvez également y jouer via ce lien : &lt;a title="http://david.blob.core.windows.net/easeljstutorial2/easelJSCoreObjectsAndCollision.html" href="http://david.blob.core.windows.net/easeljstutorial2/easelJSCoreObjectsAndCollision.html"&gt;easelJSCoreObjectsAndCollision&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pour finir le jeu, il nous reste à gérer la séquence de saut du héro en utilisant un moteur physique assez simple et des collisions un peu plus poussées, à charger la musique et les effets sonores et finalement à charger les niveaux. Mais la base est bien là si vous souhaitez écrire votre propre petit jeu. Vous avez désormais toutes les cartes en main ! &lt;img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7651.wlEmoticon_2D00_smile_5F00_2F5A53FD.png" /&gt;&lt;/p&gt;

&lt;p&gt;Mais si vous souhaitez analyser le jeu entier avec l’ensemble du code source disponible, rendez-vous dans le prochain article : &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-portage-complet-du-jeu-xna-vers-lt-canvas-gt-gr-226-ce-224-easeljs.aspx"&gt;HTML5 Platformer: portage complet du jeu XNA vers &amp;lt;canvas&amp;gt; grâce à EaselJS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;span style="text-decoration: underline"&gt;Note :&lt;/span&gt;&lt;/strong&gt; ce tutoriel a été écrit à l’origine pour &lt;strong&gt;EaselJS 0.3.2&lt;/strong&gt; en Juillet 2010 et a été mis à jour pour &lt;strong&gt;EaselJS 0.4&lt;/strong&gt;. Pour ceux d’entre vous qui aviez lu la version 0.3.2, voici les changements principaux de la v0.4 à connaitre ayant un impact sur cet article :&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;BitmapSequence n’est désormais plus disponible et a été remplacé par BitmapAnimation &lt;/li&gt;

  &lt;li&gt;Vous pouvez désormais simplement ralentir la boucle d’animation des sprites via la propriété &lt;em&gt;frequency&lt;/em&gt; du SpriteSheet &lt;/li&gt;

  &lt;li&gt;EaselJS 0.4 peut utiliser désormais requestAnimationFrame pour des animations potentiellement plus efficaces sur les navigateurs le supportant (comme IE10+, Firefox 4.0+ &amp;amp; Chrome via les préfixes appropriés) &lt;/li&gt;

  &lt;li&gt;Vous devez appeler explicitement la méthode tick() de chacun des objets dans un gestionnaire d’évènements global plutôt que de laisser un Ticker global appeler automatiquement chacun des implémentations du tick.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10198571" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Tutorial/">Tutorial</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/EaselJS/">EaselJS</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Game/">Game</category></item><item><title>HTML5 Gaming: animating sprites in Canvas with EaselJS</title><link>http://blogs.msdn.com/b/davrous/archive/2012/03/16/html5-gaming-animating-sprites-in-canvas-with-easeljs.aspx</link><pubDate>Fri, 16 Mar 2012 18:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10188613</guid><dc:creator>David Rousset</dc:creator><slash:comments>18</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10188613</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/03/16/html5-gaming-animating-sprites-in-canvas-with-easeljs.aspx#comments</comments><description>When you want to write casual games using the HTML5 Canvas element, you’ll need to find a way to handle your sprites. There are several libraries available to help you writing games such as ImpactJS , CraftyJS and so on. On my side, I’ve decided to use...(&lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/03/16/html5-gaming-animating-sprites-in-canvas-with-easeljs.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10188613" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/EaselJS/">EaselJS</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Game/">Game</category></item><item><title>Jeux HTML5: animation de sprites dans l’élément Canvas grâce à EaselJS</title><link>http://blogs.msdn.com/b/davrous/archive/2012/03/16/jeux-html5-animation-de-sprites-dans-l-233-l-233-ment-canvas-gr-226-ce-224-easeljs.aspx</link><pubDate>Fri, 16 Mar 2012 17:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10188857</guid><dc:creator>David Rousset</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10188857</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/03/16/jeux-html5-animation-de-sprites-dans-l-233-l-233-ment-canvas-gr-226-ce-224-easeljs.aspx#comments</comments><description>&lt;p&gt;Si vous souhaitez écrire un petit jeu dit “casual” en utilisant l’élément Canvas d’HTML5, vous devrez trouver un moyen de gérer vos sprites. Il existe plusieurs librairies susceptibles de vous aider pour écrire des jeux en “HTML5” comme &lt;a href="http://impactjs.com/"&gt;ImpactJS&lt;/a&gt; ou &lt;a href="http://craftyjs.com/"&gt;CraftyJS&lt;/a&gt; par exemple. De mon côté, j’ai décidé de me pencher sur la librairie &lt;a href="http://easeljs.com/"&gt;EaselJS&lt;/a&gt; qui a été utilisée pour écrire &lt;a href="http://www.pirateslovedaisies.com/"&gt;PiratesLoveDaisies&lt;/a&gt; : un jeu en HTML5 de “Tower Defense”. Cette super librairie fonctionne dans tous les navigateurs HTML5 modernes et pourra même vous aider à écrire des jeux HTML5 pour les nouvelles applications Windows 8 Metro. &lt;/p&gt;  &lt;p&gt;Par exemple, si vous avez installé la version &lt;a href="http://go.microsoft.com/fwlink/?LinkID=239723"&gt;Windows 8 Consumer Preview&lt;/a&gt;, vous pouvez ainsi installer et jouer au jeu Pirates Love Daisies depuis le Windows Store ici: &lt;a title="http://apps.microsoft.com/webpdp/fr-fr/app/pirates-love-daisies/c9424bb5-d7d8-483b-bd96-7ca2badd2b2a" href="http://apps.microsoft.com/webpdp/fr-fr/app/pirates-love-daisies/c9424bb5-d7d8-483b-bd96-7ca2badd2b2a"&gt;Pirates Loves Daisies pour Windows 8&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Nous allons donc voir dans cet article à travers 3 petits tutoriels &lt;strong&gt;comment utiliser vos sprites existants et comment les animer&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;Cette article est le 1er d’une série de 3 articles :&lt;/p&gt;  &lt;p&gt;- Jeux HTML5: animation de sprites dans l’élément Canvas grâce à EaselJS    &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/08/22/jeux-html5-construction-des-objets-principaux-amp-gestion-des-collisions-avec-easeljs.aspx"&gt;Jeux HTML5: construction des objets principaux &amp;amp; gestion des collisions avec EaselJS&lt;/a&gt;     &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-portage-complet-du-jeu-xna-vers-lt-canvas-gt-gr-226-ce-224-easeljs.aspx"&gt;HTML5 Platformer: portage complet du jeu XNA vers &amp;lt;canvas&amp;gt; grâce à EaselJS&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;Introduction&lt;/h2&gt;  &lt;p&gt;Sur le site officiel &lt;a href="http://easeljs.com/"&gt;EaselJS&lt;/a&gt;, vous pouvez parcourir quelques exemples intéressants à décortiquer et une &lt;a href="http://easeljs.com/docs/"&gt;documentation assez sommaire&lt;/a&gt;. Nous allons prendre l’exemple nommé &lt;a title="sprites" href="http://easeljs.com/examples/bitmapSequences.html"&gt;sprites&lt;/a&gt; comme base de travail. Nous allons également utiliser les ressources disponibles dans l’exemple &lt;a href="http://create.msdn.com/en-US/education/catalog/sample/platformer"&gt;XNA 4.0 Platformer&lt;/a&gt;. Pour ceux qui suivent régulièrement mon blog, vous savez peut-être que j’affectionne particulièrement ce petit jeu et que j’aime jouer avec son code pour apprendre. Voici quelques articles que j’ai déjà écrit à ce sujet :&lt;/p&gt;  &lt;p&gt;- &lt;a title="http://blogs.msdn.com/b/davrous/archive/2010/03/29/portage-du-platformer-starter-kit-xna-3-1-vers-xna-4-0-pour-windows-phone-7.aspx" href="http://blogs.msdn.com/b/davrous/archive/2010/03/29/portage-du-platformer-starter-kit-xna-3-1-vers-xna-4-0-pour-windows-phone-7.aspx"&gt;Portage du Platformer Starter Kit XNA 3.1 vers XNA 4.0 pour Windows Phone 7&lt;/a&gt;     &lt;br /&gt;- &lt;a title="http://blogs.msdn.com/b/davrous/archive/2010/07/22/silverlight-4-xna-platformer-level-editor-pour-windows-phone-7-introduction-1-4.aspx" href="http://blogs.msdn.com/b/davrous/archive/2010/07/22/silverlight-4-xna-platformer-level-editor-pour-windows-phone-7-introduction-1-4.aspx"&gt;Silverlight 4 XNA Platformer Level Editor pour Windows Phone 7&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Entre temps, cet exemple de code a été mis à jour par nos équipes XNA et est désormais disponible pour les plateformes Xbox 360, PC &amp;amp; Windows Phone 7 ici: &lt;a title="http://create.msdn.com/en-US/education/catalog/sample/platformer" href="http://create.msdn.com/en-US/education/catalog/sample/platformer"&gt;App Hub – platformer&lt;/a&gt; . Vous pouvez le télécharger pour jouer avec le jeu et surtout pour extraire les sprites afin de les utiliser avec EaselJS. &lt;/p&gt;  &lt;p&gt;Dans cet article, nous allons ainsi utiliser ces 2 images PNG comme source de nos séquences de sprites:&lt;/p&gt;  &lt;p&gt;Notre ennemi/monstre en train de courir:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://david.blob.core.windows.net/easeljstutorials/img/MonsterARun.png" /&gt;&lt;/p&gt;  &lt;p&gt;qui contient &lt;strong&gt;10&lt;/strong&gt; images/sprites différents. &lt;/p&gt;  &lt;p&gt;Notre monstre au repos:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://david.blob.core.windows.net/easeljstutorials/img/MonsterAIdle.png" /&gt;&lt;/p&gt;  &lt;p&gt;qui contient une séquence de &lt;strong&gt;11&lt;/strong&gt; sprites différents.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/strong&gt; ces exemples ont été testés avec succès par votre serviteur dans IE9/IE10 PP5/Chrome 17/Firefox 11 &amp;amp; Opera 11.&lt;/p&gt;  &lt;h2&gt;Tutoriel 1 : construction des objets SpriteSheet et BitmapAnimation&lt;/h2&gt;  &lt;p&gt;Nous allons commencer par faire bouger notre monstre en train de courir sur toute la largeur du canvas. &lt;/p&gt;  &lt;p&gt;La 1ère étape consiste donc à charger la séquence complète contenue dans l’image PNG via ce code:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;imgMonsterARun = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image();

&lt;span style="color: blue"&gt;function &lt;/span&gt;init() {
    &lt;span style="color: #006400"&gt;//récupère le canvas et charge les images, attention à bien attendre la fin de tous les téléchargements
    &lt;/span&gt;canvas = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;testCanvas&amp;quot;&lt;/span&gt;);

    imgMonsterARun.onload = handleImageLoad;
    imgMonsterARun.onerror = handleImageError;
    imgMonsterARun.src = &lt;span style="color: maroon"&gt;&amp;quot;img/MonsterARun.png&amp;quot;&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Ce code sera donc appelé en premier pour initialiser le contenu de notre jeu. Une fois chargé, nous pouvons démarrer le jeu. EaselJS expose un objet de type &lt;a href="http://easeljs.com/docs/SpriteSheet.html"&gt;&lt;em&gt;SpriteSheet&lt;/em&gt;&lt;/a&gt;&lt;em&gt; &lt;/em&gt;pour gérer nos sprites. Ainsi en utilisant ce code :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;spriteSheet = &lt;span style="color: blue"&gt;new &lt;/span&gt;SpriteSheet({
    &lt;span style="color: #006400"&gt;// image à utiliser et à découper&lt;br /&gt;    &lt;/span&gt;images: [imgMonsterARun], 
    &lt;span style="color: #006400"&gt;// largeur, hauteur &amp;amp; point central de chacun des sprites&lt;br /&gt;    &lt;/span&gt;frames: {width: 64, height: 64, regX: 32, regY: 32}, 
    animations: {    
        walk: [0, 9, &lt;span style="color: maroon"&gt;&amp;quot;walk&amp;quot;&lt;/span&gt;]
    }
});&lt;/pre&gt;


&lt;p&gt;Nous indiquons que nous souhaitons créer une nouvelle séquence appelée “&lt;em&gt;walk&lt;/em&gt;”&lt;em&gt; &lt;/em&gt;qui sera fabriquée à partir de l’image appelée &lt;em&gt;imgMonsterARun&lt;/em&gt;. Cette image sera divisée en 10 sous-images ayant une taille de 64x64 pixels chacune. Il constitue notre objet de base pour charger nos sprites et en créer des séquences. A noter que vous pouvez créer plusieurs séquences à partir de même fichier PNG si vous le souhaitez. C’est le cas de l’exemple avec les rats sur le site officiel d’EaselJS. &lt;/p&gt;

&lt;p&gt;Maintenant, il nous faut utiliser l’objet &lt;em&gt;&lt;a href="http://easeljs.com/docs/BitmapAnimation.html"&gt;BitmapAnimation&lt;/a&gt;&lt;/em&gt;. Cet objet va nous aider à animer notre séquence et à la positionner à l’écran. Revoyons ensemble le code d’initialisation de cette &lt;em&gt;BitmapAnimation&lt;/em&gt; :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// crée une instance de BitmapSequence pour afficher et animer une instance de SpriteSheet:
&lt;/span&gt;bmpAnimation = &lt;span style="color: blue"&gt;new &lt;/span&gt;BitmapAnimation(spriteSheet);

&lt;span style="color: #006400"&gt;// On lance la séquence d’animation
&lt;/span&gt;bmpAnimation.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;walk&amp;quot;&lt;/span&gt;);

&lt;span style="color: #006400"&gt;// mise en place d’une ombre portée. Cela peut couter cher en FPS en fonction du navigateur
&lt;/span&gt;bmpAnimation.shadow = &lt;span style="color: blue"&gt;new &lt;/span&gt;Shadow(&lt;span style="color: maroon"&gt;&amp;quot;#454&amp;quot;&lt;/span&gt;, 0, 5, 4);

bmpAnimation.name = &lt;span style="color: maroon"&gt;&amp;quot;monster1&amp;quot;&lt;/span&gt;;
bmpAnimation.direction = 90;
bmpAnimation.vX = 4;
bmpAnimation.x = 16;
bmpAnimation.y = 32;

&lt;span style="color: #006400"&gt;// On peut choisir exactement à quelle frame démarrer l’animation
&lt;/span&gt;bmpAnimation.currentFrame = 0;
stage.addChild(bmpAnimation);&lt;/pre&gt;


&lt;p&gt;Le constructeur de l’objet &lt;em&gt;BitmapAnimation&lt;/em&gt; a simplement besoin d’un élément de type &lt;em&gt;SpriteSheet&lt;/em&gt; comme paramètre. Ensuite, on donne un nom à la séquence, positionne quelques paramètres comme la vitesse et la position initiale de notre 1ère étape d’animation. Pour finir, on ajoute cette séquence aux éléments affichables à l’écran avec l’objet &lt;a href="http://easeljs.com/docs/Stage.html"&gt;&lt;em&gt;Stage&lt;/em&gt;&lt;/a&gt;&lt;em&gt;&amp;#160;&lt;/em&gt;et sa méthode &lt;em&gt;addChild()&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;La dernière étape consiste maintenant à décider ce que l’on souhaite faire dans la boucle d’animation. Cette boucle est appelée toutes les xxx millisecondes et vous permet de mettre à jour la position de vos sprites. Pour cela, EaselJS expose un objet &lt;a href="http://easeljs.com/docs/Ticker.html"&gt;&lt;em&gt;Ticker&lt;/em&gt;&lt;/a&gt; qui nous fournit une horloge centralisée diffusée à un intervalle précis à tous les éléments souhaitant l’écouter. Si vous jetez un œil au code de Ticker.js, vous verrez que &lt;strong&gt;l’objet Ticker d’EaselJS 0.4 supporte désormais requestAnimationFrame()&lt;/strong&gt; :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;f = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame 
        || window.oRequestAnimationFrame || window.msRequestAnimationFrame;&lt;/pre&gt;

&lt;p&gt;Grâce à ce code, IE10, Firefox, Chrome et les futures versions d’Opéra sont déjà supportées. Par contre, EaselJS n’utilise pas par défaut requestAnimationFrame. Peut-être pour des raisons de compatibilité j’imagine.&lt;/p&gt;

&lt;p&gt;Vous pouvez alors demander à l’utiliser explicitement (afin d’avoir potentiellement des animations plus efficaces) en positionnant la propriété booléen &lt;em&gt;&lt;strong&gt;useRAF&lt;/strong&gt;&lt;/em&gt; à vrai. Et si votre navigateur ne le supporte pas, ne vous inquiétez pas, le code basculera alors automatiquement sur setTimeout() universellement reconnu. &lt;/p&gt;

&lt;p&gt;Bon, ensuite, tout ce qui vous reste à faire, c’est de vous abonner à l’évènement tick et d’implémenter une méthode &lt;em&gt;.tick()&lt;/em&gt; qui sera rappelée pour vous. Ce code s’abonne par exemple à cet évènement sur l’objet global window :&lt;/p&gt;

&lt;pre class="code"&gt;Ticker.addListener(window);
Ticker.useRAF = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
&lt;span style="color: #006400"&gt;// On vise le taux d’images/seconde optimal (60 FPS)
&lt;/span&gt;Ticker.setInterval(17);&lt;/pre&gt;


&lt;p&gt;Et voici le code qui sera rappelé toutes les 17 ms (lorsque cela sera possible) pour mettre à jour la position de notre monstre: &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;tick() {
    &lt;span style="color: #006400"&gt;// On teste si le personnage n’arrive pas en bout d’écran à droite avant qu’il ne disparaisse à jamais!
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(bmpAnimation.x &amp;gt;= screen_width - 16) {
        &lt;span style="color: #006400"&gt;// Nous avons atteint le côté droit de notre écran
        // Nous devons maintenant marcher vers la gauche pour retourner à la positon initiale
        &lt;/span&gt;bmpAnimation.direction = -90;
    }

    &lt;span style="color: blue"&gt;if &lt;/span&gt;(bmpAnimation.x &amp;lt; 16) {
        &lt;span style="color: #006400"&gt;// Nous avons atteint le côté gauche de notre écran
        // Nous devons maintenant marcher vers la droite
        &lt;/span&gt;bmpAnimation.direction = 90;
    }

    &lt;span style="color: #006400"&gt;// On bouge le sprite en fonction de la direction et de la vitesse demandée
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(bmpAnimation.direction == 90) {
        bmpAnimation.x += bmpAnimation.vX;
    }
    &lt;span style="color: blue"&gt;else &lt;/span&gt;{
        bmpAnimation.x -= bmpAnimation.vX;
    }

    &lt;span style="color: #006400"&gt;// mise à jour de la scène de jeu
    &lt;/span&gt;stage.update();
}&lt;/pre&gt;


&lt;p&gt;Vous pouvez tester le résultat final ici :&lt;/p&gt;
&lt;iframe style="border-top: #ffffff 0px solid; border-right: #ffffff 0px solid; border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid" height="120" src="http://david.blob.core.windows.net/easeljstutorials/easelJSSpritesTutorial01.html" width="700"&gt;&lt;/iframe&gt;

&lt;p&gt;Vous pouvez aussi naviguer vers cette URL : &lt;a title="http://david.blob.core.windows.net/easeljstutorials/easelJSSpritesTutorial01.html" href="http://david.blob.core.windows.net/easeljstutorials/easelJSSpritesTutorial01.html"&gt;easelJSSpritesTutorial01&lt;/a&gt; si vous souhaitez voir l’exemple de code complet.&lt;/p&gt;

&lt;p&gt;Eh, mais elle est bizarre cette animation non ? Effectivement, il y a 2 problèmes :&lt;/p&gt;

&lt;p&gt;1 – les étapes d’animation sont un peu étrange car le personnage semble boucler trop vite au sein de sa séquence de sprites. 
  &lt;br /&gt;2 – le personnage ne peut marcher normalement que de la droite vers la gauche. On a l’impression sinon qu’il se la raconte un peu en effectuant un Moonwalk dans l’autre sens. &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5415.wlEmoticon_2D00_winkingsmile_5F00_624D63DC.png" /&gt;&lt;/p&gt;

&lt;p&gt;Regardons comment le calmer un petit peu et fixer tout cela dans le 2ème tutoriel. .&lt;/p&gt;

&lt;h2&gt;Tutorial 2: contrôle de la vitesse d’animation et inversion des sprites&lt;/h2&gt;

&lt;p&gt;Pour corriger la vitesse de l’animation, la méthode la plus simple consiste à changer le paramètre &lt;em&gt;frequency&lt;/em&gt; de l’objet &lt;em&gt;animations &lt;/em&gt;contenu dans votre objet &lt;em&gt;SpriteSheet&lt;/em&gt;. Cela est plus ou moins précisé dans la documentation: &lt;a href="http://easeljs.com/docs/SpriteSheet.html"&gt;SpriteSheet&lt;/a&gt; . Voici le code pour construire ainsi le nouveau SpriteSheet :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;spriteSheet = &lt;span style="color: blue"&gt;new &lt;/span&gt;SpriteSheet({
&lt;span style="color: #006400"&gt;    &lt;/span&gt;images: [imgMonsterARun], 
&lt;span style="color: #006400"&gt;    &lt;/span&gt;frames: { width: 64, height: 64, regX: 32, regY: 32 }, 
    &lt;span style="color: #006400"&gt;// Pour ralentir les animations des sprites, on fixe la fréquence de rappel à 4 pour ralentir 4 fois
    &lt;/span&gt;animations: {
        walk: [0, 9, &lt;span style="color: maroon"&gt;&amp;quot;walk&amp;quot;&lt;/span&gt;, &lt;strong&gt;4&lt;/strong&gt;]
    }
});&lt;/pre&gt;


&lt;p&gt;Pour être cohérent, vous avez besoin également de changer la vélocité en changeant la propriété &lt;strong&gt;vX de 4 à 1&lt;/strong&gt; (logiquement également divisée par 4).&lt;/p&gt;

&lt;p&gt;Pour ajouter de nouvelles frames afin de permettre au personnage de marcher normalement de la gauche vers la droite, nous devons inverser horizontalement chacune des frames du sprite. Cela tombe bien, EaselJS expose un objet &lt;em&gt;&lt;a href="http://easeljs.com/docs/SpriteSheetUtils.html"&gt;SpriteSheetUtils&lt;/a&gt;&lt;/em&gt; qui contient une méthode &lt;em&gt;addFlippedFrames() &lt;/em&gt;comme vous pouvez le voir dans le &lt;a href="http://easeljs.com/docs/SpriteSheetUtils.js.html"&gt;code source&lt;/a&gt;. Voici le code permettant de l’utiliser :&lt;/p&gt;

&lt;pre class="code"&gt;SpriteSheetUtils.addFlippedFrames(spriteSheet, &lt;span style="color: blue"&gt;true&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;, &lt;span style="color: blue"&gt;false&lt;/span&gt;);&lt;/pre&gt;


&lt;p&gt;Nous créons ainsi une nouvelle séquence qui sera nommée automatiquement “&lt;em&gt;walk_h&lt;/em&gt;” basée sur la séquence “&lt;em&gt;walk&lt;/em&gt;” que nous avons inversée horizontalement. Pour finir, voici le code qui s’occupe de savoir quelle séquence jouer en fonction de la position actuelle du personnage :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;tick() {
    &lt;span style="color: #006400"&gt;// On teste si le personnage n’arrive pas en bout d’écran à droite avant qu’il ne disparaisse
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(bmpAnimation.x &amp;gt;= screen_width - 16) {
        &lt;span style="color: #006400"&gt;// Nous avons atteint le côté droit de notre écran
        // Nous devons maintenant marcher vers la gauche pour retourner à la positon initiale
        &lt;/span&gt;bmpAnimation.direction = -90;
        bmpAnimation.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;walk&amp;quot;&lt;/span&gt;)
    }

    &lt;span style="color: blue"&gt;if &lt;/span&gt;(bmpAnimation.x &amp;lt; 16) {
        &lt;span style="color: #006400"&gt;// Nous avons atteint le côté gauche de notre écran
        // Nous devons maintenant marcher vers la droite 
        &lt;/span&gt;bmpAnimation.direction = 90;
        bmpAnimation.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;walk_h&amp;quot;&lt;/span&gt;);
    }

    &lt;span style="color: #006400"&gt;// On bouge le sprite en fonction de la direction et de la vitesse demandée
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(bmpAnimation.direction == 90) {
        bmpAnimation.x += bmpAnimation.vX;
    }
    &lt;span style="color: blue"&gt;else &lt;/span&gt;{
        bmpAnimation.x -= bmpAnimation.vX;
    }

    &lt;span style="color: #006400"&gt;// mise à jour de la scène de jeu
    &lt;/span&gt;stage.update();
}&lt;/pre&gt;


&lt;p&gt;Vous pouvez tester le résultat final ici :&lt;/p&gt;
&lt;iframe style="border-top: #ffffff 0px solid; border-right: #ffffff 0px solid; border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid" height="120" src="http://david.blob.core.windows.net/easeljstutorials/easelJSSpritesTutorial02.html" width="700"&gt;&lt;/iframe&gt;

&lt;p&gt;Vous pouvez aussi naviguer vers cette URL : &lt;a title="http://david.blob.core.windows.net/easeljstutorials/easelJSSpritesTutorial02.html" href="http://david.blob.core.windows.net/easeljstutorials/easelJSSpritesTutorial02.html"&gt;easelJSSpritesTutorial02&lt;/a&gt; si vous souhaitez voir l’exemple de code complet.&lt;/p&gt;

&lt;h2&gt;Tutoriel 3 : chargement de plusieurs sprites et utilisation de plusieurs animations&lt;/h2&gt;

&lt;p&gt;Il est temps désormais de charger l’état “au repos” de notre monstre préféré. L’idée est donc de jouer l’animation où il court sur un aller/retour complet. Ensuite, fatigué, le monstre passera à l’état “au repos” à jamais.&lt;/p&gt;

&lt;p&gt;Nous allons donc devoir charger plusieurs images PNG depuis le serveur web. Il est d’ailleurs très important d’attendre que toutes les ressources soient totalement téléchargées afin de commencer les opérations de dessin. Voici une manière très simple de s’en assurer :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;numberOfImagesLoaded = 0;

&lt;span style="color: blue"&gt;var &lt;/span&gt;imgMonsterARun = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image();
&lt;span style="color: blue"&gt;var &lt;/span&gt;imgMonsterAIdle = &lt;span style="color: blue"&gt;new &lt;/span&gt;Image();

&lt;span style="color: blue"&gt;function &lt;/span&gt;init() {
    &lt;span style="color: #006400"&gt;//récupère le canvas et charge les images, attention à bien attendre la fin de tous les téléchargements 
    &lt;/span&gt;canvas = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;testCanvas&amp;quot;&lt;/span&gt;);

    imgMonsterARun.onload = handleImageLoad;
    imgMonsterARun.onerror = handleImageError;
    imgMonsterARun.src = &lt;span style="color: maroon"&gt;&amp;quot;img/MonsterARun.png&amp;quot;&lt;/span&gt;;

    imgMonsterAIdle.onload = handleImageLoad;
    imgMonsterAIdle.onerror = handleImageError;
    imgMonsterAIdle.src = &lt;span style="color: maroon"&gt;&amp;quot;img/MonsterAIdle.png&amp;quot;&lt;/span&gt;;
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;handleImageLoad(e) {
    numberOfImagesLoaded++;

    &lt;span style="color: #006400"&gt;// Nous ne démarrons pas le jeu tant que toutes les images ne sont pas téléchargées
    // Sinon vous risquez de commencer à dessiner sans la bonne ressource et de lever 
    // cet exception du DOM: INVALID_STATE_ERR (11) sur l’appel de la méthode drawImage
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(numberOfImagesLoaded == 2) {
        numberOfImagesLoaded = 0;
        startGame();
    }
}&lt;/pre&gt;

&lt;p&gt;Ce code est très basique. Par exemple, il ne gère pas les erreurs correctement en tentant de télécharger à nouveau l’image problématique en cas de 1er échec. Si vous fabriquez un jeu, vous aurez besoin d’écrire votre propre gestionnaire de téléchargements de contenus si la librairie JavaScript que vous utilisez de l’implémente pas encore.&lt;/p&gt;

&lt;p&gt;Pour ajouter la séquence “au repos” et positionner ses différents paramètres, il nous suffit d’utiliser le même type de code vu précédemment :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;spriteSheetIdle = &lt;span style="color: blue"&gt;new &lt;/span&gt;SpriteSheet({
    images: [imgMonsterAIdle],
    frames: { width: 64, height: 64, regX: 32, regY: 32 }, 
    animations: {
        idle: [0, 10, &lt;span style="color: maroon"&gt;&amp;quot;idle&amp;quot;&lt;/span&gt;, 4]
    }
});

bmpAnimationIdle = &lt;span style="color: blue"&gt;new &lt;/span&gt;BitmapAnimation(spriteSheetIdle);

bmpAnimationIdle.name = &lt;span style="color: maroon"&gt;&amp;quot;monsteridle1&amp;quot;&lt;/span&gt;;
bmpAnimationIdle.x = 16;
bmpAnimationIdle.y = 32;&lt;/pre&gt;


&lt;p&gt;Ensuite, au sein de la méthode &lt;em&gt;tick()&lt;/em&gt;, nous devons stopper l’animation où le monstre court une fois que ce dernier atteint à nouveau le côté gauche de l’écran. Puis ensuite, il suffit de jouer l’animation “au repos” à la place. Voici le code qui fait exactement cela :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(bmpAnimation.x &amp;lt; 16) {
    &lt;span style="color: #006400"&gt;// Nous avons atteint le côté gauche de notre écran, il est temps de se reposer 
    &lt;/span&gt;bmpAnimation.direction = 90;
    bmpAnimation.gotoAndStop(&lt;span style="color: maroon"&gt;&amp;quot;walk&amp;quot;&lt;/span&gt;);
    stage.removeChild(bmpAnimation);
    bmpAnimationIdle.gotoAndPlay(&lt;span style="color: maroon"&gt;&amp;quot;idle&amp;quot;&lt;/span&gt;);
    stage.addChild(bmpAnimationIdle);
}&lt;/pre&gt;


&lt;p&gt;Vous pouvez tester le résultat final ici :&lt;/p&gt;
&lt;iframe style="border-top: #ffffff 0px solid; border-right: #ffffff 0px solid; border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid" height="120" src="http://david.blob.core.windows.net/easeljstutorials/easelJSSpritesTutorial03.html" width="700"&gt;&lt;/iframe&gt;

&lt;p&gt;Vous pouvez aussi naviguer vers cette URL : &lt;a title="http://david.blob.core.windows.net/easeljstutorials/easelJSSpritesTutorial03.html" href="http://david.blob.core.windows.net/easeljstutorials/easelJSSpritesTutorial03.html"&gt;easelJSSpritesTutorial03&lt;/a&gt; si vous souhaitez voir l’exemple de code complet.&lt;/p&gt;

&lt;p&gt;Voilà, c’est tout pour aujourd’hui ! Vous pouvez reprendre une activité normale. Mais si l’envie vous en prend, n’hésitez pas à jeter un œil à la suite ici : &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/08/22/jeux-html5-construction-des-objets-principaux-amp-gestion-des-collisions-avec-easeljs.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/08/22/jeux-html5-construction-des-objets-principaux-amp-gestion-des-collisions-avec-easeljs.aspx"&gt;Jeux HTML5: construction des objets principaux &amp;amp; gestion des collisions avec EaselJS&lt;/a&gt; . C’est une 2ème partie indispensable à comprendre avant de réussir à écrire un jeu de plateforme complet comme nous le verrons dans le 3ème et dernier article.&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/strong&gt; ce tutoriel a été écrit à l’origine pour &lt;strong&gt;EaselJS 0.3.2&lt;/strong&gt; en Juillet 2010 et a été mis à jour pour &lt;strong&gt;EaselJS 0.4&lt;/strong&gt;. Pour ceux d’entre vous qui aviez lu la version 0.3.2, voici les changements principaux de la v0.4 à connaitre ayant un impact sur cet article :&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;BitmapSequence n’est désormais plus disponible et a été remplacé par BitmapAnimation&lt;/li&gt;

  &lt;li&gt;Vous pouvez désormais simplement ralentir la boucle d’animation des sprites via la propriété &lt;em&gt;frequency&lt;/em&gt; du SpriteSheet&lt;/li&gt;

  &lt;li&gt;EaselJS 0.4 peut utiliser désormais requestAnimationFrame pour des animations potentiellement plus efficaces sur les navigateurs le supportant (comme IE10+, Firefox 4.0+ &amp;amp; Chrome via les préfixes appropriés)&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10188857" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/EaselJS/">EaselJS</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Game/">Game</category></item><item><title>Techdays 2012: vidéos des sessions HTML5... au format HTML5 h264 et WebM!</title><link>http://blogs.msdn.com/b/davrous/archive/2012/03/13/techdays-2012-vid-233-os-des-sessions-html5-au-format-html5-h264-et-webm.aspx</link><pubDate>Tue, 13 Mar 2012 13:44:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10281965</guid><dc:creator>David Rousset</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10281965</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/03/13/techdays-2012-vid-233-os-des-sessions-html5-au-format-html5-h264-et-webm.aspx#comments</comments><description>&lt;!-- Include the VideoJS Library --&gt;  &lt;p&gt;&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;Si vous le ne saviez pas encore, nous avons mis en ligne une grande partie des vidéos/webcasts des sessions des Techdays 2012 sur notre site officiel: &lt;a href="http://www.mstechdays.fr"&gt;http://www.mstechdays.fr&lt;/a&gt; . Vous pouvez ainsi y retrouver le parcours découverte HTML5. Mais le mieux pour regarder une session parlant de HTML5, c'est quand même d'avoir une expérience HTML5 non? Pour résoudre cela, je me suis amusé à ré-encoder toutes les vidéos au format WebM en plus de h264 pour encapsuler le tout dans le player &lt;a href="http://videojs.com"&gt;VideoJS&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Ce billet sera donc un complément de mon précédent où je partageais une partie des slides et démos : &lt;a title="http://blogs.msdn.com/b/davrous/archive/2012/02/20/slides-quelques-d-233-mos-et-vid-233-os-des-sessions-ie10-html5-css3-des-techdays-2012.aspx" href="http://blogs.msdn.com/b/davrous/archive/2012/02/20/slides-quelques-d-233-mos-et-vid-233-os-des-sessions-ie10-html5-css3-des-techdays-2012.aspx"&gt;Slides, quelques démos et vidéos des sessions IE10/HTML5/CSS3 des Techdays 2012&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Voici donc une partie des sessions HTML5 au format HTML5.&lt;/p&gt;  &lt;h2&gt;&lt;/h2&gt;  &lt;h2&gt;Nouveautés HTML5 et CSS3 dans Internet Explorer 10 &lt;/h2&gt;  &lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="NouveautesIE10" class="video-js" height="288" width="512" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/578eab86-f64d-4086-951f-df25d4535dc4.jpg"&gt;&lt;source src="http://content3.catalog.video.msn.com/e2/ds/578eab86-f64d-4086-951f-df25d4535dc4.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/578eab86-f64d-4086-951f-df25d4535dc4.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="512" type="application/x-shockwave-flash" height="288"&gt;  &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  &lt;param name="allowfullscreen" value="true" /&gt;  &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/578eab86-f64d-4086-951f-df25d4535dc4.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://content3.catalog.video.msn.com/e2/ds/578eab86-f64d-4086-951f-df25d4535dc4.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/578eab86-f64d-4086-951f-df25d4535dc4.jpg" width="512" height="288" /&gt;   &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;    &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://content3.catalog.video.msn.com/e2/ds/578eab86-f64d-4086-951f-df25d4535dc4.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/578eab86-f64d-4086-951f-df25d4535dc4.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;    &lt;p class="vjs-no-video"&gt;&lt;a href="http://www.microsoft.com/fr-fr/showcase/details.aspx?uuid=66264bca-234e-4cee-b643-faef3a93d18b"&gt;Visionnez la version Silverlight&lt;/a&gt; et n’oubliez pas une &lt;a href="http://david.blob.core.windows.net/techdays2012/ie10/index.html"&gt;version HTML5 interactive des slides&lt;/a&gt;.&lt;/p&gt; &lt;/div&gt;  &lt;h2&gt;Introduction à JavaScript&lt;/h2&gt;  &lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="IntroJS" class="video-js" height="288" width="512" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/b3c84135-ac73-4662-a001-d7223ea3907f.jpg"&gt;&lt;source src="http://content2.catalog.video.msn.com/e2/ds/b3c84135-ac73-4662-a001-d7223ea3907f.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/b3c84135-ac73-4662-a001-d7223ea3907f.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="512" type="application/x-shockwave-flash" height="288"&gt;  &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  &lt;param name="allowfullscreen" value="true" /&gt;  &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/b3c84135-ac73-4662-a001-d7223ea3907f.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://content2.catalog.video.msn.com/e2/ds/b3c84135-ac73-4662-a001-d7223ea3907f.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/b3c84135-ac73-4662-a001-d7223ea3907f.jpg" width="512" height="288" /&gt;   &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;    &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://content2.catalog.video.msn.com/e2/ds/b3c84135-ac73-4662-a001-d7223ea3907f.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/b3c84135-ac73-4662-a001-d7223ea3907f.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;    &lt;p class="vjs-no-video"&gt;&lt;a href="http://www.microsoft.com/fr-fr/showcase/details.aspx?uuid=8d480df2-6ce2-4d2a-b7d2-e57c6fe17df4"&gt;Visionnez la version Silverlight&lt;/a&gt;&lt;/p&gt; &lt;/div&gt;  &lt;h2&gt;Patterns et bonnes pratiques autour de JavaScript&lt;/h2&gt;  &lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="PatternsJS" class="video-js" height="288" width="512" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/c572a50e-5eca-47b9-ab24-58228142236a.jpg"&gt;&lt;source src="http://content4.catalog.video.msn.com/e2/ds/c572a50e-5eca-47b9-ab24-58228142236a.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/c572a50e-5eca-47b9-ab24-58228142236a.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="512" type="application/x-shockwave-flash" height="288"&gt;  &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  &lt;param name="allowfullscreen" value="true" /&gt;  &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/c572a50e-5eca-47b9-ab24-58228142236a.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://content4.catalog.video.msn.com/e2/ds/c572a50e-5eca-47b9-ab24-58228142236a.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/c572a50e-5eca-47b9-ab24-58228142236a.jpg" width="512" height="288" /&gt;   &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;    &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://content4.catalog.video.msn.com/e2/ds/c572a50e-5eca-47b9-ab24-58228142236a.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/c572a50e-5eca-47b9-ab24-58228142236a.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;    &lt;p class="vjs-no-video"&gt;&lt;a href="http://www.microsoft.com/fr-fr/showcase/details.aspx?uuid=f9416d60-cbfa-45b9-8f5e-2c9af1fefaae"&gt;Visionnez la version Silverlight&lt;/a&gt;&lt;/p&gt; &lt;/div&gt;  &lt;h2&gt;Trois avancées majeures en CSS3 : Media Queries, Grid Layout et Animations&lt;/h2&gt;  &lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="3avanceesMajeures" class="video-js" height="288" width="512" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/be551c82-6974-403d-90f1-32384efcb2a5.jpg"&gt;&lt;source src="http://content2.catalog.video.msn.com/e2/ds/be551c82-6974-403d-90f1-32384efcb2a5.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/be551c82-6974-403d-90f1-32384efcb2a5.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="512" type="application/x-shockwave-flash" height="288"&gt;  &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  &lt;param name="allowfullscreen" value="true" /&gt;  &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/be551c82-6974-403d-90f1-32384efcb2a5.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://content2.catalog.video.msn.com/e2/ds/be551c82-6974-403d-90f1-32384efcb2a5.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/be551c82-6974-403d-90f1-32384efcb2a5.jpg" width="512" height="288" /&gt;   &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;    &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://content2.catalog.video.msn.com/e2/ds/be551c82-6974-403d-90f1-32384efcb2a5.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/be551c82-6974-403d-90f1-32384efcb2a5.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;    &lt;p class="vjs-no-video"&gt;&lt;a href="http://www.microsoft.com/fr-fr/showcase/details.aspx?uuid=184b0ae7-beba-4981-8dad-f7ff44df7a20"&gt;Visionnez la version Silverlight&lt;/a&gt;&lt;/p&gt; &lt;/div&gt;  &lt;h2&gt;Développement de jeux 2D avec HTML5&lt;/h2&gt;  &lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="jeux2D" class="video-js" height="288" width="512" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/720fc546-fdf2-4846-8b12-ab0791440e3f.jpg"&gt;&lt;source src="http://content5.catalog.video.msn.com/e2/ds/720fc546-fdf2-4846-8b12-ab0791440e3f.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/720fc546-fdf2-4846-8b12-ab0791440e3f.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="512" type="application/x-shockwave-flash" height="288"&gt;  &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  &lt;param name="allowfullscreen" value="true" /&gt;  &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/720fc546-fdf2-4846-8b12-ab0791440e3f.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://content5.catalog.video.msn.com/e2/ds/720fc546-fdf2-4846-8b12-ab0791440e3f.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/720fc546-fdf2-4846-8b12-ab0791440e3f.jpg" width="512" height="288" /&gt;   &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;    &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://content5.catalog.video.msn.com/e2/ds/720fc546-fdf2-4846-8b12-ab0791440e3f.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/720fc546-fdf2-4846-8b12-ab0791440e3f.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;    &lt;p class="vjs-no-video"&gt;&lt;a href="http://www.microsoft.com/fr-fr/showcase/details.aspx?uuid=3f54d0e0-9242-4445-b62f-f294279aadf2"&gt;Visionnez la version Silverlight&lt;/a&gt;&lt;/p&gt; &lt;/div&gt;  &lt;h2&gt;Création d'une application HTML5 utilisant Canvas, SVG et les animations CSS3&lt;/h2&gt;  &lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="CSS3Animations" class="video-js" height="288" width="512" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/9b3609f2-7b54-4698-a2f3-baf75a3092ab.jpg"&gt;&lt;source src="http://content4.catalog.video.msn.com/e2/ds/9b3609f2-7b54-4698-a2f3-baf75a3092ab.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/9b3609f2-7b54-4698-a2f3-baf75a3092ab.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="512" type="application/x-shockwave-flash" height="288"&gt;  &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  &lt;param name="allowfullscreen" value="true" /&gt;  &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/9b3609f2-7b54-4698-a2f3-baf75a3092ab.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://content4.catalog.video.msn.com/e2/ds/9b3609f2-7b54-4698-a2f3-baf75a3092ab.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/9b3609f2-7b54-4698-a2f3-baf75a3092ab.jpg" width="512" height="288" /&gt;   &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;    &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://content4.catalog.video.msn.com/e2/ds/9b3609f2-7b54-4698-a2f3-baf75a3092ab.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/9b3609f2-7b54-4698-a2f3-baf75a3092ab.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;    &lt;p class="vjs-no-video"&gt;&lt;a href="http://www.microsoft.com/fr-fr/showcase/details.aspx?uuid=3d5941d2-4d99-4aaf-9486-82ff8a0a0117"&gt;Visionnez la version Silverlight&lt;/a&gt;&lt;/p&gt; &lt;/div&gt;  &lt;h2&gt;Accessibilité du Web 2.0 : HTML5 et WAI-ARIA&lt;/h2&gt;  &lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="AccessibiliteHTML5" class="video-js" height="288" width="512" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/3e3801dc-23c0-4b27-a9a8-311b1d08ef95.jpg"&gt;&lt;source src="http://content3.catalog.video.msn.com/e2/ds/3e3801dc-23c0-4b27-a9a8-311b1d08ef95.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/3e3801dc-23c0-4b27-a9a8-311b1d08ef95.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="512" type="application/x-shockwave-flash" height="288"&gt;  &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  &lt;param name="allowfullscreen" value="true" /&gt;  &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/3e3801dc-23c0-4b27-a9a8-311b1d08ef95.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://content3.catalog.video.msn.com/e2/ds/3e3801dc-23c0-4b27-a9a8-311b1d08ef95.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/3e3801dc-23c0-4b27-a9a8-311b1d08ef95.jpg" width="512" height="288" /&gt;   &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;    &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://content3.catalog.video.msn.com/e2/ds/3e3801dc-23c0-4b27-a9a8-311b1d08ef95.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/3e3801dc-23c0-4b27-a9a8-311b1d08ef95.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;    &lt;p class="vjs-no-video"&gt;&lt;a href="http://www.microsoft.com/fr-fr/showcase/details.aspx?uuid=a1217df4-ee78-41eb-84ca-8e0bb331e42b"&gt;Visionnez la version Silverlight&lt;/a&gt;&lt;/p&gt; &lt;/div&gt;  &lt;h2&gt;HTML5 sur mobile: le bon, la brute et un gros paquet de truands&lt;/h2&gt;  &lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="BonBruteTruand" class="video-js" height="288" width="512" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/videos/6b6492b3-1870-4414-bc30-57b621cb83c4.jpg"&gt;&lt;source src="http://content2.catalog.video.msn.com/e2/ds/6b6492b3-1870-4414-bc30-57b621cb83c4.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/videos/6b6492b3-1870-4414-bc30-57b621cb83c4.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="512" type="application/x-shockwave-flash" height="288"&gt;  &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;  &lt;param name="allowfullscreen" value="true" /&gt;  &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/6b6492b3-1870-4414-bc30-57b621cb83c4.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://content2.catalog.video.msn.com/e2/ds/6b6492b3-1870-4414-bc30-57b621cb83c4.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;  &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;   &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/6b6492b3-1870-4414-bc30-57b621cb83c4.jpg" width="512" height="288" /&gt;   &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;    &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://content2.catalog.video.msn.com/e2/ds/6b6492b3-1870-4414-bc30-57b621cb83c4.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/6b6492b3-1870-4414-bc30-57b621cb83c4.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;    &lt;p class="vjs-no-video"&gt;&lt;a href="http://www.microsoft.com/fr-fr/showcase/details.aspx?uuid=3256d50a-6a28-4759-8a89-3101b88cec67"&gt;Visionnez la version Silverlight&lt;/a&gt;&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;Bon visionnage !&lt;/p&gt;  &lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10281965" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/CSS3/">CSS3</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/SVG/">SVG</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/IE10/">IE10</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/TechDays2012/">TechDays2012</category></item><item><title>Slides, quelques démos et vidéos des sessions IE10/HTML5/CSS3 des Techdays 2012</title><link>http://blogs.msdn.com/b/davrous/archive/2012/02/20/slides-quelques-d-233-mos-et-vid-233-os-des-sessions-ie10-html5-css3-des-techdays-2012.aspx</link><pubDate>Mon, 20 Feb 2012 18:59:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10269917</guid><dc:creator>David Rousset</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10269917</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/02/20/slides-quelques-d-233-mos-et-vid-233-os-des-sessions-ie10-html5-css3-des-techdays-2012.aspx#comments</comments><description>&lt;h2&gt;La version HTML5 de la session IE10&lt;/h2&gt;  &lt;p&gt;&lt;a href="http://david.blob.core.windows.net/techdays2012/ie10/index.html"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: right; padding-top: 0px; padding-left: 0px; margin: 0px 0px 0px 5px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" align="right" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7317.image_5F00_thumb_5F00_06B58660.png" width="454" height="208" /&gt;&lt;/a&gt;Plusieurs d’entre vous m’ont demandé s’ils pouvaient avoir accès à l’application HTML5 que j’ai utilisée pendant ma session générale sur les &lt;strong&gt;nouveautés d’HTML5 et CSS3 dans Internet Explorer 10&lt;/strong&gt; des Techdays 2012. Vous pouvez la jouer depuis cette adresse : &lt;a title="http://david.blob.core.windows.net/techdays2012/ie10/index.html" href="http://david.blob.core.windows.net/techdays2012/ie10/index.html"&gt;version interactive des slides en HTML5&lt;/a&gt; . &lt;/p&gt;  &lt;p&gt;L’ensemble complet des démos ne fonctionne que dans la &lt;a href="http://ie.microsoft.com/testdrive"&gt;version dite “PP3”&lt;/a&gt; (pour Platform Preview 3) d’IE10. Mais si vous avez un autre navigateur récent comme un des derniers Chrome ou Firefox, la quasi-totalité des démos devraient également fonctionner (comme CSS3 3D Transform, Transition, Animation, etc.). &lt;/p&gt;  &lt;p&gt;En fait, il n’y a en gros que CSS3 Grid (-ms-grid) ne fonctionnant que sous IE10 pour l’instant. &lt;/p&gt;  &lt;h2&gt;Les présentations à voir ou à télécharger&lt;/h2&gt;  &lt;p&gt;Vous pouvez voir les slides de la session “nouveautés HTML5 et CSS3 dans IE10” ici: &lt;/p&gt;  &lt;div id="__ss_11678245" style="margin-bottom: 5px; width: 425px"&gt;&lt;strong style="margin: 5px 0px 4px; display: block"&gt;&lt;a title="Nouveautés html5 et css3 dans internet explorer 10" href="http://www.slideshare.net/davrous/nouveauts-html5-et-css3-dans-internet-explorer-10"&gt;Nouveautés html5 et css3 dans internet explorer 10&lt;/a&gt;&lt;/strong&gt;&lt;object id="__sse11678245" width="425" height="355"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=nouveautshtml5etcss3dansinternetexplorer10-120220130843-phpapp01&amp;amp;stripped_title=nouveauts-html5-et-css3-dans-internet-explorer-10" /&gt;&lt;param name="allowFullScreen" value="true" /&gt;&lt;param name="allowScriptAccess" value="always" /&gt;&lt;param name="wmode" value="transparent" /&gt;&lt;embed name="__sse11678245" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=nouveautshtml5etcss3dansinternetexplorer10-120220130843-phpapp01&amp;amp;stripped_title=nouveauts-html5-et-css3-dans-internet-explorer-10&amp;amp;userName=davrous" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;  &lt;p&gt;Mais avec mon ami &lt;a href="http://blogs.msdn.com/eternalcoding"&gt;David Catuhe&lt;/a&gt;, nous avons également animé 2 autres sessions autour d’HTML5 et IE10 ayant pour support l’application Snapyx dont voici les slides :&lt;/p&gt;  &lt;div id="__ss_11678255" style="margin-bottom: 5px; width: 425px"&gt;&lt;strong style="margin: 5px 0px 4px; display: block"&gt;&lt;a title="Création d’une application gérant l’offline et le stockage" href="http://www.slideshare.net/davrous/cration-dune-application-grant-loffline-et-le-stockage"&gt;Création d’une application gérant l’offline et le stockage&lt;/a&gt;&lt;/strong&gt;&lt;object id="__sse11678255" width="425" height="355"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=crationduneapplicationgrantlofflineetlestockage-120220130944-phpapp02&amp;amp;stripped_title=cration-dune-application-grant-loffline-et-le-stockage&amp;amp;userName=davrous" /&gt;&lt;param name="allowFullScreen" value="true" /&gt;&lt;param name="allowScriptAccess" value="always" /&gt;&lt;param name="wmode" value="transparent" /&gt;&lt;embed name="__sse11678255" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=crationduneapplicationgrantlofflineetlestockage-120220130944-phpapp02&amp;amp;stripped_title=cration-dune-application-grant-loffline-et-le-stockage&amp;amp;userName=davrous" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;  &lt;div id="__ss_11678265" style="margin-bottom: 5px; width: 425px"&gt;&lt;strong style="margin: 5px 0px 4px; display: block"&gt;&lt;a title="Création d&amp;#39;une application html5 utilisant canvas, svg et les animations css3" href="http://www.slideshare.net/davrous/cration-dune-application-html5-utilisant-canvas-svg-et-les-animations-css3"&gt;Création d'une application html5 utilisant canvas, svg et les animations css3&lt;/a&gt;&lt;/strong&gt;&lt;object id="__sse11678265" width="425" height="355"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=crationduneapplicationhtml5utilisantcanvassvgetlesanimationscss3-120220131103-phpapp02&amp;amp;stripped_title=cration-dune-application-html5-utilisant-canvas-svg-et-les-animations-css3&amp;amp;userName=davrous" /&gt;&lt;param name="allowFullScreen" value="true" /&gt;&lt;param name="allowScriptAccess" value="always" /&gt;&lt;param name="wmode" value="transparent" /&gt;&lt;embed name="__sse11678265" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=crationduneapplicationhtml5utilisantcanvassvgetlesanimationscss3-120220131103-phpapp02&amp;amp;stripped_title=cration-dune-application-html5-utilisant-canvas-svg-et-les-animations-css3&amp;amp;userName=davrous" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;  &lt;h2&gt;Quelques démonstrations à revoir en ligne&lt;/h2&gt;  &lt;p&gt;Voici une partie des démos que nous avons jouées dans la session sur Canvas, SVG &amp;amp; animations CSS3 :&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/01/06/amdev-slides-et-exemples-de-code-de-notre-session-svg-et-canvas.aspx"&gt;Démo balise vidéo avec player VideoJS&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://david.blob.core.windows.net/html5graphics/SimpleCSS3GridDemo.html"&gt;Démo simple de CSS3 Grid&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.bing.com/maps/#Y3A9NDguODQ2MjgzNDE3MzIxNX4yLjI3OTc5Nzk5OTk5OTk4MiZsdmw9MTMuOTU1MDAwMDAwMDAwMDA3JnN0eT1yJnJ0cD1wb3MuNDguODM0MzEyXzIuMjY1MTAxXzM5JTIwUXVhaSUyMGR1JTIwUHIlQzMlQTlzaWRlbnQlMjBSb29zZXZlbHQlMkMlMjA5MjEzMCUyMElzc3ktbGVzLU1vdWxpbmVhdXhfX19lX35wb3MuNDguODU4MjVfMi4yOTQ0OTVfVG91ciUyMEVpZmZlbCUyQyUyMFZpbGxlJTIwZGUlMjBQYXJpcyUyQyUyMEZyYW5jZV9fX2VfJm1vZGU9RCZydG9wPTB+MH4wfg=="&gt;SVG – Démo Bing Maps&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://ie.microsoft.com/testdrive/Graphics/RealWorldDataAndDiagrams/Default.xhtml"&gt;SVG – Complex document&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://raphaeljs.com/"&gt;SVG – RaphaelJS&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.highcharts.com/"&gt;SVG – HighCharts.com&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://people.mozilla.com/~dbolter/svg-checkbox-test.html"&gt;SVG – Accessibilité&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.atopon.org/mandel/"&gt;Canvas – MandelBrot&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://thejit.org/"&gt;Canvas – Complex charting&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://bolaslenses.catuhe.com/"&gt;Canvas – Bolas Lenses&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://dwpe.googlecode.com/svn/trunk/charting/index.html"&gt;Canvas – Accessibilité&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.catuhe.com/msdn/yoda/yoda.htm"&gt;Canvas – Coding4fun YODA&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.catuhe.com/msdn/transitions/index.htm"&gt;CSS3 Transitions – jeu de puzzle&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://david.blob.core.windows.net/html5/css3atat/index.htm"&gt;CSS3 Animations – StarWars AT-AT&lt;/a&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;h2&gt;Des articles complémentaires à lire&lt;/h2&gt;  &lt;p&gt;A noter qu’avec David, nous avons écrit une série d’articles tournant autour de ces sujets où vous retrouverez notamment nos “helpers”/librairies de “fallback” pour CSS3 Transitions/Animations. Les voici :&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/05/09/introduction-aux-apis-graphiques-d-html5-svg-amp-canvas-1-4.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/05/09/introduction-aux-apis-graphiques-d-html5-svg-amp-canvas-1-4.aspx"&gt;Introduction aux APIs graphiques d’HTML5: SVG &amp;amp; Canvas (1/2)&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/05/20/introduction-aux-apis-graphiques-d-html5-svg-amp-canvas-2-4.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/05/20/introduction-aux-apis-graphiques-d-html5-svg-amp-canvas-2-4.aspx"&gt;Introduction aux APIs graphiques d’HTML5: SVG &amp;amp; Canvas (2/2)&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="http://blogs.msdn.com/b/eternalcoding/archive/2011/11/24/fr-introduction-224-css3-transitions.aspx" href="http://blogs.msdn.com/b/eternalcoding/archive/2011/11/24/fr-introduction-224-css3-transitions.aspx"&gt;Introduction aux transitions CSS3&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-aux-animations-css3.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-aux-animations-css3.aspx"&gt;Introduction aux animations CSS3&lt;/a&gt;&amp;#160; &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Les vidéos à voir ou à revoir&lt;/h2&gt;  &lt;p&gt;Vous pouvez dors et déjà revoir la session “&lt;strong&gt;Création d’une application HTML5 utilisant Canvas, SVG et les animations CSS3&lt;/strong&gt;” car elle est déjà en ligne ici: &lt;a title="http://tdtv.microsoft.fr/j2/Live.aspx#fbid=MUCBi06MEn2" href="http://tdtv.microsoft.fr/j2/Live.aspx#fbid=MUCBi06MEn2"&gt;Replay du live Tehdays 2012 du mercredi 8 février&lt;/a&gt; et cliquez directement sur le dernier marqueur “Session Technique” pour sauter dans le temps vers 8h54.&lt;/p&gt;  &lt;p&gt;Au sujet de l’application Snapyx, nous travaillons actuellement à sa finalisation pour la mettre en ligne publiquement et vous laissez jouer avec. En attendant, vous pouvez la revoir dans la vidéo en ligne de la session précédente ou &lt;strong&gt;à la fin de la plénière du 1er jour dédiée aux développeurs&lt;/strong&gt; (vers 1h02 sur la timeline) sur YouTube ici: &lt;/p&gt; &lt;iframe style="margin-bottom: 10px" height="315" src="http://www.youtube.com/embed/r64B13fh9nc" frameborder="0" width="560" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;  &lt;p&gt;A bientôt pour de nouvelles aventures HTML5 !&lt;/p&gt;  &lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10269917" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/IE10/">IE10</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/TechDays2012/">TechDays2012</category></item><item><title>Venez découvrir le parcours Web aux Techdays 2012 avec du Windows 8 dedans !</title><link>http://blogs.msdn.com/b/davrous/archive/2012/01/27/venez-d-233-couvrir-le-parcours-web-aux-techdays-2012.aspx</link><pubDate>Fri, 27 Jan 2012 12:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10252484</guid><dc:creator>David Rousset</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10252484</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/01/27/venez-d-233-couvrir-le-parcours-web-aux-techdays-2012.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;&lt;span style="color: #804040;" color="#804040"&gt;Mise &amp;agrave; jour du 27/01/2012 sp&amp;eacute;ciale Windows 8 :&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Beaucoup d&amp;rsquo;entre vous ne l&amp;rsquo;ont pas encore remarqu&amp;eacute; mais nous avons la chance de pouvoir vous pr&amp;eacute;senter en 3 sessions le mod&amp;egrave;le de &lt;strong&gt;d&amp;eacute;veloppement de Windows 8 Metro&lt;/strong&gt;. Ces 3 sessions seront jou&amp;eacute;es aux m&amp;ecirc;mes cr&amp;eacute;neaux horaires sur les 3 jours. Les voici :&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=340e7a5e-8513-4f0e-b005-68e994e89e92&amp;amp;SessionID=7aca4b18-4c15-4d16-9743-bbed6bc3de74"&gt;Windows 8 : Construire une application au style METRO&lt;/a&gt; : vous d&amp;eacute;couvrirez ici les 8 traits importants constituant les bases d&amp;rsquo;une bonne application Metro. Cette session sera anim&amp;eacute;e par mes amis Eric Verni&amp;eacute; et David Catuhe&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=340e7a5e-8513-4f0e-b005-68e994e89e92&amp;amp;SessionID=a5eeebdd-fd9b-48ed-ad14-7f9cbb5e5507"&gt;Windows 8 : Architecture du nouveau Runtime de Windows&lt;/a&gt; : nous verrons ici les 3 mani&amp;egrave;res de &lt;strong&gt;cr&amp;eacute;er une application Metro &amp;agrave; l&amp;rsquo;aide de C++, C# et HTML5/JavaScript&lt;/strong&gt;. D&amp;eacute;veloppeurs JS : vous verrez ainsi, entre autres, comment cr&amp;eacute;er une application &amp;ldquo;from scratch&amp;rdquo; en 20 min acc&amp;eacute;dant &amp;agrave; l&amp;rsquo;ensemble de la plateforme. J&amp;rsquo;aurais la chance d&amp;rsquo;animer cette session avec mon clone David Catuhe.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=340e7a5e-8513-4f0e-b005-68e994e89e92&amp;amp;SessionID=16d2023c-55c8-4b65-b64e-0a8a85ad1e75"&gt;Windows 8 : Les outils pour construire des applications au style METRO&lt;/a&gt; : nous verrons ici les outils mis &amp;agrave; disposition du d&amp;eacute;veloppeur pour cr&amp;eacute;er des applications Metro. Ici on parlera en d&amp;eacute;tails de &lt;strong&gt;Visual Studio 11 et d&amp;rsquo;Expression Blend 5&lt;/strong&gt;. J&amp;rsquo;aurais la chance d&amp;rsquo;animer cette session avec mon ami Eric Verni&amp;eacute;.&lt;/p&gt;
&lt;p&gt;Donc messieurs, mesdames les d&amp;eacute;veloppeurs &amp;ldquo;web&amp;rdquo;, venez voir comment r&amp;eacute;utiliser vos comp&amp;eacute;tences pour fabriquer des applications Windows 8. Pour cela, inscrivez-vous vite sur le site des Techdays 2012 !&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6378.logo_5F00_mstechdays_5F00_2012_5F00_020EF877.png"&gt;&lt;img title="logo_mstechdays_2012" style="background-image: none; float: right; padding-top: 0px; padding-left: 0px; margin: 0px 5px 0px 10px; display: inline; padding-right: 0px; border-width: 0px;" border="0" alt="logo_mstechdays_2012" align="right" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0160.logo_5F00_mstechdays_5F00_2012_5F00_thumb_5F00_488BE87F.png" width="197" height="93" /&gt;&lt;/a&gt;Par ailleurs, comme depuis maintenant plusieurs ann&amp;eacute;es, j&amp;rsquo;ai la chance d&amp;rsquo;&amp;ecirc;tre responsable du parcours D&amp;eacute;veloppement Web aux &lt;a href="http://www.mstechdays.fr"&gt;Microsoft Techdays&lt;/a&gt;. Cette mission implique la d&amp;eacute;finition des sujets que je souhaiterais voir traiter, la d&amp;eacute;licate op&amp;eacute;ration de s&amp;eacute;lection des fameux &amp;ldquo;speakers&amp;rdquo; (ou orateurs en bon fran&amp;ccedil;ais) et bien entendu l&amp;rsquo;immense joie de d&amp;eacute;livrer moi-m&amp;ecirc;me certaines sessions. &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0830.wlEmoticon_2D00_smile_5F00_4DCF1F7A.png" /&gt;&lt;/p&gt;
&lt;p&gt;Cette ann&amp;eacute;e, je voulais mettre un accent fort sur HTML5 et tout ce qui gravite autour (JavaScript, CSS3, etc.) d&amp;rsquo;une part et les nouveaut&amp;eacute;s de nos frameworks/outils d&amp;rsquo;autre part. J&amp;rsquo;ai &amp;eacute;galement fait appel &amp;agrave; des orateurs issus de communaut&amp;eacute;s que j&amp;rsquo;appr&amp;eacute;cie et dont la qualit&amp;eacute; est reconnue de tous. Au final, je suis particuli&amp;egrave;rement content du programme. A vous de me dire ce que vous en pensez !&lt;/p&gt;
&lt;p&gt;Commen&amp;ccedil;ons par la galaxie HTML5 regroup&amp;eacute;e dans &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=439299ba-f894-423e-a035-2f85d519fce9"&gt;le parcours d&amp;eacute;couverte&lt;/a&gt; sur le site des TechDays.&lt;/p&gt;
&lt;h2&gt;HTML5&lt;/h2&gt;
&lt;h3&gt;Parcours Web&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=439299ba-f894-423e-a035-2f85d519fce9&amp;amp;SessionID=3590a981-19ec-4950-a5e3-2afd2f69e20c"&gt;&lt;strong&gt;Introduction &amp;agrave; JavaScript&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="http://braincracking.org/"&gt;&lt;strong&gt;Jean-Pierre Vincent&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; et &lt;/strong&gt;&lt;a href="http://blogs.msdn.com/pierlag"&gt;&lt;strong&gt;Pierre Lagarde&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Si vous &amp;ecirc;tes d&amp;rsquo;origine C#, VB.NET, C++, Java ou PHP et que vous souhaitez vous mettre au JavaScript pour de bonnes raisons, voici une excellente session &amp;agrave; suivre que j&amp;rsquo;ai programm&amp;eacute; le 1er cr&amp;eacute;neau du 1er jour. N&amp;rsquo;oubliez pas en effet que derri&amp;egrave;re HTML5, il y a toujours du JavaScript qui tourne ! Mieux vaut donc savoir comment il fonctionne et &amp;eacute;viter de partir sur de mauvais aprioris. Quoi de mieux que des experts tel que Jean-Pierre et Pierre pour cela ? (et non vous n&amp;rsquo;&amp;ecirc;tes pas oblig&amp;eacute; d&amp;rsquo;avoir Pierre dans votre pr&amp;eacute;nom pour faire du JS).&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=439299ba-f894-423e-a035-2f85d519fce9&amp;amp;SessionID=33b591de-c3c4-4c20-80fa-a23150f14a7a"&gt;&lt;strong&gt;Les nouveaut&amp;eacute;s HTML5 et CSS3 dans Internet Explorer 10&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par moi-m&amp;ecirc;me&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;IE10 a d&amp;eacute;sormais autant de trucs cools que les petits copains comme CSS3 &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2011/11/24/fr-introduction-224-css3-transitions.aspx"&gt;Transitions&lt;/a&gt;/&lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-aux-animations-css3.aspx"&gt;Animations&lt;/a&gt; ou IndexedDB et l&amp;rsquo;offline voir m&amp;ecirc;me des trucs en plus comme CSS3 Grid bien pratiques. Je passerais en revue toutes les nouveaut&amp;eacute;s importantes qui vont nous permettre d&amp;rsquo;envisager la construction d&amp;rsquo;applications de plus en plus riches en JavaScript/HTML5.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=439299ba-f894-423e-a035-2f85d519fce9&amp;amp;SessionID=0722f37b-1e49-49b7-9d51-fbbc3e8604af"&gt;&lt;strong&gt;D&amp;eacute;veloppement Web pour Mobiles&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="http://www.wygwam.com/"&gt;&lt;strong&gt;Aur&amp;eacute;lien Verla&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Une session anim&amp;eacute;e par l&amp;rsquo;excellent Aur&amp;eacute;lien qui sera &amp;agrave; cheval entre le d&amp;eacute;veloppement c&amp;ocirc;t&amp;eacute; serveur et c&amp;ocirc;t&amp;eacute; client qui vous montra comme tirer partie d&amp;rsquo;ASP.NET MVC c&amp;ocirc;t&amp;eacute; serveur et d&amp;rsquo;HTML5 et de jQuery Mobile c&amp;ocirc;t&amp;eacute; client pour cr&amp;eacute;er des exp&amp;eacute;riences web mobiles.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=439299ba-f894-423e-a035-2f85d519fce9&amp;amp;SessionID=deec50f3-4d86-4170-910e-eebf93e54481"&gt;&lt;strong&gt;Patterns et bonnes pratiques autour de JavaScript&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="http://braincracking.org/"&gt;&lt;strong&gt;Jean-Pierre Vincent&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Ici que je veux que Jean-Pierre vous montre que l&amp;rsquo;on peut bien architecturer son code JavaScript en suivant les bon patterns (module, namespace, etc.) voir m&amp;ecirc;me que l&amp;rsquo;on peut tester unitairement son code ! Bref, les bases indispensables &amp;agrave; avoir pour travailler sur des projets s&amp;eacute;rieux o&amp;ugrave; une &amp;eacute;quipe doit d&amp;eacute;livrer de la qualit&amp;eacute;. Cela tombe bien, Jean-Pierre a justement travaill&amp;eacute; dans ce domaine ! C&amp;rsquo;est &amp;eacute;galement le co-auteur du &lt;a href="http://livre-html5.com"&gt;livre HTML5 : De la page web &amp;agrave; l'application web&lt;/a&gt;. C&amp;rsquo;est donc une session &amp;agrave; suivre derri&amp;egrave;re la session d&amp;rsquo;introduction si vous en avez besoin.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=439299ba-f894-423e-a035-2f85d519fce9&amp;amp;SessionID=2ce877b0-f4e0-4173-a2f0-dc553788348d"&gt;&lt;strong&gt;Cr&amp;eacute;ation d'une application HTML5 g&amp;eacute;rant l'offline et le stockage client&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="http://blogs.msdn.com/eternalcoding"&gt;&lt;strong&gt;David Catuhe&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; et moi-m&amp;ecirc;me&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Avec David (l&amp;rsquo;autre), nous souhaitons vous pr&amp;eacute;senter les nouveaut&amp;eacute;s int&amp;eacute;ressantes autour &amp;ldquo;d&amp;rsquo;HTML5&amp;rdquo; pour construire des applications pouvant fonctionner hors connexion (Offline). Nous allons en profiter ainsi pour les d&amp;eacute;montrer &amp;agrave; travers une belle application que nous r&amp;eacute;utiliserons &amp;eacute;galement dans une autre session. Au programme : IndexedDB, Offline APIs, Drag&amp;rsquo;n&amp;rsquo;drop, File APIs, etc. Vous verrez ainsi que lorsque l&amp;rsquo;on utilise les tous derniers standards, on peut vraiment faire de belles choses !&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=439299ba-f894-423e-a035-2f85d519fce9&amp;amp;SessionID=5516b79d-804c-487d-b61e-247dd60c3a91"&gt;&lt;strong&gt;Trois avanc&amp;eacute;es majeures en CSS3 : Media Queries, Grid Layout et Animations&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="https://twitter.com/#!/goetter"&gt;&lt;strong&gt;Raphael Goetter&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Le Monsieur CSS3 d&amp;rsquo;&lt;a href="http://www.alsacreations.fr"&gt;Alsacr&amp;eacute;ations&lt;/a&gt; auteur du livre &lt;a title="http://www.goetter.fr/livres/css-avancees/" href="http://www.goetter.fr/livres/css-avancees/"&gt;CSS avanc&amp;eacute;es vers HTML5 et CSS3&lt;/a&gt; nous fait le plaisir de venir animer une session autour de 3 avanc&amp;eacute;es majeures dans ce domaine. Je vous conseille donc vivement cette session anim&amp;eacute;e par l&amp;rsquo;une des r&amp;eacute;f&amp;eacute;rences fran&amp;ccedil;aises sur CSS !&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=439299ba-f894-423e-a035-2f85d519fce9&amp;amp;SessionID=8d778efa-6481-4190-94dc-5ba271807425"&gt;&lt;strong&gt;D&amp;eacute;veloppement de jeux 2D avec HTML5&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="http://pierreloicdoulcet.fr/"&gt;&lt;strong&gt;Pierre-Loic Doulcet&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Rencontr&amp;eacute; lors du &lt;a href="http://parisjs.org"&gt;ParisJS&lt;/a&gt; h&amp;eacute;berg&amp;eacute; par Microsoft France, Pierre-Loic partage le m&amp;ecirc;me genre de passion que moi. Il s&amp;rsquo;occupera de vous faire r&amp;ecirc;ver avec le d&amp;eacute;veloppement de jeux 2D mobile et web gr&amp;acirc;ce &amp;agrave; HTML5.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=439299ba-f894-423e-a035-2f85d519fce9&amp;amp;SessionID=5c43ba8c-badd-43a1-b110-e266ece26ebe"&gt;&lt;strong&gt;Cr&amp;eacute;ation d'une application HTML5 utilisant Canvas, SVG et les animations CSS3&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="http://blogs.msdn.com/eternalcoding"&gt;&lt;strong&gt;David Catuhe&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; et moi-m&amp;ecirc;me&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Ici nous allons reprendre l&amp;rsquo;application g&amp;eacute;rant l&amp;rsquo;offline et mettre l&amp;rsquo;accent sur la partie &amp;ldquo;graphique&amp;rdquo; de l&amp;rsquo;application. Nous reverrons rapidement les bases et les diff&amp;eacute;rences entre canvas et SVG puis nous verrons comment nous les avons utilis&amp;eacute;s dans notre application d&amp;rsquo;exemple. Nous verrons &amp;eacute;galement l&amp;rsquo;utilisation des nouveaut&amp;eacute;s de CSS3 pour animer nos &amp;eacute;l&amp;eacute;ments. C&amp;rsquo;est donc une session compl&amp;eacute;mentaire de la pr&amp;eacute;c&amp;eacute;dente.&lt;/p&gt;
&lt;h3&gt;Autres parcours&lt;/h3&gt;
&lt;p&gt;Pour finir sur HTML5, voici 2 autres sessions que je vous recommande issues d&amp;rsquo;autres parcours :&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=439299ba-f894-423e-a035-2f85d519fce9&amp;amp;SessionID=304845f3-9d01-4599-82e5-179330132b66"&gt;&lt;strong&gt;Accessibilit&amp;eacute; du Web 2.0 : HTML5 et WAI-ARIA&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="http://twitter.com/goetsu"&gt;&lt;strong&gt;Aur&amp;eacute;lien Levy&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; et &lt;/strong&gt;&lt;a href="http://twitter.com/#!/tibolan"&gt;&lt;strong&gt;Thibault Lanssade&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;L&amp;rsquo;accessibilit&amp;eacute; est un sujet &amp;eacute;minemment important et HTML5 apportera quelques &amp;eacute;l&amp;eacute;ments de r&amp;eacute;ponses int&amp;eacute;ressants. Venez d&amp;eacute;couvrir ce sujet anim&amp;eacute; par 2 experts en la mati&amp;egrave;re.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=439299ba-f894-423e-a035-2f85d519fce9&amp;amp;SessionID=ee825bb4-91dc-4b47-b8e3-dea68d8bd9af"&gt;&lt;strong&gt;HTML5 sur mobile: le bon, la brute et un gros paquet de truands anim&amp;eacute;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; par &lt;/strong&gt;&lt;a href="http://blogs.msdn.com/pierreca"&gt;&lt;strong&gt;Pierre Cauchois&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;R&amp;eacute;put&amp;eacute; pour avoir les titres de sessions les plus cool des TechDays, Pierre a envie ici de faire un &amp;eacute;tat des lieux sur le d&amp;eacute;veloppement cross-plateformes en HTML5 et de faire sauter certaines croyances erron&amp;eacute;es sur la magie trop souvent associ&amp;eacute;e &amp;agrave; HTML5.&lt;/p&gt;
&lt;h2&gt;Du c&amp;ocirc;t&amp;eacute; du serveur Web&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=b04fa7a6-32fc-4b94-a21a-b0e48697d664&amp;amp;SessionID=a114a0fc-adce-4942-9288-64af58209d2a"&gt;&lt;strong&gt;D&amp;eacute;velopper le potentiel de IIS7.5 pour des sc&amp;eacute;narios de haute disponibilit&amp;eacute;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="https://twitter.com/#!/loic_calvy"&gt;&lt;strong&gt;Lo&amp;iuml;c Calvy&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; et &lt;/strong&gt;&lt;a href="https://twitter.com/#!/paulcociuba"&gt;&lt;strong&gt;Paul Cociuba&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Revenons aux bases! Venez d&amp;eacute;couvrir comment tirer au mieux partie d&amp;rsquo;IIS dans plusieurs sc&amp;eacute;narios de haute disponibilit&amp;eacute;. Lo&amp;iuml;c dispose d&amp;rsquo;une exp&amp;eacute;rience et d&amp;rsquo;un recul tr&amp;egrave;s int&amp;eacute;ressant sur de la mise en production sur ce sujet et Paul nous vient de nos &amp;eacute;quipes de support europ&amp;eacute;en en tant qu&amp;rsquo;ing&amp;eacute;nieur d&amp;rsquo;escalade sur IIS. Bref, &amp;agrave; eux 2, vous devriez forc&amp;eacute;ment apprendre plein de choses int&amp;eacute;ressantes!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=b04fa7a6-32fc-4b94-a21a-b0e48697d664&amp;amp;SessionID=6e6f95a3-9430-4c45-8818-f74c6d9a1b9f"&gt;&lt;strong&gt;Quoi de neuf dans ASP.NET 4.5&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="http://blogs.codes-sources.com/tja/default.aspx"&gt;&lt;strong&gt;Thomas Jaskula&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thomas aura pour mission ici de vous faire d&amp;eacute;couvrir l&amp;rsquo;ensemble des nouveaut&amp;eacute;s de la plateforme ASP.NET 4.5, du c&amp;oelig;ur en passant par WebForms et MVC. Bref, une session assur&amp;eacute;ment &amp;agrave; ne pas louper pour suivre les derni&amp;egrave;res &amp;eacute;volutions de la brique ASP.NET du framework .NET.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=b04fa7a6-32fc-4b94-a21a-b0e48697d664&amp;amp;SessionID=cfeebe6c-a5bf-4cff-9f9c-133d30501bd3"&gt;&lt;strong&gt;Architecture, bonnes pratiques et recettes pour la r&amp;eacute;ussite de vos projets avec ASP.NET MVC&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="http://www.rui.fr/"&gt;&lt;strong&gt;Rui Carvalho&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; et &lt;/strong&gt;&lt;a href="http://www.juliencorioland.net/"&gt;&lt;strong&gt;Julien Corioland&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Rui et Julien ont tous les 2 une v&amp;eacute;ritable expertise sur la mise en pratique d&amp;rsquo;ASP.NET MVC. Cette session vous permettra de profiter de leur exp&amp;eacute;rience pour b&amp;eacute;n&amp;eacute;ficier d&amp;rsquo;un cahier de recettes &amp;agrave; mettre en &amp;oelig;uvre dans vos futurs projets utilisant notre framework.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=b04fa7a6-32fc-4b94-a21a-b0e48697d664&amp;amp;SessionID=a9e96174-d1a2-4d80-9a8a-1b0d29b70877"&gt;&lt;strong&gt;WebMatrix 2 : le couteau suisse gratuit pour vos d&amp;eacute;veloppements Web&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="http://www.smartview.fr/"&gt;&lt;strong&gt;Gilles Pommier&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; et &lt;/strong&gt;&lt;a href="http://blog.couzy.com/"&gt;&lt;strong&gt;Pierre Couzy&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Une heure sympa pour d&amp;eacute;couvrir WebMatrix 2 et Razor en compagnie de Gilles et de mon coll&amp;egrave;gue Pierre qui vous monteront comment r&amp;eacute;aliser une application de bout en bout. Si vous ne connaissez pas WebMatrix, c&amp;rsquo;est un outil gratuit permettant soit d'&amp;eacute;diter des solutions toutes faites comme Drupal, Wordpress, DotNetNuke tr&amp;egrave;s facilement, soit de d&amp;eacute;velopper avec le langage Razor. Ca vaut vraiment le coup d&amp;rsquo;y jeter un &amp;oelig;il si vous ne connaissez pas d&amp;eacute;j&amp;agrave;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=b04fa7a6-32fc-4b94-a21a-b0e48697d664&amp;amp;SessionID=034efe48-5a21-4ce4-8ed8-c410662accd7"&gt;&lt;strong&gt;Introduction &amp;agrave; DotNetNuke&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="https://twitter.com/#!/6RiL_fr"&gt;&lt;strong&gt;Cyril Plassard&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Cela fait justement parti des solutions d&amp;eacute;ployables par WebMatrix. Venez d&amp;eacute;couvrir ce CMS bas&amp;eacute; sur les technologies Microsoft et pr&amp;eacute;sent&amp;eacute; par un membre de sa communaut&amp;eacute;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=b04fa7a6-32fc-4b94-a21a-b0e48697d664&amp;amp;SessionID=16517a28-bddb-4f6b-aed4-3dcf17cb9372"&gt;&lt;strong&gt;PHP dans le monde Microsoft&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; anim&amp;eacute; par &lt;/strong&gt;&lt;a href="http://fr.viadeo.com/profile/00223og1tsxe86u0"&gt;&lt;strong&gt;Christophe Villeneuve&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; et &lt;/strong&gt;&lt;a href="http://blog.couzy.com/"&gt;&lt;strong&gt;Pierre Couzy&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Microsoft s&amp;rsquo;est v&amp;eacute;ritablement int&amp;eacute;ress&amp;eacute; au monde PHP ces derni&amp;egrave;res ann&amp;eacute;es et ce n&amp;rsquo;est pas Pierre Couzy qui me dira le contraire ! &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" alt="Clignement d'&amp;oelig;il" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5554.wlEmoticon_2D00_winkingsmile_5F00_471A7A57.png" /&gt; Venez justement voir un membre de l&amp;rsquo;AFUP et un employ&amp;eacute; de Microsoft vous partager comment les 2 univers ont travaill&amp;eacute; ensemble pour avancer dans le bon sens avec diff&amp;eacute;rentes illustrations comme Drupal, le driver PDO pour SQL Server, le support de SQL Azure, etc.&lt;/p&gt;
&lt;h2&gt;En r&amp;eacute;sum&amp;eacute;&amp;hellip;&lt;/h2&gt;
&lt;p&gt;J&amp;rsquo;esp&amp;egrave;re que ce petit programme sera &amp;agrave; la hauteur de votre soif technique et de ce que vous cherchez en ce moment comme type de sessions, que ce soit pour vos besoins de veilles technologies ou de choix d&amp;rsquo;architectures. Normalement, que vous soyez d&amp;eacute;veloppeurs web &amp;ldquo;front&amp;rdquo; ou &amp;ldquo;back&amp;rdquo;, il devrait y avoir de bonnes choses &amp;agrave; apprendre.&lt;/p&gt;
&lt;p&gt;Allez, bonne ann&amp;eacute;e 2012, bon Techdays 2012 et &amp;agrave; bient&amp;ocirc;t au palais des congr&amp;egrave;s !&lt;/p&gt;
&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10252484" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/ASPNET/">ASPNET</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/CSS3/">CSS3</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/IE10/">IE10</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/TechDays2012/">TechDays2012</category></item><item><title>AMDEV JavaScript: vidéos, slides et exemples de code des 4 sessions</title><link>http://blogs.msdn.com/b/davrous/archive/2012/01/06/amdev-slides-et-exemples-de-code-de-notre-session-svg-et-canvas.aspx</link><pubDate>Fri, 06 Jan 2012 04:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10235917</guid><dc:creator>David Rousset</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10235917</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2012/01/06/amdev-slides-et-exemples-de-code-de-notre-session-svg-et-canvas.aspx#comments</comments><description>&lt;!-- Include the VideoJS Library --&gt;
&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;
&lt;p&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5432.ADDJS_5F00_444675E0.png"&gt;&lt;img style="background-image: none; margin: 0px 10px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; padding-top: 0px; border-width: 0px;" title="ADDJS" border="0" alt="ADDJS" align="left" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3858.ADDJS_5F00_thumb_5F00_32A66548.png" width="150" height="150" /&gt;&lt;/a&gt;Vous &amp;eacute;tiez un peu plus de &lt;strong&gt;200&lt;/strong&gt; &amp;agrave; &amp;ecirc;tre venus &amp;agrave; notre centre de conf&amp;eacute;rence retirer votre T-Shirt et surtout pour assister &amp;agrave; l&amp;rsquo;apr&amp;egrave;s-midi du d&amp;eacute;veloppement consacr&amp;eacute;e &amp;agrave; JavaScript et HTML5. Merci &amp;agrave; vous !&lt;/p&gt;
&lt;p&gt;Je tiens tout d&amp;rsquo;abord &amp;agrave; remercier chaleureusement les 2 orateurs non-Microsoft pour la qualit&amp;eacute; de leur pr&amp;eacute;sentation : &lt;a href="https://twitter.com/theystolemynick"&gt;Jean-Pierre Vincent&lt;/a&gt; pour les fondamentaux de JavaScript et Aur&amp;eacute;lien Verla de &lt;a href="http://www.wygwam.com"&gt;Wygwam&lt;/a&gt; pour sa superbe session sur jQuery.&lt;/p&gt;
&lt;h2&gt;JavaScript&lt;/h2&gt;
&lt;p&gt;Vous pouvez retrouver les slides de Jean-Pierre ici : &lt;a title="http://www.slideshare.net/jpvincent/javascript-fondamentaux-et-oop" href="http://www.slideshare.net/jpvincent/javascript-fondamentaux-et-oop"&gt;les fondamentaux de JavaScript et la programmation orient&amp;eacute; objet&lt;/a&gt; . Vous pourrez donc revoir tout cela calmement &amp;agrave; la maison pour essayer de dig&amp;eacute;rer toutes les bonnes pratiques que Jean-Pierre nous a partag&amp;eacute;es. En compl&amp;eacute;ment, si le sujet vous int&amp;eacute;resse, je ne serais que trop vous conseiller ces 3 livres si vous ne les avez pas d&amp;eacute;j&amp;agrave; lus :&lt;/p&gt;
&lt;p&gt;- &lt;a href="http://www.amazon.fr/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742/ref=sr_1_1?ie=UTF8&amp;amp;qid=1320954867&amp;amp;sr=8-1"&gt;JavaScript The Good Parts&lt;/a&gt; &lt;br /&gt;- &lt;a href="http://www.amazon.fr/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752/ref=sr_1_1?s=english-books&amp;amp;ie=UTF8&amp;amp;qid=1320954902&amp;amp;sr=1-1"&gt;JavaScript Patterns&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Sans compter le livre de Jean-Pierre bien entendu : &lt;a title="http://www.amazon.fr/HTML5-page-web-%C3%A0-lapplication/dp/2100565281/ref=sr_1_cc_2?s=english-books&amp;amp;ie=UTF8&amp;amp;qid=1320954928&amp;amp;sr=1-2-catcorr" href="http://www.amazon.fr/HTML5-page-web-%C3%A0-lapplication/dp/2100565281/ref=sr_1_cc_2?s=english-books&amp;amp;ie=UTF8&amp;amp;qid=1320954928&amp;amp;sr=1-2-catcorr"&gt;HTML5 - De la page web &amp;agrave; l'application web&lt;/a&gt; ! Avec tout &amp;ccedil;a, &amp;agrave; vous la maitrise des closures, prototypage, namespace, POO &amp;agrave; la sauce JavaScript, j&amp;rsquo;en passe et des meilleurs. J&amp;rsquo;esp&amp;egrave;re que les sceptiques seront alors convaincus que l&amp;rsquo;on peut organiser son code, faire du d&amp;eacute;veloppement s&amp;eacute;rieux et maintenable (et m&amp;ecirc;me testable!) avec JavaScript en &amp;eacute;vitant d&amp;rsquo;avoir 480 variables globales par exemple. &lt;img class="wlEmoticon wlEmoticon-smilewithtongueout" alt="Tire la langue" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8461.wlEmoticon_2D00_smilewithtongueout_5F00_50C9CEF4.png" /&gt;&lt;/p&gt;
&lt;p&gt;Voici la vid&amp;eacute;o de session :&lt;/p&gt;
&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="FondamentauxJS" class="video-js" poster="http://david.blob.core.windows.net/videos/1_FondamentauxJavaScript.png" preload="preload" controls="controls" width="512" height="288"&gt;&lt;source type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" src="http://david.blob.core.windows.net/videos/1_FondamentauxJavascript.mp4" /&gt;&lt;source type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" src="http://david.blob.core.windows.net/videos/1_FondamentauxJavascript.webm" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="512" type="application/x-shockwave-flash" height="288"&gt;&lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/1_FondamentauxJavaScript.png&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/1_FondamentauxJavascript.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;&lt;!-- Image Fallback. Typically the same as the poster image. --&gt; &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/1_FondamentauxJavaScript.png" width="512" height="288" /&gt; &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;
&lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/videos/1_FondamentauxJavascript.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/1_FondamentauxJavascript.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;p class="vjs-no-video"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;h2&gt;Outils de debug&lt;/h2&gt;
&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="OutilsDebug" class="video-js" poster="http://david.blob.core.windows.net/videos/2_OutilsDeDebug.png" preload="preload" controls="controls" width="512" height="288"&gt;&lt;source type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" src="http://david.blob.core.windows.net/videos/2_OutilsDeDebug.mp4" /&gt;&lt;source type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" src="http://david.blob.core.windows.net/videos/2_OutilsDeDebug.webm" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="Object1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="512" type="application/x-shockwave-flash" height="288"&gt;&lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/2_OutilsDeDebug.png&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/2_OutilsDeDebug.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;&lt;!-- Image Fallback. Typically the same as the poster image. --&gt; &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/2_OutilsDeDebug.png" width="512" height="288" /&gt; &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;
&lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/videos/2_OutilsDeDebug.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/2_OutilsDeDebug.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;p class="vjs-no-video"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;h2&gt;jQuery&lt;/h2&gt;
&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="IntroductionjQuery" class="video-js" poster="http://david.blob.core.windows.net/videos/3_IntroductionjQuery.png" preload="preload" controls="controls" width="512" height="288"&gt;&lt;source type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" src="http://david.blob.core.windows.net/videos/3_IntroductionjQuery.mp4" /&gt;&lt;source type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" src="http://david.blob.core.windows.net/videos/3_IntroductionjQuery.webm" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="Object2" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="512" type="application/x-shockwave-flash" height="288"&gt;&lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/3_IntroductionjQuery.png&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/3_IntroductionjQuery.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;&lt;!-- Image Fallback. Typically the same as the poster image. --&gt; &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/3_IntroductionjQuery.png" width="512" height="288" /&gt; &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;
&lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/videos/3_IntroductionjQuery.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/3_IntroductionjQuery.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;p class="vjs-no-video"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;C&amp;ocirc;t&amp;eacute; jQuery, je publierais les slides d&amp;rsquo;Aur&amp;eacute;lien d&amp;egrave;s que je les aurais en mettant &amp;agrave; jour ce post. Mais comme il a tout fait avec son plug-in jQuery, je vous zipperais sa solution plut&amp;ocirc;t.&lt;/p&gt;
&lt;h2&gt;Canvas &amp;amp; SVG&lt;/h2&gt;
&lt;p&gt;Les slides de notre session avec &lt;a href="http://blogs.msdn.com/eternalcoding"&gt;David Catuhe&lt;/a&gt; sur Canvas et SVG sont ici (PowerPoint en JavaScript ! &lt;img class="wlEmoticon wlEmoticon-openmouthedsmile" alt="Rire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5342.wlEmoticon_2D00_openmouthedsmile_5F00_5B6C387F.png" /&gt;) :&lt;/p&gt;
&lt;p&gt;&lt;iframe height="327" src="http://r.office.microsoft.com/r/rlidPowerPointEmbed?p1=1&amp;amp;p2=1&amp;amp;p3=SDEE4BD0F5EA745C6!2017&amp;amp;p4=&amp;amp;kip=1" frameborder="0" width="402" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Je les ai mis aussi sur SlideShare : &lt;a href="http://www.slideshare.net/davrous/amdev-graphismes-avec-html5-grce-canvas-et-svg"&gt;http://www.slideshare.net/davrous/amdev-graphismes-avec-html5-grce-canvas-et-svg&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;La vid&amp;eacute;o :&lt;/p&gt;
&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="Video1" class="video-js" poster="http://david.blob.core.windows.net/videos/4_Graphismes%20HTML5_CanvasSVG.png" preload="preload" controls="controls" width="512" height="288"&gt;&lt;source type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" src="http://david.blob.core.windows.net/videos/4_Graphismes%20HTML5_CanvasSVG.mp4" /&gt;&lt;source type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" src="http://david.blob.core.windows.net/videos/4_Graphismes%20HTML5_CanvasSVG.webm" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="Object3" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" width="512" type="application/x-shockwave-flash" height="288"&gt;&lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/4_Graphismes%20HTML5_CanvasSVG.png&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/4_Graphismes%20HTML5_CanvasSVG.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;&lt;!-- Image Fallback. Typically the same as the poster image. --&gt; &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/4_Graphismes%20HTML5_CanvasSVG.png" width="512" height="288" /&gt; &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;
&lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/videos/4_Graphismes%20HTML5_CanvasSVG.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/4_Graphismes%20HTML5_CanvasSVG.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;p class="vjs-no-video"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Vous retrouverez quasiment tous les &lt;strong&gt;exemples de code des d&amp;eacute;mos d&amp;eacute;montr&amp;eacute;es&lt;/strong&gt; &amp;agrave; travers ces 4 articles ou s&amp;eacute;ries d&amp;rsquo;articles :&lt;/p&gt;
&lt;p&gt;- &lt;a href="http://blogs.msdn.com/davrous/archive/2011/05/09/introduction-aux-apis-graphiques-d-html5-svg-amp-canvas-1-4.aspx"&gt;Introduction aux APIs graphiques d&amp;rsquo;HTML5: SVG &amp;amp; Canvas&lt;/a&gt; (2 articles) &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/davrous/archive/2011/09/09/html5-platformer-portage-complet-du-jeu-xna-vers-lt-canvas-gt-gr-226-ce-224-easeljs.aspx"&gt;HTML5 Platformer: portage complet du jeu XNA vers &amp;lt;canvas&amp;gt; gr&amp;acirc;ce &amp;agrave; EaselJS&lt;/a&gt; (3 articles) &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/eternalcoding/archive/2011/07/13/retours-sur-un-d-233-veloppement-html5-amp-javascript.aspx"&gt;Bolas Lenses : un d&amp;eacute;veloppement HTML5 Canvas &amp;amp; JavaScript&lt;/a&gt; &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2011/09/02/cahier-de-vacances-html-5-d-233-velopper-son-propre-jeu-de-casse-briques-en-html-5-avec-canvas-et-svg.aspx"&gt;D&amp;eacute;velopper un jeu de casse-briques avec Canvas et SVG&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;C&amp;ocirc;t&amp;eacute; &lt;strong&gt;accessibilit&amp;eacute;&lt;/strong&gt;, si le sujet vous int&amp;eacute;resse, j&amp;rsquo;avais &amp;eacute;t&amp;eacute; un peu plus loin que ce que je vous ai montr&amp;eacute; cette apr&amp;egrave;s-midi dans cet article : &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/02/21/slides-et-ressources-de-la-session-accessibilit-233-d-html5-et-silverlight-des-techdays-2011.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/02/21/slides-et-ressources-de-la-session-accessibilit-233-d-html5-et-silverlight-des-techdays-2011.aspx"&gt;Techdays 2011 &amp;ndash; slides et ressources de la session Accessibilit&amp;eacute; d&amp;rsquo;HTML5 et Silverlight&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Je finirais par remercier mon acolyte Monsieur Catuhe avec lequel je me suis bien marr&amp;eacute;. Nous avons essay&amp;eacute; de partager notre bonne humeur naturelle et notre humour pourrie de g33k/d&amp;eacute;veloppeur.&lt;/p&gt;
&lt;p&gt;A bient&amp;ocirc;t pour de nouvelles aventures !&lt;/p&gt;
&lt;p&gt;David&amp;sup2;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10235917" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Canvas/">Canvas</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/SVG/">SVG</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/JavaScript/">JavaScript</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/AMDEV/">AMDEV</category></item><item><title>Tutorial: how to create HTML5 applications on Windows Phone thanks to PhoneGap</title><link>http://blogs.msdn.com/b/davrous/archive/2011/12/23/tutorial-how-to-create-html5-applications-on-windows-phone-thanks-to-phonegap.aspx</link><pubDate>Fri, 23 Dec 2011 17:00:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10250721</guid><dc:creator>David Rousset</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10250721</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2011/12/23/tutorial-how-to-create-html5-applications-on-windows-phone-thanks-to-phonegap.aspx#comments</comments><description>&lt;p&gt;We will first see in this article what the added values of PhoneGap for HTML5 applications are. We’ll then discover how to create our very first project where we will retrieve the accelerometer’s values from our JavaScript code. At last, we will review a complete HTML5 gaming sample almost ported as-is to PhoneGap to use the accelerometer available on the Windows Phones.&amp;#160;&amp;#160; &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="#introduction"&gt;Introduction&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#phonegap"&gt;PhoneGap: a framework filling the gap&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#firstproject"&gt;Let’s create our first PhoneGap project&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#accelero"&gt;Getting the accelerometer’s values from JavaScript&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#html5platformer"&gt;Review of a complete sample with the HTML5 Platformer game&lt;/a&gt;       &lt;ol&gt;       &lt;li&gt;Forcing the landscape orientation &lt;/li&gt;        &lt;li&gt;Handling various resolutions &lt;/li&gt;        &lt;li&gt;Loading the levels with calls to the file system instead of using XHR &lt;/li&gt;        &lt;li&gt;Modification of the gameplay to use the accelerometer &lt;/li&gt;        &lt;li&gt;Screenshots of the result and FPS on some phones &lt;/li&gt;        &lt;li&gt;Complete Visual Studio Solution to download &lt;/li&gt;     &lt;/ol&gt;   &lt;/li&gt;    &lt;li&gt;&lt;a href="#conclusion"&gt;Conclusion&lt;/a&gt; &lt;/li&gt; &lt;/ol&gt; &lt;a name="introduction"&gt;   &lt;h2&gt;Introduction&lt;/h2&gt; &lt;/a&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1651.image_5F00_679E8583.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 10px 10px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="left" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1541.image_5F00_thumb_5F00_05306083.png" width="132" height="240" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The Mango update for Windows Phone came with the &lt;strong&gt;support of HTML5 thanks to the embedded IE9 browser&lt;/strong&gt;. As the desktop version, the mobile version of IE9 delivers hardware acceleration through the GPU of your Windows Phone. Thus, combined with JavaScript, IE9 can now serve as a base of interesting user’s experiences usually reserved to “native code”. &lt;/p&gt;  &lt;p&gt;The Pros of using HTML5 as a development platform is a relative promise to easily re-use parts of the code on others compatibles platforms like Android or iOS. HTML5 has then driven a lot of interests from the mobiles developers’ ecosystem during the last months. &lt;/p&gt;  &lt;p&gt;However, even if the HTML5/CSS3/SVG &amp;amp; JavaScript specifications have greatly evolved during the last months, they still &lt;strong&gt;lack some major features to build mobile applications&lt;/strong&gt;. Indeed, a phone or a tablet exposes specific capabilities like: GPS, accelerometer, camera, sending SMS, accessing contacts, etc.&lt;/p&gt;  &lt;p&gt;To have access to these capabilities from the JavaScript code, the W3C has been working now for a while on what we call “&lt;a href="http://www.w3.org/2009/dap/"&gt;Device APIs&lt;/a&gt;” or &lt;strong&gt;DAP&lt;/strong&gt;. Unfortunately, we can consider that no implementation currently exists of those specifications as this document seems to confirm: &lt;a title="http://www.w3.org/2011/11/mobile-web-app-state.html" href="http://www.w3.org/2011/11/mobile-web-app-state.html"&gt;Standards for Web Applications on Mobile: November 2011 current state and roadmap&lt;/a&gt; . Mozilla has started an interesting work by more or less forking those specifications via what they call &lt;a href="http://hacks.mozilla.org/2011/08/introducing-webapi/"&gt;Web APIs&lt;/a&gt; to support their &lt;a href="http://hacks.mozilla.org/2011/07/announcing-boot-to-gecko-b2g-booting-to-the-web/"&gt;Boot To Gecko&lt;/a&gt; project. This is then a good news as a form of implementation seems to start with an on-going discussions with the W3C. However, even if things start to move slowly, we will probably have to wait for several years before having a stable official W3C specification implemented widely on all platforms.&lt;/p&gt;  &lt;p&gt;So the question is: what should we do in the meantime? Can HTML5 really address those scenarios?&lt;/p&gt; &lt;a name="phonegap"&gt;   &lt;h2&gt;PhoneGap: a framework filling the gap&lt;/h2&gt; &lt;/a&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 10px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" align="right" src="http://phonegap.com/assets/artwork/Build-Diagram-2.png" width="300" height="225" /&gt;&lt;/p&gt;  &lt;p&gt;While waiting on real standardized specifications, we don’t have the choice: we need to create some &lt;strong&gt;bridges between JavaScript and the native code&lt;/strong&gt; of the targeted platform to have access to its capabilities. The idea is then the following one: taking the native languages of each platform (C#, Objective-C and Java) and creating a framework with these languages that will expose interfaces to the JavaScript developer.&lt;/p&gt;  &lt;p&gt;This is exactly what &lt;a href="http://phonegap.com/"&gt;PhoneGap&lt;/a&gt; is doing. Let’s take the Windows Phone case which is the main topic of this article. A Windows Phone’s PhoneGap project is simply a Silverlight application hosting the WebBrowser control (and thus IE9) as well as a Silverlight Assembly written in C# which does the job to access to the accelerometer, GPS, contacts, camera and so on. In this way, as a JavaScript developer, you will use a DLL named &lt;strong&gt;WP7GapClassLib.dll&lt;/strong&gt; (the PhoneGap core runtime) without even knowing it via the usage of the code embedded in the &lt;strong&gt;phonegap-1.3.0.js &lt;/strong&gt;file. This DLL contains some C# code which does calls to the Silverlight runtime available on the phone. As the runtime has access to all the capabilities of the phone, the JavaScript will do also. The JavaScript library will then act as a gateway between both worlds. Moreover, the good point of using this library is that your code will most of the time works as-is on the PhoneGap versions of Android or iOS. PhoneGap offers then an interesting form of portability.&lt;/p&gt;  &lt;p&gt;Please note by the way that the PhoneGap support for Windows Phone is now totally complete since the recent 1.3.0 version:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-86-46/1362.PhoneGap.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-86-46/1362.PhoneGap.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;At last, PhoneGap offers also another interesting service. It embeds your .js, .css, .html, .png resources inside its projects to package it as a classical application. In summary, you can use PhoneGap to package your HTML5 application for the various applications' stores. This is for instance the case of the &lt;a href="http://www.windowsphone.com/en-US/apps/09dc9317-0f63-4a98-9042-47c7976b2d88"&gt;SujiQ Windows Phone application&lt;/a&gt; built using this approach. &lt;/p&gt; &lt;a name="firstproject"&gt;   &lt;h2&gt;Let’s create our first PhoneGap project&lt;/h2&gt; &lt;/a&gt;  &lt;h3&gt;Prerequisites&lt;/h3&gt;  &lt;p&gt;Here are the very first steps you need to follow:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Download the Windows Phone SDK: &lt;a href="http://aka.ms/hp-windows-phone"&gt;Windows Phone SDK&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Download the last version of Phone (1.3.0 today) on their site: &lt;a title="http://phonegap.com/" href="http://phonegap.com/"&gt;http://phonegap.com/&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Unzip the downloaded file&amp;#160; &lt;/li&gt;    &lt;li&gt;Copy the &lt;strong&gt;PhoneGapStarter.zip &lt;/strong&gt;and&lt;strong&gt; PhoneGapCustom.zip&lt;/strong&gt; files into &lt;font color="#008000"&gt;&lt;strong&gt;\Documents\Visual Studio 2010\Templates\ProjectTemplates&lt;/strong&gt;&lt;/font&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;File-&amp;gt;New project&lt;/h3&gt;  &lt;p&gt;Once the previous steps are done, you will be able to create your first PhoneGap project. Start Visual Studio 2010, select the “Visual C#” templates and filter them via the “Gap” keyword. You should then see a new type of project named &lt;strong&gt;PhoneGapStarter&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6330.image_5F00_7EB46BEA.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5353.image_5F00_thumb_5F00_59E308D9.png" width="640" height="452" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Name your project “&lt;em&gt;MyFirstPhoneGapProject&lt;/em&gt;”. Once done, you will find the files I was talking about before in the Solution Explorer:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5661.image_5F00_21D0EF29.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6242.image_5F00_thumb_5F00_57F26778.png" width="200" height="281" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You just now have to insert your HTML5 application into the “www” directory.&lt;/p&gt;  &lt;p&gt;Here are several tips I’d like to share with you about this default project template:&lt;/p&gt;  &lt;p&gt;- &lt;strong&gt;never ever touch the&lt;/strong&gt;&amp;#160;&lt;strong&gt;&lt;em&gt;phonegap-1.3.0.js &lt;/em&gt;file&lt;/strong&gt; if you’d like to keep a portable code on other versions of PhoneGap     &lt;br /&gt;- all files you will add inside the “www” directory must be set as “&lt;strong&gt;Content&lt;/strong&gt;” in the properties window&amp;#160; &lt;br /&gt;- instead of the &lt;em&gt;WP7GapClassLib.dll&lt;/em&gt; binary file, you can add a reference to the &lt;em&gt;WP7GapClassLib.csproj&lt;/em&gt; C# project available in the “&lt;em&gt;Windows Phone\framework&lt;/em&gt;” directory of the downloaded PhoneGap archive. It will help you debugging or discovering the native code of the PhoneGap library if needed.&lt;/p&gt;  &lt;p&gt;Ok, let’s now start by doing something normally impossible by default with IE9 Mango: accessing to the accelerometer’s values from JavaScript.&lt;/p&gt; &lt;a name="accelero"&gt;   &lt;h2&gt;Getting the accelerometer’s values from JavaScript&lt;/h2&gt; &lt;/a&gt;  &lt;p&gt;We’re going to see here how to get the values sent back by the accelerometer (of the emulator or the real device) in a very simple way.&lt;/p&gt;  &lt;p&gt;Open the “&lt;strong&gt;&lt;em&gt;index.html&lt;/em&gt;&lt;/strong&gt;” page and change its default body by this one:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;h1&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Accelerometer sample&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;h1&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;valueX&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;valueY&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;valueZ&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;We will simply use 3 &amp;lt;div&amp;gt; tags to display the current X, Y &amp;amp; Z values of the accelerometer. &lt;/p&gt;

&lt;p&gt;Next step is to change the last default &amp;lt;script&amp;gt; block by this one:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;script &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;
    &lt;/span&gt;document.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;deviceready&amp;quot;&lt;/span&gt;, onDeviceReady, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

    &lt;span style="color: #006400"&gt;// variable to output the current x, y &amp;amp; z values of the accelerometer
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;valueX;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;valueY;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;valueZ;

    &lt;span style="color: #006400"&gt;// when PhoneGap tells us everything is ready, start watching the accelerometer
    &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;onDeviceReady() {
        valueX = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;valueX&amp;quot;&lt;/span&gt;);
        valueY = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;valueY&amp;quot;&lt;/span&gt;);
        valueZ = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;valueZ&amp;quot;&lt;/span&gt;);
        startWatch();
    }

    &lt;span style="color: #006400"&gt;// start monitoring the state of the accelerometer
    &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;startWatch() {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;options = { frequency: 500 };
        navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
    }

    &lt;span style="color: #006400"&gt;// if the z-axis has moved outside of our sensitivity threshold, move the aarvark's head in the appropriate direction
    &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;onSuccess(acceleration) {
        valueX.innerHTML = &lt;span style="color: maroon"&gt;&amp;quot;X: &amp;quot; &lt;/span&gt;+ acceleration.x;
        valueY.innerHTML = &lt;span style="color: maroon"&gt;&amp;quot;Y: &amp;quot; &lt;/span&gt;+ acceleration.y;
        valueZ.innerHTML = &lt;span style="color: maroon"&gt;&amp;quot;Z: &amp;quot; &lt;/span&gt;+ acceleration.z;
    }

    &lt;span style="color: blue"&gt;function &lt;/span&gt;onError() {
        alert(&lt;span style="color: maroon"&gt;'onError!'&lt;/span&gt;);
    }
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Well the code is relatively self-explicit I think. The very first thing to note is that you need to wait for the “&lt;strong&gt;&lt;em&gt;deviceready&lt;/em&gt;&lt;/strong&gt;” event raised by PhoneGap to be sure to be in a stable state. You then need to subscribe to this event. In our case, we will be call-backed into the &lt;em&gt;OnDeviceReady() &lt;/em&gt;function. This function is getting the references to the 3 &amp;lt;div&amp;gt; tags and then asks to be notified by any changes done inside the accelerometer every 500ms with the &lt;em&gt;startWatch() &lt;/em&gt;function. The notifications will be sent to the &lt;em&gt;onSuccess() &lt;/em&gt;function that will have access to the &lt;em&gt;acceleration &lt;/em&gt;object containing the x, y &amp;amp; z values. You’ll find the complete documentation on the PhoneGap site: &lt;a title="http://docs.phonegap.com/en/1.2.0/phonegap_accelerometer_accelerometer.md.html#Accelerometer" href="http://docs.phonegap.com/en/1.2.0/phonegap_accelerometer_accelerometer.md.html#Accelerometer"&gt;PhoneGap Documentation - API Reference - Accelerometer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is all you need to do on the JavaScript side. However, to make it works, you need to specify in the project’s properties that &lt;strong&gt;you want to request access to the device’s sensor&lt;/strong&gt;. The capabilities needed for the proper execution of our application are listed inside the &lt;strong&gt;&lt;em&gt;WMAppManifest.xml&lt;/em&gt; &lt;/strong&gt;file available in the “&lt;em&gt;Properties&lt;/em&gt;” directory. By default, since 1.3.0, PhoneGap is listing the strict minimum capabilities: &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capabilities&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capability &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID_CAP_IDENTITY_DEVICE&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capability &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID_CAP_IDENTITY_USER&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capability &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID_CAP_LOCATION&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capability &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID_CAP_NETWORKING&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capability &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID_CAP_WEBBROWSERCOMPONENT&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capabilities&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;It’s then up to you to add the capabilities you need for your PhoneGap application. In our case, we need to add this line:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capability &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID_CAP_SENSORS&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;To be allowed to access to the accelerometer. You’ll find the complete list of all available capabilities here:&amp;#160; &lt;a title="http://msdn.microsoft.com/en-us/library/ff769509(v=VS.92).aspx#BKMK_Capabilities" href="http://msdn.microsoft.com/en-us/library/ff769509(v=VS.92).aspx#BKMK_Capabilities"&gt;Application Manifest File for Windows Phone&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, we’re logically ready to test that inside the emulator as a first phase. Press on the magical “F5” key and let’s have a look to the result:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3060.image_5F00_5BAEC277.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6746.image_5F00_thumb_5F00_0439B65A.png" width="640" height="386" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By moving the virtual phone in the emulator on the right, you should see the values of the accelerometer updated. Congratulations!&lt;/p&gt;

&lt;p&gt;You can &lt;strong&gt;download the complete source code of this first solution here&lt;/strong&gt;: &lt;a title="http://david.blob.core.windows.net/html5/MyFirstPhoneGapProject.zip" href="http://david.blob.core.windows.net/html5/MyFirstPhoneGapProject.zip"&gt;http://david.blob.core.windows.net/html5/MyFirstPhoneGapProject.zip&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Issues with phones using French locale&lt;/h3&gt;

&lt;p&gt;If you’re testing the very same code on your phone configured to use a French local (as mine for instance! &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0020.wlEmoticon_2D00_winkingsmile_5F00_53225FA2.png" /&gt;), you will have the feeling that the application doesn’t work at all…which is indeed the case. I’ve then spent some time debugging the code and I’ve discovered that the following exception was raised inside &lt;em&gt;phonegap-1.3.0.js&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;font color="#800000"&gt;&amp;quot;Error in success callback: Accelerometer = Syntax error&amp;quot;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;After dumping the values, I’ve seen that the error was due to a tentative of de-serialization of the following bad formatted JSON string:&lt;/p&gt;

&lt;p&gt;&lt;font color="#800000"&gt;&lt;strong&gt;&amp;quot;{\&amp;quot;x\&amp;quot;:0,00472,\&amp;quot;y\&amp;quot;:-0,19879,\&amp;quot;z\&amp;quot;:-0,98115}&amp;quot;&lt;/strong&gt;&lt;/font&gt; whereas the proper EN-US is the following one: &lt;font color="#008000"&gt;&lt;strong&gt;&amp;quot;{\&amp;quot;x\&amp;quot;:0.00472,\&amp;quot;y\&amp;quot;:-0.19879,\&amp;quot;z\&amp;quot;:-0.98115}&amp;quot;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;Yes, we’re using a coma in France as a numeric separator. &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0020.wlEmoticon_2D00_winkingsmile_5F00_53225FA2.png" /&gt;&lt;/p&gt;

&lt;p&gt;2 solutions to solve this problem:&lt;/p&gt;

&lt;p&gt;1 – The lazy one: switch your phone into EN-US (I know, this is not a solution!) 
  &lt;br /&gt;2 – Fix the problem that comes from the C# code. For that, replace the following code from the &lt;em&gt;Accelometer.cs&lt;/em&gt; file of the &lt;em&gt;WP7GalClassLib&lt;/em&gt; library:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color: green"&gt;Formats current coordinates into JSON format
&lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;Coordinates in JSON format&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;private string &lt;/span&gt;GetCurrentAccelerationFormatted()
{
    &lt;span style="color: blue"&gt;string &lt;/span&gt;resultCoordinates = &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;\&amp;quot;x\&amp;quot;:{0},\&amp;quot;y\&amp;quot;:{1},\&amp;quot;z\&amp;quot;:{2}&amp;quot;&lt;/span&gt;,
                    accelerometer.CurrentValue.Acceleration.X.ToString(&lt;span style="color: #a31515"&gt;&amp;quot;0.00000&amp;quot;&lt;/span&gt;),
                    accelerometer.CurrentValue.Acceleration.Y.ToString(&lt;span style="color: #a31515"&gt;&amp;quot;0.00000&amp;quot;&lt;/span&gt;),
                    accelerometer.CurrentValue.Acceleration.Z.ToString(&lt;span style="color: #a31515"&gt;&amp;quot;0.00000&amp;quot;&lt;/span&gt;));
    resultCoordinates = &lt;span style="color: #a31515"&gt;&amp;quot;{&amp;quot; &lt;/span&gt;+ resultCoordinates + &lt;span style="color: #a31515"&gt;&amp;quot;}&amp;quot;&lt;/span&gt;;
    &lt;span style="color: blue"&gt;return &lt;/span&gt;resultCoordinates;
}&lt;/pre&gt;

&lt;p&gt;By this one:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private string &lt;/span&gt;GetCurrentAccelerationFormatted()
{
    &lt;span style="color: blue"&gt;string &lt;/span&gt;resultCoordinates = &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;\&amp;quot;x\&amp;quot;:{0},\&amp;quot;y\&amp;quot;:{1},\&amp;quot;z\&amp;quot;:{2}&amp;quot;&lt;/span&gt;,
             accelerometer.CurrentValue.Acceleration.X.ToString(&lt;span style="color: #a31515"&gt;&amp;quot;0.00000&amp;quot;&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture),
             accelerometer.CurrentValue.Acceleration.Y.ToString(&lt;span style="color: #a31515"&gt;&amp;quot;0.00000&amp;quot;&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture),
             accelerometer.CurrentValue.Acceleration.Z.ToString(&lt;span style="color: #a31515"&gt;&amp;quot;0.00000&amp;quot;&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture));
    resultCoordinates = &lt;span style="color: #a31515"&gt;&amp;quot;{&amp;quot; &lt;/span&gt;+ resultCoordinates + &lt;span style="color: #a31515"&gt;&amp;quot;}&amp;quot;&lt;/span&gt;;
    &lt;span style="color: blue"&gt;return &lt;/span&gt;resultCoordinates;
}&lt;/pre&gt;

&lt;p&gt;And the sample will now work with all locales. I’ve filled a bug on this topic here: &lt;a title="https://issues.apache.org/jira/browse/CB-141" href="https://issues.apache.org/jira/browse/CB-141"&gt;https://issues.apache.org/jira/browse/CB-141&lt;/a&gt; suggesting the same solution that will normally be shipped with the next version (2.0.0).&lt;/p&gt;

&lt;p&gt;By the way, you’re maybe wondering how I’ve managed to debug the JavaScript part of my PhoneGap project? Well, you can simply use the wonderful &lt;strong&gt;jsConsole&lt;/strong&gt; project. If you want to know more about that, please read one of my colleague’s article: &lt;a title="http://bristowe.com/blog/2011/6/8/jsconsole-remote-debugging-in-ie9-on-windows-phone-mango.html" href="http://bristowe.com/blog/2011/6/8/jsconsole-remote-debugging-in-ie9-on-windows-phone-mango.html"&gt;jsConsole Remote Debugging in IE9 on Windows Phone Mango&lt;/a&gt;&lt;/p&gt;
&lt;a name="html5platformer"&gt;
  &lt;h2&gt;Review of a complete sample with the HTML5 Platformer game&lt;/h2&gt;
&lt;/a&gt;

&lt;p&gt;Let’s now review a more complex sample. My idea was to start from the game I’ve written before. It’s exposed in this article: &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx"&gt;HTML5 Platformer: the complete port of the XNA game to &amp;lt;canvas&amp;gt; with EaselJS&lt;/a&gt; . I wanted to see what I should do to make it works on the phone. &lt;/p&gt;

&lt;p&gt;First step is to simply copy/paste the different .js, .png, .css files into the “www” directory and to mark them as “&lt;strong&gt;Content&lt;/strong&gt;”. Here are the others steps to follow.&lt;/p&gt;

&lt;h3&gt;Forcing the landscape orientation&lt;/h3&gt;

&lt;h3&gt;&lt;/h3&gt;

&lt;p&gt;The game has to be played in landscape mode. I’ve then forced this orientation. I’ve also remove the information bar on the side (the System Tray). For that, you need to open the &lt;strong&gt;&lt;em&gt;MainPage.xaml&lt;/em&gt;&lt;/strong&gt; file and change these properties:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: red"&gt;SupportedOrientations&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Landscape&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Orientation&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Landscape&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;shell&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;SystemTray.IsVisible&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot;
&lt;/span&gt;&lt;/pre&gt;

&lt;h3&gt;Handling various resolutions&lt;/h3&gt;

&lt;p&gt;As my main goal was to build a game that could run on the highest number of devices, I need to handle a lot of different resolutions.&lt;/p&gt;

&lt;p&gt;For that, I’ve slightly modified the initial code of the Platformer you can download in the &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx"&gt;other article&lt;/a&gt;. The game is now capable on running at any resolution by applying a rescale ratio on the images and sprites to draw. Everything is being redrawn based on a specific ratio that came from the Windows Phone (800x480) which is the 100% ratio. You can test this version in your desktop browser here: &lt;a title="http://david.blob.core.windows.net/html5platformerscale/index.html" href="http://david.blob.core.windows.net/html5platformerscale/index.html"&gt;HTML5 Platformer ReScale&lt;/a&gt; and try to dynamically resize the browser window. Moreover, if your screen resolution has a 16/9 aspect ratio, press the F11 key to play in fullscreen! The experience in this mode is really cool as you can see in this screenshot:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://david.blob.core.windows.net/html5platformerscale/index.html"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5125.image_5F00_255E17C3.png" width="640" height="360" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’re letting the browser taking care of the anti-aliasing during this scaling operation. Based on the browser you’ll use, you will notice also that the performance could vary a lot related to the size of the window you’ll have. On my machine, IE9/IE10 seems relatively indifferent to the fullscreen mode or small resolutions by maintaining a stable 60 fps framerate. &lt;/p&gt;

&lt;h3&gt;Loading the levels with calls to the file system instead of using XHR&lt;/h3&gt;

&lt;p&gt;In the initial code, the .TXT files linked to the each level were stored on the web server and downloaded via XmlHttpRequest calls. As we’re now running everything client-side in offline mode, XHR local calls are not very appropriated. I’ve then replaced the initial code of the &lt;em&gt;PlatformerGame.prototype.LoadNextLevel &lt;/em&gt;function by this one:&lt;/p&gt;

&lt;pre class="code"&gt;PlatformerGame.prototype.LoadNextLevel = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.levelIndex = (&lt;span style="color: blue"&gt;this&lt;/span&gt;.levelIndex + 1) % numberOfLevels;

    &lt;span style="color: #006400"&gt;// Searching where we are currently hosted
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;nextFileName = &lt;span style="color: maroon"&gt;&amp;quot;app/www/assets/levels/&amp;quot; &lt;/span&gt;+ &lt;span style="color: blue"&gt;this&lt;/span&gt;.levelIndex + &lt;span style="color: maroon"&gt;&amp;quot;.txt&amp;quot;&lt;/span&gt;;
    &lt;span style="color: blue"&gt;try &lt;/span&gt;{
        &lt;span style="color: blue"&gt;var &lt;/span&gt;instance = &lt;span style="color: blue"&gt;this&lt;/span&gt;;
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);

        &lt;span style="color: blue"&gt;function &lt;/span&gt;gotFS(fileSystem) {
            fileSystem.root.getFile(nextFileName, &lt;span style="color: blue"&gt;null&lt;/span&gt;, gotFileEntry, fail);
        }

        &lt;span style="color: blue"&gt;function &lt;/span&gt;gotFileEntry(fileEntry) {
            fileEntry.file(gotFile, fail);
        }

        &lt;span style="color: blue"&gt;function &lt;/span&gt;gotFile(file) {
            readAsText(file);
        }

        &lt;span style="color: blue"&gt;function &lt;/span&gt;readAsText(file) {
            &lt;span style="color: blue"&gt;var &lt;/span&gt;reader = &lt;span style="color: blue"&gt;new &lt;/span&gt;FileReader();
            reader.onloadend = &lt;span style="color: blue"&gt;function &lt;/span&gt;(evt) {
                instance.LoadThisTextLevel(evt.target.result.replace(/[\n\r\t]/g, &lt;span style="color: maroon"&gt;''&lt;/span&gt;));
            };
            reader.readAsText(file);
        }

        &lt;span style="color: blue"&gt;function &lt;/span&gt;fail(evt) {
            console.log(evt.target.error.code);
        }
    }
    &lt;span style="color: blue"&gt;catch &lt;/span&gt;(e) {
        console.log(&lt;span style="color: maroon"&gt;&amp;quot;Error loading level: &amp;quot; &lt;/span&gt;+ e.message);
        &lt;span style="color: #006400"&gt;// Probably an access denied if you try to run from the file:// context
        // Loading the hard coded error level to have at least something to play with
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.LoadThisTextLevel(hardcodedErrorTextLevel);
    }
};&lt;/pre&gt;

&lt;p&gt;I’ve just re-used the code available in the PhoneGap documentation: &lt;a title="http://docs.phonegap.com/en/1.3.0/phonegap_file_file.md.html#FileReader" href="http://docs.phonegap.com/en/1.3.0/phonegap_file_file.md.html#FileReader"&gt;FileReader&lt;/a&gt; . As you can see, you have a full access to the Windows Phone file system from JavaScript with PhoneGap.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Cool tip:&lt;/u&gt;&lt;/strong&gt; to help you debugging what’s really stored in the Isolated Storage of the phone or not, you should have a look to this awesome tool: &lt;a title="http://isostorespy.codeplex.com/" href="http://isostorespy.codeplex.com/"&gt;IsoStoreSpy&lt;/a&gt; written by Samuel Blanchard. &lt;/p&gt;

&lt;h3&gt;Modification of the gameplay to use the accelerometer&lt;/h3&gt;

&lt;p&gt;Well, last part is just to mix all parts of this article to obtain the final result. For that, I’ve added the following code into the constructor of the &lt;em&gt;Player&lt;/em&gt; object in the &lt;em&gt;Player.js&lt;/em&gt; file:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;options = { frequency: 500 };
&lt;span style="color: blue"&gt;var &lt;/span&gt;that = &lt;span style="color: blue"&gt;this&lt;/span&gt;;

navigator.accelerometer.watchAcceleration(
    &lt;span style="color: blue"&gt;function &lt;/span&gt;(accelerometer) { that.moveDirectionAccel(accelerometer); },
    &lt;span style="color: blue"&gt;function &lt;/span&gt;() { console.log(&lt;span style="color: maroon"&gt;&amp;quot;Error with accelerometer&amp;quot;&lt;/span&gt;); }, 
    options);&lt;/pre&gt;

&lt;p&gt;Here is the function that will be call-backed during the accelerometer variations:&lt;/p&gt;

&lt;pre class="code"&gt;Player.prototype.moveDirectionAccel = &lt;span style="color: blue"&gt;function&lt;/span&gt;(acceleration) {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;accelValue = -acceleration.y;

    &lt;span style="color: #006400"&gt;// Move the player with accelerometer
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(Math.abs(accelValue) &amp;gt; 0.15) {
        &lt;span style="color: #006400"&gt;// set our movement speed
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.direction = Math.clamp(accelValue * &lt;span style="color: blue"&gt;this&lt;/span&gt;.AccelerometerScale, -1, 1);
    }
    &lt;span style="color: blue"&gt;else &lt;/span&gt;{
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.direction = 0;
    }
};&lt;/pre&gt;

&lt;p&gt;I’ve also added an handler on the “&lt;em&gt;&lt;strong&gt;onmousedown&lt;/strong&gt;&lt;/em&gt;” event on the canvas to jump when the user tap on the screen.&lt;/p&gt;

&lt;h3&gt;Screenshots of the result and FPS on some phones&lt;/h3&gt;

&lt;p&gt;First, let’s review the result within the Windows Phone emulator:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0804.image_5F00_313B39E9.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7652.image_5F00_thumb_5F00_2F865A16.png" width="644" height="309" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have a framerate varying from 54 to 60 fps on my machine. On a real device, the framerate differs logically between models. Let’s take the first game level. On the &lt;strong&gt;LG E900&lt;/strong&gt;, the framerate is around &lt;strong&gt;22 fps&lt;/strong&gt;. On the &lt;strong&gt;&lt;font color="#800080"&gt;HTC Radar&lt;/font&gt;&lt;/strong&gt;, it’s around &lt;font color="#800080"&gt;&lt;strong&gt;31 fps&lt;/strong&gt;&lt;/font&gt;&lt;font color="#000000"&gt;. On the &lt;strong&gt;&lt;font color="#004080"&gt;Nokia Lumia 800&lt;/font&gt;&lt;/strong&gt;, it’s around &lt;strong&gt;&lt;font color="#004080"&gt;42 fps&lt;/font&gt;&lt;/strong&gt;.&lt;/font&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7824.DSCF4677_5F00_34684C2B.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="DSCF4677" border="0" alt="DSCF4677" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6648.DSCF4677_5F00_thumb_5F00_34F0B6BB.jpg" width="404" height="392" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The gameplay could then be not very convincing in most cases. Indeed, I’m using a fullscreen canvas to draw the whole game. This is not a very good idea for the mobile limited power CPU, even if the Nokia seems powerful enough to handle this approach. A better methodology could be to cut the screen stage into various little canvas that will then be moved by modifying the CSS properties on them. This is what has been done for the HTML5 version of Angry Birds for instance. Some JS gaming frameworks start to think about handling this complexity for you. The idea would then be to code the game once with high level APIs and the framework could switch between a full frame canvas or various little canvas moved via CSS based on the performance. &lt;/p&gt;

&lt;p&gt;Well, you’ll get it: the HTML5 gaming experience on mobile is currently just at its beginning. But its future looks very promising!&lt;/p&gt;

&lt;h3&gt;Complete Visual Studio Solution to download&lt;/h3&gt;

&lt;p&gt;You’ll find the &lt;strong&gt;complete source code of the HTML5 Platformer for PhoneGap here&lt;/strong&gt;: &lt;a title="http://david.blob.core.windows.net/html5/HTML5GapPlatformer.zip" href="http://david.blob.core.windows.net/html5/HTML5GapPlatformer.zip"&gt;HTML5GapPlatformer.zip&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Other useful resources &lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a title="http://blogs.technet.com/b/port25/archive/2011/12/19/full-support-for-phonegap-on-windows-phone-is-now-complete.aspx" href="http://blogs.technet.com/b/port25/archive/2011/12/19/full-support-for-phonegap-on-windows-phone-is-now-complete.aspx"&gt;Full Support for PhoneGap on Windows Phone is Now Complete!&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a title="http://blogs.msdn.com/b/glengordon/archive/2011/11/15/phonegap-on-windows-phone-tips.aspx" href="http://blogs.msdn.com/b/glengordon/archive/2011/11/15/phonegap-on-windows-phone-tips.aspx"&gt;PhoneGap on Windows Phone Tips&lt;/a&gt; from Glen Gardon who has written several very interesting tutorials to follow &lt;/li&gt;

  &lt;li&gt;Lot of good tutorials in the Wiki section of PhoneGap: &lt;a title="http://wiki.phonegap.com/w/page/35501397/Tutorials" href="http://wiki.phonegap.com/w/page/35501397/Tutorials"&gt;http://wiki.phonegap.com/w/page/35501397/Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;a name="conclusion"&gt;
  &lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;/a&gt;

&lt;p&gt;PhoneGap offers interesting perspectives to help you writing applications on the phone. It lets you using your existing skills in JavaScript, HTML and CSS. PhoneGap won’t necessary cover all the scenarios currently available with the native development stack (Silverlight or XNA). But this could be something to have a look to if you’d like to capitalize on the HTML skills of one of your team. You will have to pay attention to properly identify the kind of project to work on.&lt;/p&gt;

&lt;p&gt;You can also think about mixing both environments to create hybrid experiences: the main branch would be written using “HTML5” and some specific parts into native code. Using this idea, some plug-ins have been created to push a bit further the integration into the Metro UI: &lt;a title="https://github.com/purplecabbage/phonegap-plugins/tree/master/WindowsPhone" href="https://github.com/purplecabbage/phonegap-plugins/tree/master/WindowsPhone"&gt;PhoneGap Plug-ins for Windows Phone&lt;/a&gt; . You’ll find for instance one of them allowing a JavaScript code to update the Tiles.&lt;/p&gt;

&lt;p&gt;At last, PhoneGap and HTML5 could allow a relative portability to other platforms… with some limitations. But this is a vast subject with passionate debates that would need a complete dedicated article. &lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250721" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Internet+Explorer+9/">Internet Explorer 9</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Windows+Phone+7/">Windows Phone 7</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Platformer/">Platformer</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/EaselJS/">EaselJS</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/PhoneGap/">PhoneGap</category></item><item><title>Tutorial: créez des applications avec HTML5 sur Windows Phone grâce à PhoneGap</title><link>http://blogs.msdn.com/b/davrous/archive/2011/12/23/tutorial-cr-233-ez-des-applications-avec-html5-sur-windows-phone-gr-226-ce-224-phonegap.aspx</link><pubDate>Fri, 23 Dec 2011 13:45:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10250681</guid><dc:creator>David Rousset</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10250681</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2011/12/23/tutorial-cr-233-ez-des-applications-avec-html5-sur-windows-phone-gr-226-ce-224-phonegap.aspx#comments</comments><description>&lt;p&gt;Tout d’abord, nous allons naturellement commencer par voir l’intérêt d’utiliser PhoneGap pour HTML5. Ensuite, nous verrons comment créer son tout 1er projet et récupérer les valeurs de l’accéléromètre en JavaScript. Pour finir, nous allons voir un exemple complet où j’ai repris le code de mon jeu HTML5 Platformer pour le faire fonctionner presque tel quel avec l’accéléromètre d’un Windows Phone.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="#introduction"&gt;Introduction&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#phonegap"&gt;PhoneGap : un framework qui comble les manques&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#firstproject"&gt;Création de son 1er projet PhoneGap sur Windows Phone&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#accelero"&gt;Récupération des valeurs de l’accéléromètre&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#html5platformer"&gt;Exemple complet avec le jeu HTML5 Platformer&lt;/a&gt;       &lt;ol&gt;       &lt;li&gt;Forcer le mode paysage &lt;/li&gt;        &lt;li&gt;Adapter le code pour gérer plusieurs résolutions &lt;/li&gt;        &lt;li&gt;Chargement des niveaux via l’appel au système de fichiers plutôt que XHR &lt;/li&gt;        &lt;li&gt;Modification du gameplay pour gérer l’accéléromètre &lt;/li&gt;        &lt;li&gt;Le résultat en images avec quelques FPS sur les téléphones &lt;/li&gt;        &lt;li&gt;Solution complète à télécharger &lt;/li&gt;     &lt;/ol&gt;   &lt;/li&gt;    &lt;li&gt;&lt;a href="#conclusion"&gt;Conclusion&lt;/a&gt; &lt;/li&gt; &lt;/ol&gt; &lt;a name="introduction"&gt;   &lt;h2&gt;Introduction&lt;/h2&gt; &lt;/a&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1651.image_5F00_679E8583.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 10px 10px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="left" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1541.image_5F00_thumb_5F00_05306083.png" width="132" height="240" /&gt;&lt;/a&gt;La mise à jour Mango sur Windows Phone a apporté &lt;strong&gt;le support d’HTML5 via l’arrivée du navigateur IE9&lt;/strong&gt;. Tout comme sur la version bureau, la version mobile d’IE9 met en place l’accélération matérielle via l’utilisation du GPU embarqué sur votre Windows Phone. Ainsi, couplé à JavaScript, IE9 permet d’envisager la réalisation d’expériences utilisateurs intéressantes autre fois uniquement réservées aux applications dites “natives”. &lt;/p&gt;  &lt;p&gt;L’avantage d’utiliser HTML5 comme plateforme de développement est qu’elle permet une facilité “relative” dans la réutilisation d’une partie du code sur d’autres plateformes comme Android ou iOS. HTML5 suscite donc énormément d’intérêt de l’écosystème ces derniers temps pour les plateformes mobiles. Parfois malheureusement à tord mais j’y reviendrais surement dans un autre billet.&lt;/p&gt;  &lt;p&gt;Cependant, bien que les spécifications HTML5/CSS3/SVG et JavaScript aient nettement évoluées ces derniers mois, il existe des &lt;strong&gt;manques majeurs pour la réalisation d’applications mobiles&lt;/strong&gt;. En effet, un téléphone ou une tablette dispose de capacités spécifiques à leur mobilité : GPS, accéléromètre, caméra, SMS, accès aux contacts, etc. &lt;/p&gt;  &lt;p&gt;Pour accéder à ces spécificités matérielles depuis son code JavaScript, le W3C travaille depuis un moment sur ce que nous appelons les “&lt;a href="http://www.w3.org/2009/dap/"&gt;Device APIs&lt;/a&gt;” ou &lt;strong&gt;DAP&lt;/strong&gt;. Malheureusement, on peut considérer qu’il n’existe à l’heure actuelle aucune implémentation de ces spécifications sur le marché comme le confirme ce document : &lt;a title="http://www.w3.org/2011/11/mobile-web-app-state.html" href="http://www.w3.org/2011/11/mobile-web-app-state.html"&gt;Standards for Web Applications on Mobile: November 2011 current state and roadmap&lt;/a&gt; . Mozilla a commencé un travail intéressant sur une forme de fork de ces spécifications nommées &lt;a href="http://hacks.mozilla.org/2011/08/introducing-webapi/"&gt;Web APIs&lt;/a&gt; pour soutenir son projet &lt;a href="http://hacks.mozilla.org/2011/07/announcing-boot-to-gecko-b2g-booting-to-the-web/"&gt;Boot To Gecko&lt;/a&gt;. C’est donc une bonne nouvelle dans la mesure où une forme d’implémentation commence à voir le jour et un dialogue avec le W3C semble s’installer. Les choses commencent doucement à bouger mais il faudra probablement plusieurs années avant de voir une spécification du W3C implémentée et répandue sur toutes les plateformes. &lt;/p&gt;  &lt;p&gt;Alors comment faire en attendant ? HTML5 peut-il vraiment adresser ce scénario ?&lt;/p&gt; &lt;a name="phonegap"&gt;   &lt;h2&gt;PhoneGap : un framework qui comble les manques&lt;/h2&gt; &lt;/a&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 10px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" align="right" src="http://phonegap.com/assets/artwork/Build-Diagram-2.png" width="300" height="225" /&gt;&lt;/p&gt;  &lt;p&gt;En attendant l’arrivée de réelles spécifications standardisées, nous n’avons donc pas le choix : il faut créer &lt;strong&gt;un pont entre le code JavaScript et le code natif&lt;/strong&gt; de la plateforme visée pour accéder au matériel. L’idée est donc la suivante : on prend le langage natif de chacune des plateformes (Silverlight, Objective-C et Java) et on en créé un framework qui expose des interfaces pour le développeur JavaScript. &lt;/p&gt;  &lt;p&gt;C’est exactement ce que fait &lt;a href="http://phonegap.com/"&gt;PhoneGap&lt;/a&gt;. Prenons le cas de Windows Phone qui nous intéresse dans cet article. Un projet PhoneGap expose tout simplement une application Silverlight hébergeant le contrôle WebBrowser (et donc IE9) ainsi qu’une DLL écrite en C# s’occupant d’accéder à l’accéléromètre, au GPS, aux contacts, à la caméra, etc. Ainsi, comme on va le voir un peu plus tard, en tant que développeur JavaScript, vous allez donc utiliser indirectement une DLL nommée &lt;strong&gt;WP7GapClassLib.dll&lt;/strong&gt; (le coeur de PhoneGap) à travers le code exposé dans le fichier &lt;strong&gt;phonegap-1.3.0.js&lt;/strong&gt;. La DLL contient le code C# qui fait appel au runtime Silverlight présent sur le téléphone. Ce dernier peut accéder à l’accéléromètre et au reste du téléphone. La librairie JavaScript contenu dans le .js va faire office d’interface entre les 2 mondes. L’avantage de faire appel à cette librairie est que le code JavaScript que vous allez écrire pour accéder à la caméra du Windows Phone par exemple marchera tel quel sur PhoneGap pour Android ou iOS. PhoneGap offre donc une certaine forme de portabilité. &lt;/p&gt;  &lt;p&gt;Sachez d’ailleurs qu’à ce sujet, le support de PhoneGap pour Windows Phone est désormais aussi complet que sur Android ou iOS depuis la récente version 1.3 :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-86-46/1362.PhoneGap.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-86-46/1362.PhoneGap.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Pour finir, PhoneGap vous fournit également un autre service intéressant. Il vous permet d’inclure vos fichiers JS, CSS, HTML, PNG &amp;amp; co au sein de son projet pour packager l’ensemble comme une véritable application native. En résumé, vous pouvez donc tout à fait utiliser PhoneGap pour packager une application HTML5 que vous déploierez sur le Store. C’est le cas par exemple de &lt;a href="http://www.windowsphone.com/en-US/apps/09dc9317-0f63-4a98-9042-47c7976b2d88"&gt;l’application SujiQ&lt;/a&gt; qui a été conçue ainsi.&lt;/p&gt; &lt;a name="firstproject"&gt;   &lt;h2&gt;Création de son 1er projet PhoneGap sur Windows Phone&lt;/h2&gt; &lt;/a&gt;  &lt;h3&gt;Pré-requis&lt;/h3&gt;  &lt;p&gt;Voici les étapes à suivre avant toute chose :&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Téléchargez le SDK Windows Phone si ce n’est déjà fait ici : &lt;a href="http://aka.ms/hp-windows-phone"&gt;Télécharger le SDK Windows Phone&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Téléchargez la dernière version (1.3 aujourd’hui) de PhoneGap sur leur site : &lt;a title="http://phonegap.com/" href="http://phonegap.com/"&gt;http://phonegap.com/&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Décompressez l’archive téléchargée depuis le site de PhoneGap &lt;/li&gt;    &lt;li&gt;Copiez les fichiers &lt;strong&gt;PhoneGapStarter.zip &lt;/strong&gt;et&lt;strong&gt; PhoneGapCustom.zip&lt;/strong&gt; dans &lt;font color="#008000"&gt;&lt;strong&gt;\Documents\Visual Studio 2010\Templates\ProjectTemplates&lt;/strong&gt;&lt;/font&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;Nouveau projet&lt;/h3&gt;  &lt;p&gt;Une fois toutes ces étapes suivies correctement, nous allons pouvoir créer notre 1er projet PhoneGap. Pour cela, démarrez Visual Studio 2010, rendez-vous dans la partie “Visual C#”, filtrez sur le mot clé “Gap” et vous devriez voir un nouveau type de projet nommé &lt;strong&gt;PhoneGapStarter&lt;/strong&gt; :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0753.image_5F00_02DA64DA.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7041.image_5F00_thumb_5F00_3B45395A.png" width="640" height="452" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Nommez le projet “&lt;em&gt;MonPremierProjetPhoneGap&lt;/em&gt;”. Une fois créé, vous allez retrouver les fichiers dont je vous parlais avant dans l’explorateur de solution :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6557.image_5F00_45A5C1E0.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8032.image_5F00_thumb_5F00_74A7FDB7.png" width="250" height="353" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Vous n’avez donc plus qu’à insérer votre application HTML5 dans le répertoire “www”. &lt;/p&gt;  &lt;p&gt;Au passage, j’ai plusieurs conseils à vous fournir au sujet de ce projet par défaut :&lt;/p&gt;  &lt;p&gt;- &lt;strong&gt;ne touchez jamais au fichier &lt;em&gt;phonegap-1.3.0.js&lt;/em&gt;&lt;/strong&gt; si vous souhaitez garder un code portable sur les autres versions de Phone Gap     &lt;br /&gt;- tous les fichiers que vous rajouterez dans le répertoire “www” devront être marqué en tant que “&lt;strong&gt;Content&lt;/strong&gt;” dans leurs propriétés&amp;#160; &lt;br /&gt;- à la place du binaire &lt;em&gt;WP7GapClassLib.dll&lt;/em&gt;,vous pouvez référencer le projet C# &lt;em&gt;WP7GapClassLib.csproj&lt;/em&gt; contenu dans le répertoire “&lt;em&gt;Windows Phone\framework&lt;/em&gt;” de l’archive PhoneGap téléchargée. Cela vous permettra de débugger ou parcourir le code de la librairie PhoneGap si besoin.&lt;/p&gt;  &lt;p&gt;Allez, commençons par effectuer une action normalement impossible par défaut sous IE9 Mango : récupérer les valeurs de l’accéléromètre en JavaScript.&lt;/p&gt; &lt;a name="accelero"&gt;   &lt;h2&gt;Récupération des valeurs de l’accéléromètre&lt;/h2&gt; &lt;/a&gt;  &lt;p&gt;Nous allons voir comment, de manière très simple, récupérer les valeurs renvoyées par l’accéléromètre (de l’émulateur ou du vrai périphérique). &lt;/p&gt;  &lt;p&gt;Rendez-vous dans “&lt;em&gt;&lt;strong&gt;index.html&lt;/strong&gt;&lt;/em&gt;” et changer le contenu du body par défaut par celui-ci :&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;h1&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Démo accéléromètre&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;h1&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;valueX&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;valueY&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;valueZ&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;On va simplement utiliser 3 &amp;lt;div&amp;gt; qui afficheront les valeurs courantes X, Y et Z de l’accéléromètre. &lt;/p&gt;

&lt;p&gt;Ensuite, changer le dernier bloc de &amp;lt;script&amp;gt; par celui-ci :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;script &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;
    &lt;/span&gt;document.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;deviceready&amp;quot;&lt;/span&gt;, onDeviceReady, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

    &lt;span style="color: #006400"&gt;// variable to output the current x, y &amp;amp; z values of the accelerometer
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;valueX;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;valueY;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;valueZ;

    &lt;span style="color: #006400"&gt;// when PhoneGap tells us everything is ready, start watching the accelerometer
    &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;onDeviceReady() {
        valueX = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;valueX&amp;quot;&lt;/span&gt;);
        valueY = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;valueY&amp;quot;&lt;/span&gt;);
        valueZ = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;valueZ&amp;quot;&lt;/span&gt;);
        startWatch();
    }

    &lt;span style="color: #006400"&gt;// start monitoring the state of the accelerometer
    &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;startWatch() {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;options = { frequency: 500 };
        navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
    }

    &lt;span style="color: #006400"&gt;// if the z-axis has moved outside of our sensitivity threshold, move the aarvark's head in the appropriate direction
    &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;onSuccess(acceleration) {
        valueX.innerHTML = &lt;span style="color: maroon"&gt;&amp;quot;X: &amp;quot; &lt;/span&gt;+ acceleration.x;
        valueY.innerHTML = &lt;span style="color: maroon"&gt;&amp;quot;Y: &amp;quot; &lt;/span&gt;+ acceleration.y;
        valueZ.innerHTML = &lt;span style="color: maroon"&gt;&amp;quot;Z: &amp;quot; &lt;/span&gt;+ acceleration.z;
    }

    &lt;span style="color: blue"&gt;function &lt;/span&gt;onError() {
        alert(&lt;span style="color: maroon"&gt;'onError!'&lt;/span&gt;);
    }
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Le code est assez simple à lire je pense. Avant toute chose, vous devez attendre que l’évènement “&lt;em&gt;&lt;strong&gt;deviceready&lt;/strong&gt;&lt;/em&gt;” soit levé par PhoneGap pour être de vous retrouver dans un état stable. On commence donc par s’abonner à cet évènement et nous serons rappelé sur la fonction &lt;em&gt;OnDeviceReady()&lt;/em&gt;.Dans celle-ci, on récupère les 3 instances de &amp;lt;div&amp;gt; qui nous intéresse et on demande ensuite à être notifié des changements de l’accéléromètre toutes les 500ms dans la fonction &lt;em&gt;startWatch()&lt;/em&gt;. Si de nouvelles valeurs sont générées, la fonction &lt;em&gt;onSuccess()&lt;/em&gt; sera appelée avec les valeurs x, y et z fournies dans l’object &lt;em&gt;acceleration&lt;/em&gt;. Vous trouverez toute la documentation sur le site de PhoneGap : &lt;a title="http://docs.phonegap.com/en/1.2.0/phonegap_accelerometer_accelerometer.md.html#Accelerometer" href="http://docs.phonegap.com/en/1.2.0/phonegap_accelerometer_accelerometer.md.html#Accelerometer"&gt;PhoneGap Documentation - API Reference - Accelerometer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;C’est tout ce qu’il faut faire du côté code JavaScript. Mais pour que cela fonctionne, il faut indiquer dans les propriétés du projet que l’on a &lt;strong&gt;besoin d’accéder aux capteurs (sensors) de l’appareil&lt;/strong&gt;. La liste des capacités nécessaires au bon fonctionnement de notre application se trouve dans le fichier &lt;strong&gt;&lt;em&gt;WMAppManifest.xml&lt;/em&gt; &lt;/strong&gt;présent dans le répertoire “&lt;em&gt;Properties&lt;/em&gt;”. Par défaut, depuis la version 1.3 de PhoneGap, la liste est limitée au strict nécessaire :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capabilities&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capability &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID_CAP_IDENTITY_DEVICE&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capability &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID_CAP_IDENTITY_USER&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capability &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID_CAP_LOCATION&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capability &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID_CAP_NETWORKING&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capability &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID_CAP_WEBBROWSERCOMPONENT&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capabilities&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;A vous ensuite d’ajouter ce dont vous avez besoin dans votre application PhoneGap. Dans notre cas, ajoutez cette ligne :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Capability &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID_CAP_SENSORS&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Pour pouvoir autoriser l’accès à l’accéléromètre. Vous retrouverez la liste de toutes ces autorisations ici : &lt;a title="http://msdn.microsoft.com/en-us/library/ff769509(v=VS.92).aspx#BKMK_Capabilities" href="http://msdn.microsoft.com/en-us/library/ff769509(v=VS.92).aspx#BKMK_Capabilities"&gt;Application Manifest File for Windows Phone&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bon, on est logiquement prêt à tester tout cela dans l’émulateur dans un 1er temps. Appuyez sur la touche magique “F5” et observons le résultat :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4505.image_5F00_2218E1E5.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7725.image_5F00_thumb_5F00_3C950C97.png" width="640" height="385" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;En faisant tourner le téléphone virtuel dans l’émulateur, vous devriez bien voir les valeurs de l’accéléromètre bouger. Félicitations !&lt;/p&gt;

&lt;p&gt;Vous pouvez &lt;strong&gt;récupérer le code complet de cette solution ici&lt;/strong&gt; : &lt;a title="http://david.blob.core.windows.net/html5/MonPremierProjetPhoneGap.zip" href="http://david.blob.core.windows.net/html5/MonPremierProjetPhoneGap.zip"&gt;http://david.blob.core.windows.net/html5/MonPremierProjetPhoneGap.zip&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Petit problème sur les téléphones configurés en français&lt;/h3&gt;

&lt;p&gt;Si vous testez le même code sur votre téléphone et que vous avez une locale en français, vous aurez l’impression que l’application ne fonctionne pas. En débuggant un peu le code, je me suis aperçu que l’exception suivante était levée dans &lt;em&gt;phonegap-1.3.0.js&lt;/em&gt; :&lt;/p&gt;

&lt;p&gt;&lt;font color="#800000"&gt;&amp;quot;Error in success callback: Accelerometer = Syntax error&amp;quot;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;Et en dumpant les valeurs, je me suis aperçu que l’erreur venait d’une tentative de dé-sérialisation JSON de la chaine suivante : &lt;/p&gt;

&lt;p&gt;&lt;font color="#800000"&gt;&lt;strong&gt;&amp;quot;{\&amp;quot;x\&amp;quot;:0,00472,\&amp;quot;y\&amp;quot;:-0,19879,\&amp;quot;z\&amp;quot;:-0,98115}&amp;quot;&lt;/strong&gt;&lt;/font&gt; au lieu d’avoir celle-ci en EN-US : &lt;font color="#008000"&gt;&lt;strong&gt;&amp;quot;{\&amp;quot;x\&amp;quot;:0.00472,\&amp;quot;y\&amp;quot;:-0.19879,\&amp;quot;z\&amp;quot;:-0.98115}&amp;quot;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;Et oui, notre fameuse virgule de séparation a toujours l’air d’embêter nos chers amis américains… &lt;/p&gt;

&lt;p&gt;2 solutions pour résoudre ce problème :&lt;/p&gt;

&lt;p&gt;1 – Passer votre téléphone en EN-US (oui, je sais, c’est tout pourri comme solution) 
  &lt;br /&gt;2 – Corriger la source du problème dans le code C#. Pour cela, remplacez le code suivant présent dans &lt;em&gt;Accelometer.cs&lt;/em&gt; de la librairie &lt;em&gt;WP7GalClassLib&lt;/em&gt; :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color: green"&gt;Formats current coordinates into JSON format
&lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;Coordinates in JSON format&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;private string &lt;/span&gt;GetCurrentAccelerationFormatted()
{
    &lt;span style="color: blue"&gt;string &lt;/span&gt;resultCoordinates = &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;\&amp;quot;x\&amp;quot;:{0},\&amp;quot;y\&amp;quot;:{1},\&amp;quot;z\&amp;quot;:{2}&amp;quot;&lt;/span&gt;,
                    accelerometer.CurrentValue.Acceleration.X.ToString(&lt;span style="color: #a31515"&gt;&amp;quot;0.00000&amp;quot;&lt;/span&gt;),
                    accelerometer.CurrentValue.Acceleration.Y.ToString(&lt;span style="color: #a31515"&gt;&amp;quot;0.00000&amp;quot;&lt;/span&gt;),
                    accelerometer.CurrentValue.Acceleration.Z.ToString(&lt;span style="color: #a31515"&gt;&amp;quot;0.00000&amp;quot;&lt;/span&gt;));
    resultCoordinates = &lt;span style="color: #a31515"&gt;&amp;quot;{&amp;quot; &lt;/span&gt;+ resultCoordinates + &lt;span style="color: #a31515"&gt;&amp;quot;}&amp;quot;&lt;/span&gt;;
    &lt;span style="color: blue"&gt;return &lt;/span&gt;resultCoordinates;
}&lt;/pre&gt;

&lt;p&gt;Par :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private string &lt;/span&gt;GetCurrentAccelerationFormatted()
{
    &lt;span style="color: blue"&gt;string &lt;/span&gt;resultCoordinates = &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;\&amp;quot;x\&amp;quot;:{0},\&amp;quot;y\&amp;quot;:{1},\&amp;quot;z\&amp;quot;:{2}&amp;quot;&lt;/span&gt;,
             accelerometer.CurrentValue.Acceleration.X.ToString(&lt;span style="color: #a31515"&gt;&amp;quot;0.00000&amp;quot;&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture),
             accelerometer.CurrentValue.Acceleration.Y.ToString(&lt;span style="color: #a31515"&gt;&amp;quot;0.00000&amp;quot;&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture),
             accelerometer.CurrentValue.Acceleration.Z.ToString(&lt;span style="color: #a31515"&gt;&amp;quot;0.00000&amp;quot;&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture));
    resultCoordinates = &lt;span style="color: #a31515"&gt;&amp;quot;{&amp;quot; &lt;/span&gt;+ resultCoordinates + &lt;span style="color: #a31515"&gt;&amp;quot;}&amp;quot;&lt;/span&gt;;
    &lt;span style="color: blue"&gt;return &lt;/span&gt;resultCoordinates;
}&lt;/pre&gt;

&lt;p&gt;Et désormais, l’exemple fonctionnera avec toutes les locales. J’ai ouvert un bug à ce sujet ici: &lt;a title="https://issues.apache.org/jira/browse/CB-141" href="https://issues.apache.org/jira/browse/CB-141"&gt;https://issues.apache.org/jira/browse/CB-141&lt;/a&gt; en proposant la solution ci-dessus qui sera intégrée dans la prochaine version (2.0.0). &lt;/p&gt;

&lt;p&gt;Au passage, pour débugger un projet PhoneGap, vous pouvez très bien utiliser &lt;strong&gt;jsConsole&lt;/strong&gt; et toutes les astuces décrites dans mon article précédent : &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/12/13/testez-et-d-233-buggez-vos-sites-html5-sous-windows-phone-7-avec-l-233-mulateur-gratuit.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/12/13/testez-et-d-233-buggez-vos-sites-html5-sous-windows-phone-7-avec-l-233-mulateur-gratuit.aspx"&gt;Testez et débuggez vos sites HTML5 sous Windows Phone 7 avec l’émulateur gratuit&lt;/a&gt;&lt;/p&gt;
&lt;a name="html5platformer"&gt;
  &lt;h2&gt;Exemple complet avec le jeu HTML5 Platformer&lt;/h2&gt;
&lt;/a&gt;

&lt;p&gt;Pour conclure, essayons de mixer tout cela avec un jeu complet que j’avais réalisé dans l’article précédent : &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-portage-complet-du-jeu-xna-vers-lt-canvas-gt-gr-226-ce-224-easeljs.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-portage-complet-du-jeu-xna-vers-lt-canvas-gt-gr-226-ce-224-easeljs.aspx"&gt;HTML5 Platformer: portage complet du jeu XNA vers &amp;lt;canvas&amp;gt; grâce à EaselJS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voici les étapes que j’ai suivies pour faire fonctionner l’ensemble. La toute première étape consiste simplement à copier/coller les fichiers .js, .png, .css &amp;amp; co dans le répertoire “www” et de bien les marquer comme “&lt;strong&gt;Content&lt;/strong&gt;”. Ensuite, voici les grandes étapes à suivre.&lt;/p&gt;

&lt;h3&gt;Forcer le mode paysage&lt;/h3&gt;

&lt;h3&gt;&lt;/h3&gt;

&lt;p&gt;Tout d’abord, j’ai forcé l’orientation en mode portrait et retiré la barre d’informations qui prend de la place sur le côté (System Tray) en me rendant de le fichier&lt;strong&gt; &lt;em&gt;MainPage.xaml&lt;/em&gt;&lt;/strong&gt; et en changeant ces propriétés :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: red"&gt;SupportedOrientations&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Landscape&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Orientation&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Landscape&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;shell&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;SystemTray.IsVisible&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot;
&lt;/span&gt;&lt;/pre&gt;

&lt;h3&gt;Adapter le code pour gérer plusieurs résolutions&lt;/h3&gt;

&lt;p&gt;Le but étant d’être portable sur le plus grand nombre de périphériques possibles, il faut envisager de dessiner à des résolutions très différentes. &lt;/p&gt;

&lt;p&gt;Pour cela, j’ai légèrement modifié le code initial du Platformer que vous pouvez retrouver dans &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-portage-complet-du-jeu-xna-vers-lt-canvas-gt-gr-226-ce-224-easeljs.aspx"&gt;l’autre article&lt;/a&gt;. Le jeu est ainsi désormais capable de s’adapter à n’importe quelle résolution en appliquant un ratio sur la manière de dessiner nos images et nos sprites. Tout est calculé pour partir de la résolution d’origine du Windows Phone (800x480) pour ensuite redessiner en fonction de ce ratio d’origine quelque soit la résolution. Vous pouvez le tester dans le navigateur ici : &lt;a title="http://david.blob.core.windows.net/html5platformerscale/index.html" href="http://david.blob.core.windows.net/html5platformerscale/index.html"&gt;HTML5 Platformer ReScale&lt;/a&gt; et vous amusez à redimensionner la fenêtre de votre navigateur. Pour finir, si vous êtes sur une résolution 16/9 sur votre moniteur, appuyez sur la touche F11 pour jouer en plein écran ! L’expérience devient vraiment sympa comme le montre cette copie d’écran :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://david.blob.core.windows.net/html5platformerscale/index.html"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5125.image_5F00_255E17C3.png" width="640" height="360" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On laisse alors le soin au navigateur d’appliquer éventuellement de l’anti-aliasing lors de cette opération de mise à l’échelle. Vous noterez également, selon certains navigateurs, des performances très différentes en fonction de la taille de la fenêtre et donc de la résolution demandée. IE9/IE10 semble, sur ma machine, relativement indifférent au mode plein écran ou aux petites résolutions en affichant un framerate stable de 60 fps. &lt;/p&gt;

&lt;h3&gt;Chargement des niveaux via l’appel au système de fichiers plutôt que XHR&lt;/h3&gt;

&lt;p&gt;Dans le code d’origine, les fichiers .TXT associés à chacun des niveaux étaient stockés sur le serveur et récupérés via des appels XmlHttpRequest. C’est un peu dommage d’effectuer un appel XHR local. Donc j’ai remplacé le code initial de la fonction &lt;em&gt;PlatformerGame.prototype.LoadNextLevel&lt;/em&gt; par :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Loading the next level contained into /level/{x}.txt
&lt;/span&gt;PlatformerGame.prototype.LoadNextLevel = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.levelIndex = (&lt;span style="color: blue"&gt;this&lt;/span&gt;.levelIndex + 1) % numberOfLevels;

    &lt;span style="color: #006400"&gt;// Searching where we are currently hosted
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;nextFileName = &lt;span style="color: maroon"&gt;&amp;quot;app/www/assets/levels/&amp;quot; &lt;/span&gt;+ &lt;span style="color: blue"&gt;this&lt;/span&gt;.levelIndex + &lt;span style="color: maroon"&gt;&amp;quot;.txt&amp;quot;&lt;/span&gt;;
    &lt;span style="color: blue"&gt;try &lt;/span&gt;{
        &lt;span style="color: blue"&gt;var &lt;/span&gt;instance = &lt;span style="color: blue"&gt;this&lt;/span&gt;;
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);

        &lt;span style="color: blue"&gt;function &lt;/span&gt;gotFS(fileSystem) {
            fileSystem.root.getFile(nextFileName, &lt;span style="color: blue"&gt;null&lt;/span&gt;, gotFileEntry, fail);
        }

        &lt;span style="color: blue"&gt;function &lt;/span&gt;gotFileEntry(fileEntry) {
            fileEntry.file(gotFile, fail);
        }

        &lt;span style="color: blue"&gt;function &lt;/span&gt;gotFile(file) {
            readAsText(file);
        }

        &lt;span style="color: blue"&gt;function &lt;/span&gt;readAsText(file) {
            &lt;span style="color: blue"&gt;var &lt;/span&gt;reader = &lt;span style="color: blue"&gt;new &lt;/span&gt;FileReader();
            reader.onloadend = &lt;span style="color: blue"&gt;function &lt;/span&gt;(evt) {
                instance.LoadThisTextLevel(evt.target.result.replace(/[\n\r\t]/g, &lt;span style="color: maroon"&gt;''&lt;/span&gt;));
            };
            reader.readAsText(file);
        }

        &lt;span style="color: blue"&gt;function &lt;/span&gt;fail(evt) {
            console.log(evt.target.error.code);
        }
    }
    &lt;span style="color: blue"&gt;catch &lt;/span&gt;(e) {
        console.log(&lt;span style="color: maroon"&gt;&amp;quot;Error loading level: &amp;quot; &lt;/span&gt;+ e.message);
&lt;span style="color: #006400"&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.LoadThisTextLevel(hardcodedErrorTextLevel);
    }
};&lt;/pre&gt;

&lt;p&gt;J’ai bêtement repris le code de la documentation de PhoneGap : &lt;a title="http://docs.phonegap.com/en/1.3.0/phonegap_file_file.md.html#FileReader" href="http://docs.phonegap.com/en/1.3.0/phonegap_file_file.md.html#FileReader"&gt;FileReader&lt;/a&gt; . Vous avez donc pleinement accès au système de fichiers du Windows Phone via JavaScript. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Petit tip :&lt;/u&gt;&lt;/strong&gt; pour vous aider à débugger ce qui est présent ou non dans l’Isolated Storage du téléphone, je vous conseille vivement cet outil qui m’a sauvé la vie : &lt;a title="http://isostorespy.codeplex.com/" href="http://isostorespy.codeplex.com/"&gt;IsoStoreSpy&lt;/a&gt; écrit par Samuel Blanchard. Une vraie merveille !&lt;/p&gt;

&lt;h3&gt;Modification du gameplay pour gérer l’accéléromètre&lt;/h3&gt;

&lt;p&gt;Bon il ne reste plus qu’à mixer les différentes parties de cet article pour arriver au résultat escompté. Pour cela, j’ai ajouté le code suivant dans le constructeur de l’objet &lt;em&gt;Player&lt;/em&gt; dans le fichier &lt;em&gt;Player.js&lt;/em&gt; :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;options = { frequency: 500 };
&lt;span style="color: blue"&gt;var &lt;/span&gt;that = &lt;span style="color: blue"&gt;this&lt;/span&gt;;

navigator.accelerometer.watchAcceleration(
    &lt;span style="color: blue"&gt;function &lt;/span&gt;(accelerometer) { that.moveDirectionAccel(accelerometer); },
    &lt;span style="color: blue"&gt;function &lt;/span&gt;() { console.log(&lt;span style="color: maroon"&gt;&amp;quot;Error with accelerometer&amp;quot;&lt;/span&gt;); }, 
    options);&lt;/pre&gt;

&lt;p&gt;Ensuite, voici la fonction qui sera rappelée suite aux variations de l’accéléromètre :&lt;/p&gt;

&lt;pre class="code"&gt;Player.prototype.moveDirectionAccel = &lt;span style="color: blue"&gt;function&lt;/span&gt;(acceleration) {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;accelValue = -acceleration.y;

    &lt;span style="color: #006400"&gt;// Move the player with accelerometer
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(Math.abs(accelValue) &amp;gt; 0.15) {
        &lt;span style="color: #006400"&gt;// set our movement speed
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.direction = Math.clamp(accelValue * &lt;span style="color: blue"&gt;this&lt;/span&gt;.AccelerometerScale, -1, 1);
    }
    &lt;span style="color: blue"&gt;else &lt;/span&gt;{
        &lt;span style="color: blue"&gt;this&lt;/span&gt;.direction = 0;
    }
};&lt;/pre&gt;

&lt;h3&gt;Le résultat en images avec quelques FPS sur les téléphones&lt;/h3&gt;

&lt;p&gt;Tout d’abord, voici le résultat dans l’émulateur :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0804.image_5F00_313B39E9.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7652.image_5F00_thumb_5F00_2F865A16.png" width="644" height="309" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sur un vrai périphérique, l’expérience varie d’un téléphone à l’autre. Prenons l’exemple du tout 1er niveau. Sur le &lt;strong&gt;LG E900&lt;/strong&gt;, le framerate tourne autour de &lt;strong&gt;&lt;font color="#000000"&gt;22 fps&lt;/font&gt;&lt;/strong&gt;, sur le &lt;strong&gt;&lt;font color="#800080"&gt;HTC Radar&lt;/font&gt;&lt;/strong&gt;, nous sommes autour de &lt;strong&gt;&lt;font color="#800080"&gt;31 fps&lt;/font&gt;&lt;/strong&gt; et sur le &lt;strong&gt;&lt;font color="#004080"&gt;Nokia Lumia 800&lt;/font&gt;&lt;/strong&gt; autour de &lt;strong&gt;&lt;font color="#004080"&gt;42 fps&lt;/font&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7824.DSCF4677_5F00_34684C2B.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="DSCF4677" border="0" alt="DSCF4677" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6648.DSCF4677_5F00_thumb_5F00_34F0B6BB.jpg" width="404" height="392" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Il en résulte un gameplay souvent décevant dans la plupart des cas. En effet, l’utilisation d’un canvas plein écran n’est pour l’instant pas une bonne idée sur ce genre de mobile même si le Nokia semble être le plus à même de gérer ce scénario. J’en avais déjà parlé lors de ma session ParisWeb 2011 sur le développement “cross-device”. Une approche de découpage de la scène de jeux utilisant de plus petits canvas animés ensuite via leurs propriétés CSS serait plus adaptée. C’est ce qui est fait sur la version HTML5 d’Angry Birds par exemple. Certains frameworks de jeux commencent d’ailleurs à envisager de le gérer pour vous. L’idée serait donc de coder 1 fois le jeu avec des APIs de haut niveau et le framework s’occuperait de choisir soit un canvas plein écran, soit un découpage en plusieurs petits canvas. Vous l’aurez compris : l’expérience de jeux HTML5 sur mobile n’en est qu’à ses débuts mais l’avenir s’annonce très intéressant. A suivre donc !&lt;/p&gt;

&lt;h3&gt;Solution complète à télécharger&lt;/h3&gt;

&lt;p&gt;Vous trouverez &lt;strong&gt;le code source complet du jeu HTML5 Platformer pour PhoneGap ici&lt;/strong&gt; : &lt;a title="http://david.blob.core.windows.net/html5/HTML5GapPlatformer.zip" href="http://david.blob.core.windows.net/html5/HTML5GapPlatformer.zip"&gt;HTML5GapPlatformer.zip&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Ressources complémentaires &lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a title="http://blogs.technet.com/b/port25/archive/2011/12/19/full-support-for-phonegap-on-windows-phone-is-now-complete.aspx" href="http://blogs.technet.com/b/port25/archive/2011/12/19/full-support-for-phonegap-on-windows-phone-is-now-complete.aspx"&gt;Full Support for PhoneGap on Windows Phone is Now Complete!&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a title="http://blogs.msdn.com/b/glengordon/archive/2011/11/15/phonegap-on-windows-phone-tips.aspx" href="http://blogs.msdn.com/b/glengordon/archive/2011/11/15/phonegap-on-windows-phone-tips.aspx"&gt;PhoneGap on Windows Phone Tips&lt;/a&gt; de Glen Gardon qui contient plusieurs tutoriaux intéressants à suivre&lt;/li&gt;

  &lt;li&gt;De nombreux tutoriaux excellents à suivre ici: &lt;a title="http://wiki.phonegap.com/w/page/35501397/Tutorials" href="http://wiki.phonegap.com/w/page/35501397/Tutorials"&gt;http://wiki.phonegap.com/w/page/35501397/Tutorials&lt;/a&gt;&amp;#160;&lt;/li&gt;
&lt;/ul&gt;
&lt;a name="conclusion"&gt;
  &lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;/a&gt;

&lt;p&gt;PhoneGap ouvre des perspectives intéressantes pour vous aider à écrire des applications pour le téléphone en reprenant vos compétences existantes en JavaScript, HTML et CSS. Il ne pourra pas forcément couvrir tous les scénarios actuellement adressées par un développement natif (Silverlight ou XNA) mais c’est une voie à envisager si vous souhaitez capitaliser sur les compétences de l’une de vos équipes. Il faudra par contre bien faire attention à vérifier que le type de projet retenu se prête bien aux limitations actuelles d’HTML5. &lt;/p&gt;

&lt;p&gt;Il existe aussi la possibilité de mixer les 2 environnements en créant des expériences hybrides : le tronc commun écrit en “HTML5” et le reste par des équipes maitrisant la plateforme native. C’est ainsi que certains plug-ins ont été créés pour pousser un peu loin l’intégration dans l’expérience Metro : &lt;a title="https://github.com/purplecabbage/phonegap-plugins/tree/master/WindowsPhone" href="https://github.com/purplecabbage/phonegap-plugins/tree/master/WindowsPhone"&gt;Plug-ins PhoneGap pour Windows Phone&lt;/a&gt; . Vous y trouverez par exemple la possibilité de mettre à jour les “Tiles” depuis votre code JavaScript.&lt;/p&gt;

&lt;p&gt;Pour finir, PhoneGap et l’usage d’HTML5 permet également une portabilité plus simple vers d’autres plateformes… dans une certaines mesure. Cependant, ce sujet précis étant un vaste et passionnant débat remplis de mauvaises idées reçues, j’y reviendrais peut-être dans un autre billet si j’en ai le temps d’ici les &lt;a href="http://www.mstechdays.fr"&gt;TechDays&lt;/a&gt; ! &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7444.wlEmoticon_2D00_smile_5F00_442F71E6.png" /&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250681" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Windows+Phone+7/">Windows Phone 7</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/EaselJS/">EaselJS</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/JavaScript/">JavaScript</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/PhoneGap/">PhoneGap</category></item><item><title>Testez et débuggez vos sites HTML5 sous Windows Phone 7 avec l’émulateur gratuit</title><link>http://blogs.msdn.com/b/davrous/archive/2011/12/13/testez-et-d-233-buggez-vos-sites-html5-sous-windows-phone-7-avec-l-233-mulateur-gratuit.aspx</link><pubDate>Tue, 13 Dec 2011 10:02:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10247110</guid><dc:creator>David Rousset</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10247110</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2011/12/13/testez-et-d-233-buggez-vos-sites-html5-sous-windows-phone-7-avec-l-233-mulateur-gratuit.aspx#comments</comments><description>&lt;p&gt;Les internautes arrivent de plus en plus souvent sur vos sites web depuis un périphérique mobile. Il est donc de plus en plus important de leur offrir une bonne expérience sur le navigateur embarqué. Vous ne pouvez plus vous permettre d’ignorer cette population en leur offrant une version trop dégradée. Dans notre cas, depuis la mise à jour nommée “Mango”, &lt;strong&gt;Internet Explorer 9 est arrivé sur Windows Phone&lt;/strong&gt;. Vous pouvez donc lui fournir du HTML5, CSS3 Media Queries &amp;amp; co pour créer une bonne expérience. Je vous propose alors de voir 4 choses dans cet article : &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Comment récupérer &lt;strong&gt;l’émulateur Windows Phone&lt;/strong&gt; et l’utiliser &lt;/li&gt;    &lt;li&gt;Un point sur les &lt;strong&gt;différences entre IE9 Desktop et mobile&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Comment &lt;strong&gt;débugger votre code JavaScript avec jsConsole&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Pour finir, comment &lt;strong&gt;débugger le trafic réseau&lt;/strong&gt; entre l’émulateur et le reste du monde grâce à Fiddler &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Le but principal de cet article étant de vous faire gagner potentiellement du temps. &lt;/p&gt;  &lt;h2&gt;L’émulateur Windows Phone&lt;/h2&gt;  &lt;p&gt;La toute première chose que je vous invite à faire est de télécharger le SDK qui contient l’émulateur ici : &lt;a title="Télécharger SDK Windows Phone" href="http://aka.ms/hp-windows-phone"&gt;Télécharger le SDK Windows Phone&lt;/a&gt; . Vous pouvez l’installer sous Windows Vista ou Windows 7. &lt;/p&gt;  &lt;p&gt;Il contient également les outils (gratuits) de développement. Si le sujet vous intéresse et que vous souhaitez découvrir cette plateforme, rendez-vous ici : &lt;a title="http://msdn.microsoft.com/fr-fr/windowsphone/ff637027" href="http://msdn.microsoft.com/fr-fr/windowsphone/ff637027"&gt;Découvrir la plateforme Windows Phone&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Mais revenons au sujet qui nous intéresse. Une fois le SDK installé, vous trouverez l’émulateur dans votre menu démarrer : &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0131.WPEmulator_5F00_2CB4E7E4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="WPEmulator" border="0" alt="WPEmulator" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7571.WPEmulator_5F00_thumb_5F00_35C17365.png" width="400" height="199" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Lorsque vous le lancez, vous aurez ce résultat et vous pouvez configurer 2 ou 3 trucs :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2450.image_5F00_360700D1.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3823.image_5F00_thumb_5F00_0FC4A779.png" width="132" height="240" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8625.image_5F00_52C075E6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8625.image_5F00_thumb_5F00_0543D359.png" width="132" height="240" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0880.image_5F00_63E42DBC.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7242.image_5F00_thumb_5F00_6F9974EE.png" width="132" height="240" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4034.image_5F00_4E39CF52.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8244.image_5F00_thumb_5F00_6BCBAA51.png" width="132" height="240" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4024.image_5F00_55958EFF.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6180.image_5F00_thumb_5F00_4C5953BE.png" width="132" height="240" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Vous pouvez par exemple choisir entre le fait de recevoir par défaut la version mobile du site ou la version bureau.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#800000"&gt;Détail important à connaitre&lt;/font&gt;&lt;/strong&gt; : pour éviter de taper les URLs avec le clavier virtuel, cliquez dans l’émulateur et appuyer sur la &lt;strong&gt;touche “Pause”&lt;/strong&gt;. Vous devriez ensuite être en mesure de taper avec votre clavier dans l’émulateur.&lt;/p&gt;  &lt;p&gt;Voici les autres choses à connaitre sur l’émulateur qui pourront vous aider à créer vos expériences mobiles sur Windows Phone. &lt;strong&gt;Gestion de l’orientation&lt;/strong&gt; présente sur la barre d’options à droite de l’émulateur :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6180.image_5F00_3FEB3095.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7585.image_5F00_thumb_5F00_1E8B8AF9.png" width="240" height="121" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Et voici le résultat :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8156.image_5F00_08556FA7.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1222.image_5F00_thumb_5F00_257B17B1.png" width="240" height="132" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Autre détail à connaitre, pour que l’orientation s’effectue correctement et soit prise en compte, il faut ré-appuyer sur la touche “pause” si vous l’avez fait précédemment pour utiliser votre clavier. Sinon, vous aurez l’impression de devoir systématique pencher la tête à gauche ou à droite. &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8611.wlEmoticon_2D00_winkingsmile_5F00_1EF3A9EF.png" /&gt;&lt;/p&gt;  &lt;p&gt;Vous pouvez aussi&lt;strong&gt; simuler de votre position&lt;/strong&gt; pour la géolocalisation. Prenons par exemple ce site web de démo : &lt;a title="http://ie.microsoft.com/testdrive/mobile/HTML5/Geolocation/Default.html" href="http://ie.microsoft.com/testdrive/mobile/HTML5/Geolocation/Default.html"&gt;IE Test Drive Mobile avec Géolocalisation HTML5&lt;/a&gt; qui utilise justement l’API de géolocalisation. &lt;/p&gt;  &lt;p&gt;Voici le résultat par défaut dans l’émulateur :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7178.image_5F00_190CF488.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1731.image_5F00_thumb_5F00_36329C92.png" width="132" height="240" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3884.image_5F00_1FFC8140.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3884.image_5F00_thumb_5F00_7D5842C4.png" width="132" height="240" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2816.image_5F00_42FCCCE3.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1830.image_5F00_thumb_5F00_1E3B8F9F.png" width="132" height="240" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;On vous localise sur Redmond. Donc si vous voulez changer cela (sauf si vous habitez vraiment à Redmond &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2047.wlEmoticon_2D00_smile_5F00_25E1FD1F.png" /&gt;), vous pouvez le faire en faisant apparaitre une fenêtre supplémentaire. Pour cela, cliquez sur “&amp;gt;&amp;gt;” et mettez une punaise (ou push pin en anglais) à l’endroit souhaité. Voici un exemple où j’en mets un sur la Tour Eiffel et l’application HTML5/JavaScript obtient bien la bonne information :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0184.image_5F00_71B25FB8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5808.image_5F00_thumb_5F00_5DF55057.png" width="1024" height="596" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Cela peut donc être très pratique pour débugger une application HTML5 basée sur la géolocalisation sans forcément vous balader physiquement dans toute la France… voir la planète ! &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8611.wlEmoticon_2D00_winkingsmile_5F00_1EF3A9EF.png" /&gt;&lt;/p&gt;  &lt;p&gt;Pour le reste, testez votre site de manière habituelle et observez les différences entre la version desktop et mobile comme avec le site &lt;a href="http://foodsense.is/"&gt;Food Sense&lt;/a&gt; par exemple mettant en œuvre intelligemment CSS3 Media Queries :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6138.image_5F00_7D6334F0.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6710.image_5F00_thumb_5F00_1C298302.png" width="550" height="284" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0383.image_5F00_51DEC85C.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1447.image_5F00_thumb_5F00_55303A37.png" width="350" height="192" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Vous pouvez voir ci-dessus le résultat sur IE9 sous Windows 7, IE9 sur Windows Phone en mode portrait puis paysage.&lt;/p&gt;  &lt;p&gt;Donc si tout cela vous intéresse et que vous souhaitez accueillir dans de bonnes conditions les nombreux acheteurs récents du superbe &lt;a href="http://www.nokia.fr/fr-fr/produits/mobiles/lumia800/"&gt;Nokia Lumia 800&lt;/a&gt;, foncez télécharger ici le SDK :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://aka.ms/hp-windows-phone"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Télécharger SDK Windows Phone" border="0" alt="Télécharger SDK Windows Phone" src="http://msdn.microsoft.com/ms348103.SDKPhone2_onmouseover(fr-fr,MSDN.10).gif" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Et testez votre site dessus !&lt;/p&gt;  &lt;h2&gt;Différences entre IE9 desktop et mobile&lt;/h2&gt;  &lt;p&gt;Commençons par &lt;strong&gt;&lt;font color="#800000"&gt;les choses en moins&lt;/font&gt;&lt;/strong&gt; classées par ordre d’importance selon moi:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;pas de support des fonts téléchargeables comme EOT, TTF/OTF et WOFF. Bien que le tag font-face soit supporté, le navigateur IE9 mobile n’essaiera pas de télécharger la font. La liste des fonts installées et supportées par Windows Phone se trouve ici : &lt;a title="http://msdn.microsoft.com/fr-fr/library/ff806365%28v=VS.95%29.aspx" href="http://msdn.microsoft.com/fr-fr/library/ff806365%28v=VS.95%29.aspx"&gt;Liste des fonts supportées&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;pas de support de flux multiples avec la balise audio HTML5 &lt;/li&gt;    &lt;li&gt;pas de support de mode de rétro compatibilité avec le mode de document Internet Explorer 8. IE9 mobile rendra les sites forcément avec le moteur de rendu d’IE9. &lt;/li&gt;    &lt;li&gt;assez logiquement, pas de support de communications “cross-window” via JavaScript &lt;/li&gt;    &lt;li&gt;pas de support de VBScript, d’ActiveX, d’extensibilité via les BHO (Browser Helper&amp;#160; Objects) et les barre d’outils, pas de support d’Active Document non plus &lt;/li&gt;    &lt;li&gt;pas de support de vieilles technologies comme les “binary behaviors”, HTCs, HTML+TIME et VML &lt;/li&gt;    &lt;li&gt;pas de compilation JIT &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Ainsi, heureusement, la quasi totalité des différences entre la version de bureau d’IE9 et son équivalent mobile représente, je pense, d’excellentes choses.&lt;/p&gt;  &lt;p&gt;Dans&lt;strong&gt; &lt;font color="#008000"&gt;les choses en plus&lt;/font&gt;&lt;/strong&gt;, nous avons :&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;support du GPS pour la géolocalisation HTML5. Windows Phone utilise ainsi la couche de localisation du périphérique et utilise donc le GPS s’il est disponible. La version de bureau d’IE9 s’appuyant sur d’autres méthodes n’utilisant pas le GPS car quasiment aucun PC n’en est équipé. &lt;/li&gt;    &lt;li&gt;support du &lt;em&gt;Viewport&lt;/em&gt;. &lt;em&gt;Width&lt;/em&gt;, &lt;em&gt;height&lt;/em&gt; et &lt;em&gt;user-scalable&lt;/em&gt;. Par contre, bien que certaines de ces fonctionnalités soient supportées dans certains navigateurs, les propriétés &lt;em&gt;minimum-scale&lt;/em&gt;, &lt;em&gt;maximum-scale&lt;/em&gt; et &lt;em&gt;initial-scale&lt;/em&gt; sont pour l’instant non supportées &lt;/li&gt;    &lt;li&gt;support de la propriété CSS : -&lt;em&gt;ms-text-size-adjust&lt;/em&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Vous retrouverez tout cela un peu plus en détail et en anglais ici : &lt;a title="http://msdn.microsoft.com/fr-fr/library/ff462082(v=vs.92).aspx" href="http://msdn.microsoft.com/fr-fr/library/ff462082(v=vs.92).aspx"&gt;Web Development for Windows Phone&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Pour le reste, reportez vous simplement au &lt;a href="http://msdn.microsoft.com/fr-fr/ie/ff468705.aspx"&gt;guide du développeur Internet Explorer 9&lt;/a&gt; qui contient toutes les fonctionnalités supportées par IE9 desktop et donc mobile. J’attire par exemple votre attention sur &lt;strong&gt;2 points importants lorsque vous allez tester du HTML5 ou CSS3 dans IE9 Mobile &lt;/strong&gt;:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Tout comme IE9 Desktop, il faut absolument avoir créé un document HTML5 standard avec donc la balise &amp;lt;!DOCTYPE html&amp;gt; en tout début de document. Si vous ne la positionnez pas, IE9 Desktop come Mobile basculeront dans un ancien mode de rendu non “compatible” HTML5&lt;/li&gt;    &lt;li&gt;IE9 Mobile gère une liste de compatibilité des sites comme décrit ici : &lt;a title="http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/09/29/ie9-s-faster-more-capable-compatibility-view-list-now-on-windows-phone.aspx" href="http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/09/29/ie9-s-faster-more-capable-compatibility-view-list-now-on-windows-phone.aspx"&gt;IE9’s faster, more capable Compatibility View List… now on Windows Phone!&lt;/a&gt; . Donc si vous vous apercevez que votre code ne se comporte par comme prévu dans IE9 Mobile, c’est peut-être que votre site est hébergé sur un nom de domaine marqué comme non compatible dans la liste mise à jour toutes les 2 semaines. Et tout comme IE9 Desktop, vous pouvez forcer le mode standard via le meta tag X-UA-COMPATIBLE.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Par exemple, j’ai eu une interaction récente sur Twitter avec &lt;a title="@benjamincrozat" href="https://twitter.com/#!/benjamincrozat"&gt;@benjamincrozat&lt;/a&gt; sur du border-radius qui ne marchait pas sous IE9 Mobile. En regardant depuis IE9 Desktop son URL de test, je me suis aperçu de la chose suivante dans la console de debug (via F12) :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3858.image_5F00_7D2044C3.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1212.image_5F00_thumb_5F00_4E7A1614.png" width="640" height="138" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;On observe alors que dropbox.com est présent dans la liste de compatibilité, ce qui fait basculer IE9 en mode de compatibilité IE7. Conclusion : n’hésitez pas à tester votre site sous IE9 “normal” avant de tester sous IE9 mobile pour faire une 1ère passe de tests. &lt;/p&gt;  &lt;h2&gt;Débugger le code JavaScript avec jsConsole&lt;/h2&gt;  &lt;p&gt;Dans la mise au point d’un site web pour mobile, la partie la plus pénible est souvent de débugger le code JavaScript sur tournant sur le périphérique. Heureusement, l’excellent &lt;a href="http://remysharp.com/"&gt;Remy Sharp&lt;/a&gt; a eu la bonne idée de travailler sur un projet permettant de piloter à distance le code JS exécuté sur le périphérique. Le fruit de son travail est le projet jsConsole : &lt;a href="http://jsconsole.com"&gt;http://jsconsole.com&lt;/a&gt; . &lt;/p&gt;  &lt;p&gt;Mais plutôt que de vous expliquer en détail son usage, je préfère fortement vous inviter à lire &lt;strong&gt;l’excellent tutoriel présent sur le site d’Alsacréations&lt;/strong&gt; : &lt;a title="http://www.alsacreations.com/tuto/lire/1245-deboguer-son-site-mobile-avec-jsconsole.html" href="http://www.alsacreations.com/tuto/lire/1245-deboguer-son-site-mobile-avec-jsconsole.html"&gt;Déboguer son site mobile avec JsConsole&lt;/a&gt; . Je ne vois pas trop comment je pourrais mieux faire. &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8611.wlEmoticon_2D00_winkingsmile_5F00_1EF3A9EF.png" /&gt;&lt;/p&gt;  &lt;p&gt;Par contre, j’ai bien vérifié que cette solution fonctionnait parfaitement avec IE9 sur Windows Phone. Voici un exemple utilisant jsConsole et PhoneGap pour Windows Phone 7 :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6431.image_5F00_242A6D04.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3223.image_5F00_thumb_5F00_1844B46B.png" width="640" height="331" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Vous pouvez donc compter dessus pour vous aider à tester et corriger votre site sur la version mobile d’IE9. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#800000"&gt;Attention !&lt;/font&gt;&lt;/strong&gt; Pour des raisons évidentes de sécurité, attention à bien mettre tout cela en place qu’à des fins de debug et à bien retirer son usage avant la mise en production ! Mais ai-je vraiment besoin de le vous rappeler ?&lt;/p&gt;  &lt;h2&gt;Débugger le trafic réseau avec Fiddler&lt;/h2&gt;  &lt;p&gt;Pour finir un peu plus bas dans les couches, nous allons maintenant voir comment capturer le trafic réseau entre l’émulateur Windows Phone et le reste du monde. Voici les étapes à suivre :&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Installer la &lt;a href="http://www.fiddler2.com/dl/fiddler2betasetup.exe"&gt;dernière version de Fiddler&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Démarrer Fiddler &lt;/li&gt;    &lt;li&gt;Aller dans les options via les menus “Tools” –&amp;gt; “Fiddler Options” &lt;/li&gt;    &lt;li&gt;Ouvrez l’onglet “&lt;strong&gt;Connections&lt;/strong&gt;” et cochez la case “&lt;strong&gt;Allow remote computers to connect&lt;/strong&gt;”. &lt;/li&gt;    &lt;li&gt;Cliquez sur “OK” pour fermer la fenêtre des options de Fiddler &lt;/li&gt;    &lt;li&gt;Dans la boite de commandes sous la liste des “Web sessions”, tapez la commande suivante :&amp;#160; &lt;strong&gt;prefs set fiddler.network.proxy.registrationhostname &lt;em&gt;HostName &lt;/em&gt;&lt;/strong&gt;où &lt;strong&gt;&lt;em&gt;HostName &lt;/em&gt;&lt;/strong&gt;correspond au nom de votre machine &lt;/li&gt;    &lt;li&gt;Fermer et redémarrer Fiddler &lt;/li&gt;    &lt;li&gt;Démarrer (ou redémarrer) l’émulateur Windows Phone &lt;/li&gt;    &lt;li&gt;Ouvrer Internet Explorer et naviguez vers le site à débugger &lt;/li&gt;    &lt;li&gt;Observez le trafic réseau affiché par Fiddler &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Et voici un résultat de capture en naviguant vers le site d’Alsacréations :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7242.image_5F00_44E8FC4A.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1738.image_5F00_thumb_5F00_524AFB51.png" width="640" height="385" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Avec &lt;a href="http://aka.ms/hp-windows-phone"&gt;notre émulateur gratuit&lt;/a&gt; et toutes ces astuces, j’espère que vous serez maintenant correctement armé pour tester et débugger vos sites sur IE9 mobile !&lt;/p&gt;  &lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10247110" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Internet+Explorer+9/">Internet Explorer 9</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Windows+Phone+7/">Windows Phone 7</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/CSS3/">CSS3</category></item><item><title>Introduction aux animations CSS3</title><link>http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-aux-animations-css3.aspx</link><pubDate>Mon, 05 Dec 2011 23:28:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10244424</guid><dc:creator>David Rousset</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10244424</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-aux-animations-css3.aspx#comments</comments><description>&lt;meta content="IE=edge" http-equiv="X-UA-Compatible" /&gt;&lt;script&gt;
$(function() {
// run the currently selected effect
function runEffect(target) {
// get effect type from 
var selectedEffect = "clip";

var options = {};

// run the effect
target.toggle(500 );
};

$("#properties").hide();
$("#types").hide();

// set effect from select menu value
$( "#propertiesLink" ).click(function() {
runEffect($("#properties"));
return false;
});

$( "#typesLink" ).click(function() {
runEffect($("#types"));
return false;
});
});
&lt;/script&gt;  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 10px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" align="right" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6443.TestAnimations_5F00_4312DF8D.jpg" width="300" height="200" /&gt;&lt;/p&gt;  &lt;p&gt;Les applications HTML5 d’aujourd’hui peuvent désormais fournir des expériences inédites grâces aux nouvelles spécifications CSS3. L’une d’entre elles est nommée &lt;strong&gt;CSS3 Animations&lt;/strong&gt;. Elle vous permet de créer des animations évoluées sur des éléments HTML. Cela ouvre d’intéressantes perspectives afin de fournir des retours pertinents à l’utilisateur et construire des applications rapides &amp;amp; fluides. De plus, comme ces nouvelles animations sont la plupart du temps accélérées matériellement par le GPU, elles permettent de monter la qualité de la nouvelle génération d’applications HTML5 vers de nouveaux sommets.&lt;/p&gt;  &lt;p&gt;Si l’on traduit une partie des spécifications “CSS Animation Module Level 3” du &lt;a href="http://www.w3.org/TR/css3-animations/"&gt;site officiel du W3C&lt;/a&gt;, on découvre que ces spécifications CSS3 &lt;em&gt;introduisent des animations définies, indiquant les propriétés CSS qui évolueront selon un intervalle de temps donné. Cette spécification est une extension du module CSS Transitions.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Comme CSS3 Animations est une &lt;strong&gt;extension des CSS3 Transitions&lt;/strong&gt;, je vous invite à lire dans un 1er temps l’article dédié à ce sujet de mon collègue David Catuhe: &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2011/11/24/fr-introduction-224-css3-transitions.aspx"&gt;Introduction aux transitions CSS3&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;A travers cet article, nous allons découvrir une démo intéressante mettant en avant le potentiel des animations CSS3, comment construire des animations simples et finalement comment gérer un éventuel mode dégradé via JavaScript:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="#intro"&gt;CSS3 Animations&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#support"&gt;Support dans les navigateurs&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#fallback"&gt;Librairie JavaScript pour simuler les animations CSS3&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#conclusion"&gt;Conclusion&lt;/a&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Commençons tout d’abord par rapidement découvrir ce que sont les animations CSS3. Voici un exemple d’animation d’un TB-TT (ou AT-AT en anglais) issu de l’univers de StarWars et utilisant CSS3 Animations pour animer les différentes parties du transport. Si votre navigateur ne supporte pas les spécifications CSS3 animations, une librairie JavaScript sera chargée pour simuler son action: &lt;/p&gt; &lt;iframe style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="570" src="http://david.blob.core.windows.net/html5/css3atat/index.htm" width="716" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;Vous pouvez également tester cet exemple dans une fenêtre séparée ici : &lt;a title="http://david.blob.core.windows.net/html5/css3atat/index.htm" href="http://david.blob.core.windows.net/html5/css3atat/index.htm"&gt;http://david.blob.core.windows.net/html5/css3atat/index.htm&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/strong&gt; cet exemple a été testé avec succès sous IE10 PP3/PP4, Chrome 15, Firefox 8 et iPad 2 pour le support natif des animations. La librairie de “fallback” fonctionne très bien sous IE9 classique et mobile (Windows Phone). Cependant, pour des raisons qui me sont inconnues, elle génère des comportements pour le moins étranges sous Opera 11.50 apparemment résolus sous la 11.60. Par ailleurs, notre chère plateforme de blog force souvent le moteur de rendu IE9 via un meta tag ce qui empêche la démo de fonctionner correctement sous IE10. Pour forcer le moteur IE10 standards, appuyer sur la touche F12 et changer la valeur de “Document Mode”. Sinon, regardez la démo dans une fenêtre séparée. &lt;/p&gt;  &lt;p&gt;Cet exemple est basé sur le super boulot réalisé par &lt;a href="http://twitter.com/acalzadilla"&gt;Anthony Calzadilla&lt;/a&gt;. Vous pouvez découvrir d’autres superbes démos mettant en œuvre CSS3 Animations sur son site ici : &lt;a href="http://www.anthonycalzadilla.com"&gt;http://www.anthonycalzadilla.com&lt;/a&gt; . J’apprécie particulièrement son exemple &lt;a href="http://www.anthonycalzadilla.com/i-twitty-the-fool/"&gt;I twitty the fool&lt;/a&gt; utilisant SVG &amp;amp; CSS3 Animation combinés. &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0827.wlEmoticon_2D00_winkingsmile_5F00_475BBE95.png" /&gt;&lt;/p&gt; &lt;a name="intro"&gt;   &lt;h2&gt;CSS3 Animations&lt;/h2&gt; &lt;/a&gt;  &lt;h3&gt;Introduction&lt;/h3&gt;  &lt;p&gt;Commençons par analyser sur quelles parties vous pouvez jouer pour fabriquer des animations. CSS3 Animations travaille tout simplement sur les mêmes valeurs que CSS3 Transitions.&lt;/p&gt;  &lt;p&gt;Les voici: &lt;a id="typesLink"&gt;cliquez ici pour les afficher/cacher&lt;/a&gt;&lt;/p&gt;  &lt;ul id="types"&gt;   &lt;li&gt;&lt;strong&gt;couleur &lt;/strong&gt;: interpolée via ses composantes rouge, verte, bleue et alpha (qui sont considérées comme des nombres) &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;longueur &lt;/strong&gt;: interpolée comme un nombre &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;pourcentage &lt;/strong&gt;: interpolée comme un nombre &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;entier &lt;/strong&gt;:interpolé de manière discrète (en fait l’interpolation se fait sur une version décimale qui est ensuite tronquée vers un entier en utilisant &lt;code&gt;floor())&lt;/code&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;nombre&lt;/strong&gt;: interpolé directement comme un réel &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;liste de transformation &lt;/strong&gt;: voir la spécification des CSS3 2D Transforms (&lt;a href="http://www.w3.org/TR/css3-2d-transforms"&gt;http://www.w3.org/TR/css3-2d-transforms&lt;/a&gt;) &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;rectangle&lt;/strong&gt;: interpolé via ses composantes x, y, largeur, hauteur &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;visibilité&lt;/strong&gt;: interpolé de manière discrète (en fait l’interpolation est effectuée sur un nombre réel allant de 0 à 1 ou 0 vaut &lt;em&gt;caché&lt;/em&gt; et 1 vaut &lt;em&gt;visible&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;ombre&lt;/strong&gt;: interpolé via ses composantes de couleur, x, y et flou &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;gradient&lt;/strong&gt;: interpolé au travers de la position et la couleur de chacune des étapes. La valeur d’origine et la valeur de destination de la transitions doivent par contre avoir le même type (linéaire ou radial) et le même nombre d’étapes &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;paint server&lt;/strong&gt; (SVG): l’interpolation est uniquement supporté de gradient ver gradient ou de couleur vers couleur &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;liste séparée par des espaces d’un type ci-dessus &lt;/strong&gt;: si les listes d’origine et de destination de la transition ont le même nombre d’éléments, les règles ci-dessus s’applique et l’interpolation a bien lieu. Dans le cas contraire, l’interpolation n’est pas jouée &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;propriété synthétique (shorthand property) &lt;/strong&gt;:&lt;strong&gt; &lt;/strong&gt;si toutes les parties de la synthèse peuvent être animées alors l’interpolation a lieu comme si chaque propriété avait été spécifiée individuellement &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Et les propriétés suivantes doivent être supportées pour les animations: &lt;a id="propertiesLink"&gt;cliquez ici pour les afficher/cacher&lt;/a&gt;&lt;/p&gt;  &lt;ul id="properties"&gt;   &lt;li&gt;background-color (&lt;i&gt;couleur&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;background-image (&lt;i&gt;que les gradients&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;background-position (&lt;i&gt;pourcentage et longueur&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;border-bottom-color (&lt;i&gt;couleur&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;border-bottom-width (longueur) &lt;/li&gt;    &lt;li&gt;border-color (&lt;i&gt;couleur&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;border-left-color (&lt;i&gt;couleur&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;border-left-width (longueur) &lt;/li&gt;    &lt;li&gt;border-right-color (&lt;i&gt;couleur&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;border-right-width (longueur) &lt;/li&gt;    &lt;li&gt;border-spacing (longueur) &lt;/li&gt;    &lt;li&gt;border-top-color (&lt;i&gt;couleur&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;border-top-width (longueur) &lt;/li&gt;    &lt;li&gt;border-width (longueur) &lt;/li&gt;    &lt;li&gt;bottom (&lt;i&gt;longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;color (&lt;i&gt;couleur&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;crop (&lt;i&gt;rectangle&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;font-size (&lt;i&gt;longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;font-weight (&lt;i&gt;nombre&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;grid-* (&lt;i&gt;divers&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;height (&lt;i&gt;longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;left (&lt;i&gt;longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;letter-spacing (longueur) &lt;/li&gt;    &lt;li&gt;line-height (&lt;i&gt;nombre, longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;margin-bottom (longueur) &lt;/li&gt;    &lt;li&gt;margin-left (longueur) &lt;/li&gt;    &lt;li&gt;margin-right (longueur) &lt;/li&gt;    &lt;li&gt;margin-top (longueur) &lt;/li&gt;    &lt;li&gt;max-height (&lt;i&gt;longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;max-width (&lt;i&gt;longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;min-height (&lt;i&gt;longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;min-width (longueur et &lt;i&gt;pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;opacity (&lt;i&gt;nombre&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;outline-color (&lt;i&gt;couleur&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;outline-offset (&lt;i&gt;entier&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;outline-width (longueur) &lt;/li&gt;    &lt;li&gt;padding-bottom (longueur) &lt;/li&gt;    &lt;li&gt;padding-left (longueur) &lt;/li&gt;    &lt;li&gt;padding-right (longueur) &lt;/li&gt;    &lt;li&gt;padding-top (longueur) &lt;/li&gt;    &lt;li&gt;right (&lt;i&gt;longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;text-indent (&lt;i&gt;longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;text-shadow (&lt;i&gt;ombre&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;top (&lt;i&gt;longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;vertical-align (&lt;i&gt;keywords, longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;visibility (&lt;i&gt;visibilité)&lt;/i&gt; &lt;/li&gt;    &lt;li&gt;width (&lt;i&gt;longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;word-spacing (&lt;i&gt;longueur et pourcentage&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;z-index (&lt;i&gt;entier&lt;/i&gt;) &lt;/li&gt;    &lt;li&gt;zoom (&lt;i&gt;nombre&lt;/i&gt;) &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;&lt;/h3&gt;  &lt;h3&gt;SVG&lt;/h3&gt;  &lt;p&gt;Les propriétés des objets SVG sont animables lorsque qu’elles sont définies comme &lt;b&gt;animatable:true&lt;/b&gt; dans les spécifications SVG : &lt;a href="http://www.w3.org/TR/SVG/struct.html"&gt;http://www.w3.org/TR/SVG/struct.html&lt;/a&gt;. Cependant, à l’heure où j’ai écrit cet article, je n’ai pas réussi à combiner avec succès des animations CSS3 directement sur des éléments SVG dans aucune des dernières versions des navigateurs.&amp;#160; Les exemples que vous pourrez trouver utilisent alors une petite astuce: il embarque les ressources SVG dans différents DIV eux-mêmes animés via CSS3 comme l’exemple &lt;a href="http://www.anthonycalzadilla.com/i-twitty-the-fool/"&gt;I twitty the fool&lt;/a&gt; d’Anthony.&lt;/p&gt;  &lt;h3&gt;Déclarations&lt;/h3&gt;  &lt;p&gt;Pour déclarer une animation dans un fichier CSS, voici le type de code générique que vous aurez à taper:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@keyframes &lt;/span&gt;nom_de_l_animation {
  &lt;span style="color: red"&gt;&lt;font color="#000000"&gt;from&lt;/font&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;{
   &lt;font color="#ff0000"&gt;propriété_à_animer:&lt;/font&gt; valeur_initiale&lt;/span&gt;;
  }
  50% {
     &lt;span style="color: red"&gt;&lt;font color="#ff0000"&gt;propriété&lt;/font&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;font color="#ff0000"&gt;_à_animer:&lt;/font&gt; valeur_intermédiaire&lt;/span&gt;;
  }
  &lt;span style="color: maroon"&gt;to &lt;/span&gt;{
    &lt;span style="color: red"&gt;&lt;font color="#ff0000"&gt;propriété&lt;/font&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;font color="#ff0000"&gt;_à_animer:&lt;/font&gt; valeur_finale&lt;/span&gt;;
  }
}&lt;/pre&gt;

&lt;p&gt;qui pourrait également s’écrire ainsi :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@keyframes &lt;/span&gt;nom_de_l_animation {
    0% {
        &lt;span style="color: red"&gt;&lt;font color="#ff0000"&gt;propriété&lt;/font&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;font color="#ff0000"&gt;_à_animer:&lt;/font&gt; valeur_initiale&lt;/span&gt;;
    }
    50% {
        &lt;span style="color: red"&gt;&lt;font color="#ff0000"&gt;propriété&lt;/font&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;font color="#ff0000"&gt;_à_animer:&lt;/font&gt; valeur_intermédiaire&lt;/span&gt;;
    }
    100% {
        &lt;span style="color: red"&gt;&lt;font color="#ff0000"&gt;propriété&lt;/font&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;font color="#ff0000"&gt;_à_animer:&lt;/font&gt; valeur_finale&lt;/span&gt;;
    }
}&lt;/pre&gt;

&lt;p&gt;Cette animation définit 3 étapes 0, 50 &amp;amp; 100%. Pour construire une animation valide, vous devez au moins avoir un &lt;strong&gt;&lt;em&gt;from&lt;/em&gt;&lt;/strong&gt; (ou 0%) et un &lt;strong&gt;&lt;em&gt;to&lt;/em&gt;&lt;/strong&gt; (ou 100%) soit 2 étapes minimum. Après cela, vous pouvez ajouter autant d’étapes (ou keyframes) que vous le souhaitez entre 0 et 100% pour contrôler de manière fine les différentes phases de votre animation.&lt;/p&gt;

&lt;p&gt;Une fois la définition faite, vous pouvez l’affecter à un élément en utilisant les sélecteurs CSS3 classiques et il ne vous restera plus qu’à configurer les options de l’animation. Pour cela, voici le type de bloc qu’il faut utiliser:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#id_de_l_element_html &lt;/span&gt;{
    &lt;span style="color: red"&gt;animation-name&lt;/span&gt;: &lt;span style="color: blue"&gt;nom_de_l_animation&lt;/span&gt;;
    &lt;span style="color: red"&gt;animation-duration&lt;/span&gt;: &lt;span style="color: blue"&gt;nombre_de_secondes s&lt;/span&gt;;
    &lt;span style="color: red"&gt;animation-iteration-count&lt;/span&gt;: &lt;span style="color: blue"&gt;nombre | infinite&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Pour mieux comprendre, observons un exemple réel. Tout d’abord, comme la spécification CSS3 Animations est toujours à l’état de brouillon, vous devez utiliser les bons préfixes des éditeurs de navigateurs. Prenons par exemple IE10 dont le préfixe est –ms donc. Regardons maintenant comme la tête de notre TB-TT est animée.&lt;/p&gt;

&lt;p&gt;Voici la déclaration de l’animation:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@-ms-keyframes &lt;/span&gt;rotate-skull {
    0% {
        &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(0deg)
    &lt;/span&gt;}
    25% {
        &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(15deg)
    &lt;/span&gt;}
    50% {
        &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(-5deg)
    &lt;/span&gt;}
    55% {
        &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(0deg)
    &lt;/span&gt;}
    75% {
        &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(-10deg)
    &lt;/span&gt;}
    100% {
        &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(0deg)
    &lt;/span&gt;}
} &lt;/pre&gt;

&lt;p&gt;Nous avons définit 6 étapes (0, 25, 50, 55, 75 &amp;amp; 100%) qui vont agir sur la propriétés CSS3 2D Transform en jouant sur la valeur de la rotation.&lt;/p&gt;

&lt;p&gt;Cette animation est alors appliquée via cette règle CSS:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#skull 
&lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-animation-name&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate-skull&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-animation-duration&lt;/span&gt;: &lt;span style="color: blue"&gt;7s&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-animation-iteration-count&lt;/span&gt;: &lt;span style="color: blue"&gt;infinite&lt;/span&gt;;       
}&lt;/pre&gt;

&lt;p&gt;On vise l’élément &amp;lt;div&amp;gt; ayant pour “id=&lt;strong&gt;skull&lt;/strong&gt;” et nous lui appliquons l’animation nommée “&lt;strong&gt;rotate-skull&lt;/strong&gt;” dessus. L’animation devra être terminée en &lt;strong&gt;7s&lt;/strong&gt; et devra être jouée un nombre &lt;strong&gt;infini&lt;/strong&gt; de fois.&lt;/p&gt;

&lt;p&gt;Voici le résultat animé si votre navigateur supporte CSS3 Animations :&lt;/p&gt;
&lt;iframe style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="200" src="http://david.blob.core.windows.net/html5/css3atat/AnimSkullATAT.htm" width="400" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;Nous aurions très bien pu d’ailleurs écrire cette règle de manière raccourcie ainsi :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#skull &lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-animation&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate-skull 7s infinite&lt;/span&gt;;
}&lt;/pre&gt;
L’animation sera lancée dès qu’une règle qui correspond sera appliquée. Vous pouvez donc jouer ou stopper une animation simplement par &lt;strong&gt;JavaScript&lt;/strong&gt; ou via CSS3 en travaillant sur &lt;strong&gt;les classes affectées à un tag&lt;/strong&gt;. 

&lt;h3&gt;Animations non linéaires&lt;/h3&gt;

&lt;p&gt;La propriété “animation-timing-function” doit être utilisée si vous souhaitez mettre en place des animations non linéaires. Vous pouvez même mixer plusieurs types d’animations entre chaque keyframe si vous le souhaitez.&lt;/p&gt;

&lt;p&gt;CSS3 animations va utiliser une &lt;a href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves"&gt;courbe de Bézier cubique&lt;/a&gt; pour “fluidifier” la transition en calculant une vitesse de progression différente tout au long de sa durée.&lt;/p&gt;

&lt;p&gt;Les valeurs suivantes sont supportées: &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;linear&lt;/em&gt;: Vitesse constante (comportement par défaut) &lt;/li&gt;

  &lt;li&gt;&lt;em&gt;cubic-bezier&lt;/em&gt;: La vitesse sera calculée grâce à une courbe de Bézier cubique définie par deux points de contrôles : P0 et P1 (Il faudra donc fournir 4 paramètres : P0x, P0y, P1x et P1y). &lt;/li&gt;

  &lt;li&gt;&lt;em&gt;ease&lt;/em&gt;: La vitesse sera calculée avec la formule suivante : cubic-bezier(0.25, 0.1, 0.25, 1) &lt;/li&gt;

  &lt;li&gt;&lt;em&gt;ease-in&lt;/em&gt;: La vitesse sera calculée avec la formule suivante : cubic-bezier(0.42, 0, 1, 1) &lt;/li&gt;

  &lt;li&gt;&lt;em&gt;ease-inout&lt;/em&gt;: La vitesse sera calculée avec la formule suivante : cubic-bezier(0.42, 0, 0.58, 1) &lt;/li&gt;

  &lt;li&gt;&lt;em&gt;ease-out&lt;/em&gt;: La vitesse sera calculée avec la formule suivante : cubic-bezier(0, 0, 0.58, 1) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Voici un outil de simulation écrit par &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2011/11/24/fr-introduction-224-css3-transitions.aspx"&gt;David Catuhe&lt;/a&gt; qui utilise du JavaScript 100% pur jus pour démontrer l’impact de chacune des fonctions non linéaires:&lt;/p&gt;
&lt;iframe style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="650" src="http://www.catuhe.com/msdn/transitions/easingfunctions.htm" width="100%"&gt;&lt;/iframe&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/strong&gt; cet outil utilise du SVG “in-line” supporté par Firefox, Chrome, Opera 11.60 &amp;amp; IE9/10. Il ne fonctionnera donc pas correctement sous Opera 11.50 et sous Safari sur iPad.&lt;/p&gt;

&lt;p&gt;Ce super outil utilise donc SVG. Vous pouvez alors même jouer avec votre souris à éditer la courbe de la fonction “custom”. Si vous souhaitez en savoir davantage sur cet outil, rendez-vous à nouveau sur l’article de David Catuhe sur les transitions.&lt;/p&gt;

&lt;p&gt;Si votre navigateur supporte les animations CSS3, regardons maintenant une démo toute simple utilisant &lt;strong&gt;les fonctions non linéaires pour bouger un élément &amp;lt;canvas&amp;gt; via CSS3&lt;/strong&gt; contenant un sprite animé.&lt;/p&gt;

&lt;p&gt;Voici le bloc de CSS3 Animations qui sera utilisé dans cette démo:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@-ms-keyframes &lt;/span&gt;demo {
    &lt;span style="color: red"&gt;&lt;font color="#000000"&gt;from&lt;/font&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;{
    &lt;font color="#ff0000"&gt;-ms-animation-timing-function&lt;/font&gt;: ease&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;translateX(0px)&lt;/span&gt;;
    }
    50% {
    &lt;span style="color: red"&gt;-ms-animation-timing-function&lt;/span&gt;: &lt;span style="color: blue"&gt;ease-in&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;translateX(300px)&lt;/span&gt;;
    }
    &lt;span style="color: maroon"&gt;to &lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-animation-timing-function&lt;/span&gt;: &lt;span style="color: blue"&gt;ease-inout&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;translateX(900px)&lt;/span&gt;;
    }
}

&lt;span style="color: maroon"&gt;#testCanvas
&lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-animation-delay&lt;/span&gt;: &lt;span style="color: blue"&gt;0s&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-animation-duration&lt;/span&gt;: &lt;span style="color: blue"&gt;6s&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-animation-iteration-count&lt;/span&gt;: &lt;span style="color: blue"&gt;infinite&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-animation-name&lt;/span&gt;: &lt;span style="color: blue"&gt;demo&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Ainsi que toutes les variations de préfixes pour pouvoir fonctionner sous Google Chrome &amp;amp; Mozilla Firefox. Voici le résultat en image:&lt;/p&gt;
&lt;iframe style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="90" src="http://david.blob.core.windows.net/html5/css3animcanvas/sprites.htm" width="1000"&gt;&lt;/iframe&gt;

&lt;p&gt;Si votre navigateur ne supporte pas CSS3 Animation mais uniquement canvas, l’animation du sprite en train de courir devrait être relativement statique car le personnage ne bougera pas sur toute la largeur de l’écran.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/b&gt; si vous souhaitez en savoir davantage sur &amp;lt;canvas&amp;gt; et l’animation de sprites, je vous invite à lire cet article : &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/07/22/jeux-html5-animation-de-sprites-dans-l-233-l-233-ment-canvas-gr-226-ce-224-easeljs.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/07/22/jeux-html5-animation-de-sprites-dans-l-233-l-233-ment-canvas-gr-226-ce-224-easeljs.aspx"&gt;Jeux HTML5: animation de sprites dans l’élément Canvas grâce à EaselJS&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Délais&lt;/h3&gt;

&lt;p&gt;Ta propriété “animation-delay” permet tout simplement de lancer l’animation un peu plus tard que prévu. Rien de bien sorcier.&lt;/p&gt;

&lt;h3&gt;Evènements&lt;/h3&gt;

&lt;p&gt;3 &lt;strong&gt;évènements&lt;/strong&gt; peuvent être levés pendant une animation. Ils sont nommés “Animation&lt;em&gt;Start&lt;/em&gt;”, “Animation&lt;i&gt;End&lt;/i&gt;” et “Animation&lt;em&gt;Iteration&lt;/em&gt;”. En fonction du navigateur, le nom correctement préfixé sera alors:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Chrome:&lt;i&gt; webkitAnimationEnd&lt;/i&gt; &lt;/li&gt;

  &lt;li&gt;Firefox: &lt;i&gt;mozAnimationEnd&lt;/i&gt; &lt;/li&gt;

  &lt;li&gt;Internet Explorer:&lt;i&gt; MSAnimationEnd&lt;/i&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ces évènements vous donneront les détails suivants:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;i&gt;animationName&lt;/i&gt;: nom de l’animation ayant levée l’évènement &lt;/li&gt;

  &lt;li&gt;&lt;i&gt;elapsedTime&lt;/i&gt;: le temps écoulé depuis le début de l’animation, en secondes &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;En voici un exemple d’usage pour IE10 :&lt;/p&gt;

&lt;pre class="code"&gt;elementToAnimate.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSAnimationEnd&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    alert(&lt;span style="color: maroon"&gt;&amp;quot;the end !&amp;quot;&lt;/span&gt;);
}, &lt;span style="color: blue"&gt;false&lt;/span&gt;);&lt;/pre&gt;

&lt;h3&gt;D’autres choses à propos des animations CSS3&lt;/h3&gt;

&lt;p&gt;Les animations CSS3 sont vraiment utiles pour 2 raisons principales :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;L’accélération matérielle:&lt;/b&gt; les animations CSS3 sont la plupart du temps gérées directement par le GPU et peuvent donc produire des résultats plus fluides. Cela peut donc être particulièrement intéressant pour les scénarios visant les périphériques mobiles. &lt;/li&gt;

  &lt;li&gt;&lt;b&gt;Meilleure séparation entre le code et le design&lt;/b&gt;: je sais qu’il existe de nombreux débats à ce sujet mais avec David, nous avons tendance à penser qu’un développeur ne devrait pas s’occuper des animations ou de toute autre chose ayant rapport au design autant que possible. De la même manière, un designer/graphiste ne devrait pas s’occuper de JavaScript. CSS3 offre donc cette possibilité et peut permettre aux designers/intégrateurs de travailler avec leurs outils classiques pour générer les animations sur les bons éléments, les changements entre écrans, etc. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pour illustrer l’importance des performances, sachez que le jeu HTML5 suivant &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-portage-complet-du-jeu-xna-vers-lt-canvas-gt-gr-226-ce-224-easeljs.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-portage-complet-du-jeu-xna-vers-lt-canvas-gt-gr-226-ce-224-easeljs.aspx"&gt;HTML5 Platformer&lt;/a&gt; que j’ai écrit et utilisant une balise &amp;lt;canvas&amp;gt; en plein écran tourne à 60 fps sous IE9/IE10 sur mon PC mais à maximum 10 fps sur un iPad 2. C’est tout simplement du au fait que le CPU de l’iPad soit bien moins puissant et qu’il n’utilise pas encore l’accélération matérielle sur le tag &amp;lt;canvas&amp;gt;. L’utilisation de transitions ou d’animations CSS3 pour animer plusieurs petits éléments &amp;lt;canvas&amp;gt; pourrait ainsi fournir un gain très net de performance pour ce jeu. Ne l’oubliez donc pas lorsque vous aurez un projet visant les périphériques mobiles !&lt;/p&gt;
&lt;a name="support"&gt;
  &lt;h2&gt;Support dans les navigateurs&lt;/h2&gt;
&lt;/a&gt;

&lt;p&gt;Depuis la Platform Preview 3 d’IE10 disponible au sein de &lt;a href="http://msdn.microsoft.com/en-us/windows/apps/br229516"&gt;Windows 8 Developer Preview&lt;/a&gt;, nous supportons les animations CSS3. Par ailleurs, comme vous pouvez le voir sur le rapport suivi généré depuis le site &lt;a href="http://caniuse.com/#search=CSS3 animation"&gt;caniuse.com&lt;/a&gt;, les animations CSS3 sont désormais supportées dans un large panel de navigateurs :&lt;/p&gt;

&lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8546.clip_5F00_image002_5F00_3DD1FC3C.jpg" /&gt;&lt;/p&gt;

&lt;p&gt;Mais comme la spécification n’est pas encore terminée (&lt;em&gt;working draft&lt;/em&gt;), vous devez utiliser les préfixes tels que –ms, –moz, –webkit et –o pour construire des applications compatibles cross-navigateurs.&lt;/p&gt;

&lt;p&gt;Mais la question qui devrait alors rapidement se poser est la suivante: comment prendre en charge les navigateurs ne supportant pas cette nouvelle fonctionnalité ?&lt;/p&gt;

&lt;p&gt;La première option consiste simplement à ne rien faire. Grâce à la beauté de la dégradation élégante (ou &lt;em&gt;graceful degradation&lt;/em&gt; en anglais), vous pouvez simplement offrir une image statique à l’utilisateur. Cela est par exemple le cas des 2 démonstrations d’Anthony : &lt;a href="http://www.anthonycalzadilla.com/i-twitty-the-fool/"&gt;I Twitty the Fool!&lt;/a&gt; et &lt;a href="http://www.anthonycalzadilla.com/css3-ATAT/"&gt;Pure CSS3 AT-AT Walker&lt;/a&gt; . Lorsqu’affichés sous IE9, vous avez l’impression de n’avoir qu’une image statique. Cependant, lorsque vous les affichez sous IE10, le même code affiche alors de belles animations. Les utilisateurs sous IE10 disposeront d’une version améliorée tant dis que les utilisateurs sous IE9 continueront de pouvoir bénéficier du site. Plus votre navigateur sera moderne, plus vous aurez de bonus visuels.&lt;/p&gt;

&lt;p&gt;La deuxième option consiste à détecter le support de la fonctionnalité via une librairie JavaScript comme Modernizr puis de tenter de fournir la même animation avec une autre librairie JavaScript qui s’occupera de copier les animations CSS3. C’est ce que nous appelons communément un mécanisme de “fallback”. Malheureusement, je n’ai pas réussi à trouver aujourd’hui une librairie fonctionnelle et complète pouvant totalement remplacer les animations CSS3 lorsque non supportées par le navigateur.&lt;/p&gt;

&lt;p&gt;Il n’en fallait pas plus pour me donner l’envie d’en écrire une petite plus ou moins spécialement étudiée pour notre exemple initial de TB-TT.&lt;/p&gt;
&lt;a name="fallback"&gt;
  &lt;h2&gt;Librairie JavaScript pour simuler les animations CSS3&lt;/h2&gt;
&lt;/a&gt;

&lt;p&gt;Les animations ne sont finalement qu’une série de transitions séparées pour une certaine durée définie par les keyframes. J’ai donc ré-utilisé les concepts introduits par David Catuhe dans sa librairie pour palier à l’absence éventuelle de CSS3 Transitions. Je vous laisse donc le soin de revoir son article détaillant les concepts derrière ce code si ce n’est déjà fait.&lt;/p&gt;

&lt;p&gt;De mon côté, j���ai ajouté le support des animations sur les propriétés rotation &amp;amp; translation de CSS3 2D tranform ainsi qu’une manière d’itérer à travers chacun des keyframes.&lt;/p&gt;

&lt;p&gt;Voici la partie principale de la librairie que vous devrez étudier :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Objet Animation 
// Il a besoin de l’élément HTML visé, du nom de l’animation, de sa durée, du nombre de fois qu’il faut la jouer et
// des keyframes contenus au sein d’un tableau
// Imaginez ainsi une animation comme une simple séquence de transitions jouées un certain nombre de fois
&lt;/span&gt;ANIMATIONSHELPER.animation = &lt;span style="color: blue"&gt;function &lt;/span&gt;(target, name, duration, iterationcount, keyframes) {
    &lt;span style="color: #006400"&gt;// on sauvegarde les valeurs de nos propriétés
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.name = name;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.duration = duration;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.iterationcount = iterationcount;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.target = target;

    &lt;span style="color: blue"&gt;var &lt;/span&gt;elapsedtime = 0;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;keyframeduration = 0;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;elapsedtime = 0;

    &lt;span style="color: #006400"&gt;// On transforme les pourcentages de chaque keyframe en une valeur de durée
    &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i = 0; i &amp;lt; keyframes.length; i++) {
        keyframeduration = ((keyframes[i].percentage * duration) / 100) - elapsedtime;
        keyframes[i].duration = keyframeduration;
        elapsedtime += keyframeduration;
    }

    &lt;span style="color: blue"&gt;this&lt;/span&gt;.currentTransition = { isPlaying: &lt;span style="color: blue"&gt;false &lt;/span&gt;};
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.keyframes = keyframes;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.keyframesCount = keyframes.length;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.currentKeyFrameIndex = 0;

    &lt;span style="color: #006400"&gt;// La fonction nextTransition() retourne la prochaine transition à jouer
    // en fonction du keyframe courant à lancer
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.nextTransition = &lt;span style="color: blue"&gt;function &lt;/span&gt;(keyframe, ease, customEaseP1X, customEaseP1Y, customEaseP2X, customEaseP2Y) {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;properties = [];
        &lt;span style="color: blue"&gt;var &lt;/span&gt;finalValues = [];
        &lt;span style="color: blue"&gt;var &lt;/span&gt;transition;

        &lt;span style="color: #006400"&gt;// Comparé au TRANSITIONSHELPER original de David Catuhe
        // Nous avons besoin de code spécifique supplémentaire pour jouer sur les valeurs de 2D Transform
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(keyframe.propertyToAnimate === &lt;span style="color: maroon"&gt;&amp;quot;transform&amp;quot;&lt;/span&gt;) {
            &lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i = 0; i &amp;lt; keyframe.transformType.length; i++) {
                properties.push(keyframe.transformType[i].type);
                &lt;span style="color: blue"&gt;if &lt;/span&gt;(keyframe.transformType[i].type == &lt;span style="color: maroon"&gt;&amp;quot;rotate&amp;quot;&lt;/span&gt;) {
                    finalValues.push({ deg: keyframe.transformType[i].value1 });
                }
                &lt;span style="color: blue"&gt;else &lt;/span&gt;{
                    finalValues.push({ x: keyframe.transformType[i].value1, y: keyframe.transformType[i].value2 });
                }
            }

            &lt;span style="color: #006400"&gt;// Création d’une nouvelle transition
            &lt;/span&gt;transition = {
                name: &lt;span style="color: blue"&gt;this&lt;/span&gt;.name + &lt;span style="color: blue"&gt;this&lt;/span&gt;.currentKeyFrameIndex,
                target: &lt;span style="color: blue"&gt;this&lt;/span&gt;.target,
                properties: properties,
                finalValues: finalValues,
                originalValues: ANIMATIONSHELPER.extractValues(target.style[ANIMATIONSHELPER.currentTransformProperty], &lt;span style="color: blue"&gt;this&lt;/span&gt;.name),
                duration: keyframe.duration,
                startDate: (&lt;span style="color: blue"&gt;new &lt;/span&gt;Date).getTime(),
                currentDate: (&lt;span style="color: blue"&gt;new &lt;/span&gt;Date).getTime(),
                ease: ease,
                customEaseP1X: customEaseP1X,
                customEaseP2X: customEaseP2X,
                customEaseP1Y: customEaseP1Y,
                customEaseP2Y: customEaseP2Y,
                isPlaying: &lt;span style="color: blue"&gt;true&lt;/span&gt;,
                type: &lt;span style="color: maroon"&gt;&amp;quot;transform&amp;quot;
            &lt;/span&gt;};

            &lt;span style="color: blue"&gt;return &lt;/span&gt;transition;
        }
        &lt;span style="color: #006400"&gt;// Si c’est une propriété simple à animer, on peut tout simplement utiliser le TRANSITIONSHELPER presque tel quel
        &lt;/span&gt;&lt;span style="color: blue"&gt;else &lt;/span&gt;{
            &lt;span style="color: blue"&gt;return &lt;/span&gt;TRANSITIONSHELPER.transition(&lt;span style="color: blue"&gt;this&lt;/span&gt;.target, keyframe.propertyToAnimate, keyframe.value, keyframe.duration, TRANSITIONSHELPER.easingFunctions.linear);
        }
    };

    &lt;span style="color: #006400"&gt;// chaque instance d’animation dispose d’une fonction tick
    // qui sera appelée toutes les 17 ms (pour tenter de viser les 60 fps)
    // Ce ticker surveille l’état de la transition en cours et 
    // en créé une nouvelle dès qu’elle est terminée ou morte
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.tick = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.iterationcount &amp;gt; 0) {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentTransition.isPlaying) {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.currentTransition = &lt;span style="color: blue"&gt;this&lt;/span&gt;.nextTransition(&lt;span style="color: blue"&gt;this&lt;/span&gt;.keyframes[&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentKeyFrameIndex], ANIMATIONSHELPER.easingFunctions.linear);
                &lt;span style="color: #006400"&gt;// Nous utilisons le ticker global de ANIMATIONSHELPER uniquement pour les transformations 2D
                // Sinon, on utilise celui de la librairie TRANSITIONSHELPER
                &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentTransition.type === &lt;span style="color: maroon"&gt;&amp;quot;transform&amp;quot;&lt;/span&gt;) {
                    ANIMATIONSHELPER.currentTransitions.push(&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentTransition);
                }
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.currentKeyFrameIndex++;

                &lt;span style="color: #006400"&gt;// Nous avons atteint le dernier keyframe (100%). On peut recommencer au début donc.
                &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentKeyFrameIndex &amp;gt;= &lt;span style="color: blue"&gt;this&lt;/span&gt;.keyframesCount) {
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.currentKeyFrameIndex = 0;
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.iterationcount--;
                }
            }
        }
    };
};&lt;/pre&gt;

&lt;p&gt;La 1ère partie du code parcourt la collection des keyframes pour calculer la durée exacte engendrée par chacun des pourcentages. On définit alors une fonction nextTransition() qui va construire dynamiquement la prochaine transition à jouer en se basant sur l’index courant dans la collection de keyframes associés à l’animation en cours. Pour finir, nous avons une function tick() qui surveille l’état de la transition actuellement affectée. Dès que cette dernière se termine, nous demandons la prochaine transition, on la pousse sur la pile des transitions à jouer et on bouge les différents indexes. &lt;/p&gt;

&lt;p&gt;La function tick() est rappelée grâce à ce code :&lt;/p&gt;

&lt;pre class="code"&gt;ANIMATIONSHELPER.launchAnimation = &lt;span style="color: blue"&gt;function &lt;/span&gt;(animation) {
    &lt;span style="color: #006400"&gt;// On lance le service global de ticker si nécessaire
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(ANIMATIONSHELPER.tickIntervalID == 0) {
        ANIMATIONSHELPER.tickIntervalID = setInterval(ANIMATIONSHELPER.tick, 17);
    }

    &lt;span style="color: #006400"&gt;// Petite closure pour lancer la méthode tick sur la bonne instance d’animation
    &lt;/span&gt;setInterval(&lt;span style="color: blue"&gt;function &lt;/span&gt;() { animation.tick(); }, 17);
};&lt;/pre&gt;

&lt;p&gt;Pour finir, nous avons ce type de code pour nous aider à fabriquer les keyframes :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Objet pour construire des keyframes génériques (et pas pour les CSS3 2D Transform donc)
&lt;/span&gt;ANIMATIONSHELPER.keyframe = &lt;span style="color: blue"&gt;function &lt;/span&gt;(percentage, propertyToAnimate, value) {
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.percentage = percentage;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.propertyToAnimate = propertyToAnimate;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.value = value;
};

&lt;span style="color: #006400"&gt;//Objet pour construire des keyframes dédiés aux rotations
&lt;/span&gt;ANIMATIONSHELPER.rotationkeyframe = &lt;span style="color: blue"&gt;function &lt;/span&gt;(percentage, value) {
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.percentage = percentage;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.propertyToAnimate = &lt;span style="color: maroon"&gt;&amp;quot;transform&amp;quot;&lt;/span&gt;;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.transformType = [];
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.transformType.push(&lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.transformType(&lt;span style="color: maroon"&gt;&amp;quot;rotate&amp;quot;&lt;/span&gt;, value));
};&lt;/pre&gt;

&lt;p&gt;Pour illustrer son usage, amusons-nous à refaire le 1er exemple d’animations simples effectuées sur la tête de notre TB-TT avec cette librairie :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// nombre de fois que vous souhaitez voir l’animation tourner
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;iterationsNumber = 100;

&lt;span style="color: blue"&gt;var &lt;/span&gt;skullElement = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;skull&amp;quot;&lt;/span&gt;);
&lt;span style="color: blue"&gt;var &lt;/span&gt;keyframes = [];
keyframes.push(&lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.rotationkeyframe(25, 15));
keyframes.push(&lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.rotationkeyframe(50, -5));
keyframes.push(&lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.rotationkeyframe(55, 0));
keyframes.push(&lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.rotationkeyframe(75, -10));
keyframes.push(&lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.rotationkeyframe(100, 0));

&lt;span style="color: blue"&gt;var &lt;/span&gt;animation1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.animation(skullElement, &lt;span style="color: maroon"&gt;&amp;quot;rotate-skull&amp;quot;&lt;/span&gt;, 7000, 
                                                iterationsNumber, keyframes);

ANIMATIONSHELPER.launchAnimation(animation1, ANIMATIONSHELPER.easingFunctions.linear);&lt;/pre&gt;

&lt;p&gt;Et voici le résultat animé qui devrait maintenant fonctionner dans tous les navigateurs supportant CSS3 2D Transform :&lt;/p&gt;
&lt;iframe style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="200" src="http://david.blob.core.windows.net/html5/css3atat/indexSkullJS.htm" width="400" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;Pour finir, si l’on revient sur la toute première démonstration au début de cet article, vous verrez qu’elle utilise Modernizr pour vérifier le support des animations CSS3. Si ce n’est pas le cas, on charge le code qui s’occupera de copier le comportement défini par les keyframes présents dans master.css, moz-master.css &amp;amp; ms-master.css :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// On vérifie le support des animations CSS3
&lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(!Modernizr.cssanimations) {
    &lt;span style="color: #006400"&gt;// Si ce n’est pas le cas, on invoque notre librairie JavaScript de secours 
    &lt;/span&gt;supportElement.innerHTML = &lt;span style="color: maroon"&gt;&amp;quot;CSS3 Animations &amp;lt;strong&amp;gt;are not supported&amp;lt;/strong&amp;gt;&amp;quot;&lt;/span&gt;;
    LoadJSAnimationsFallback();
}
&lt;span style="color: blue"&gt;else &lt;/span&gt;{
    &lt;span style="color: #006400"&gt;// Si CSS3 Animations est supportée, nous n’avons rien à faire. 
    // Les feuilles de style *master.css seront automatiquement appliquées et utilisées.
    &lt;/span&gt;supportElement.innerHTML = &lt;span style="color: maroon"&gt;&amp;quot;CSS3 Animations &amp;lt;strong&amp;gt;are supported&amp;lt;/strong&amp;gt;&amp;quot;&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;La fonction &lt;em&gt;LoadJSAnimationsFallback()&lt;/em&gt; est définie dans le fichier &lt;em&gt;jsfallback-master.js&lt;/em&gt; qui contient simplement les déclarations de keyframes ainsi que les 19 animations nécessaires à recréer le comportement défini par Anthony en pur CSS3. Avec cette approche, le designer doit donc potentiellement ré-écrire toutes ses règles en faisant appel à la librairie JavaScript. Une autre approche pourrait consister à parser l’un des fichiers CSS en le téléchargeant via une requête XHR puis d’en déduire dynamiquement les appels JavaScript à faire vers la librairie. Cela nécessite cependant bien plus de travail car il vous faut quasiment ré-implémenter l’ensemble de la spécification CSS3 Animations en JavaScript !&lt;/p&gt;

&lt;p&gt;Vous avez normalement maintenant une idée de la manière de créer une mécanisme de “fallback” pour supporter le plus grand nombre de navigateurs tout en commençant à utiliser les dernières spécifications CSS3.&lt;/p&gt;

&lt;p&gt;Vous pouvez télécharger les fichiers pour l’exemple principal de cet article ici : &lt;a title="http://david.blob.core.windows.net/html5/css3atat/CSS3ATATNonMinified.zip" href="http://david.blob.core.windows.net/html5/css3atat/CSS3ATATNonMinified.zip"&gt;http://david.blob.core.windows.net/html5/css3atat/CSS3ATATNonMinified.zip&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Il contient les versions non minimisées des fichiers JavaScript animationsHelper.js, transitionsHelper.js, jsfallback-master.js ainsi que les différentes déclinaisons des feuilles de style CSS3 pour les différentes préfixes.&lt;/p&gt;
&lt;a name="conclusion"&gt;
  &lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;/a&gt;

&lt;p&gt;Les animations CSS3 représente une technologie puissante pour repousser les applications HTML5 vers un nouveau niveau. Elles offrent des scénarios intéressants. Les designers/intégrateurs peuvent les utiliser pour créer une nouvelle génération d’expérience utilisateur avec des écrans rapides et fluides sans avoir besoin de faire appel à un développeur. Comme elles sont la plupart du temps accélérées matériellement, les développeurs doivent également malgré tout y jeter un œil. Pour finir, les 2 populations peuvent collaborer. Les designers pourraient concevoir une série d’animations prédéfinies répondant aux besoins les plus courants et offrant une expérience homogène. Les développeurs pourraient alors récupérer le fruit de ce travail pour en créer des librairies JavaScript qui implémenteront ces animations. Ces librairies pourraient alors offrir une manière transparente de fournir 2 implémentations sous-jacentes : de la génération dynamique d’animations CSS3 à la volée ou une version de secours en pur JavaScript pour les anciens navigateurs. &lt;/p&gt;

&lt;h3&gt;Pour aller plus loin&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Article sur les transitions CSS3 par David Catuhe: &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2011/11/24/fr-introduction-224-css3-transitions.aspx"&gt;Introduction aux transitions CSS3&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;Les spécifications CSS3 Animations officielles : &lt;a title="http://www.w3.org/TR/css3-animations/" href="http://www.w3.org/TR/css3-animations/"&gt;http://www.w3.org/TR/css3-animations/&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;Notre site IE Test Drive pour jouer avec les CSS3 animations: &lt;a title="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_animations.htm" href="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_animations.htm"&gt;http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_animations.htm&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;D’autres articles intéressants : 
    &lt;ul&gt;
      &lt;li&gt;Alsacréations : &lt;a title="http://www.alsacreations.com/tuto/lire/1299-timing-des-animations-et-des-transitions-en-css3.html" href="http://www.alsacreations.com/tuto/lire/1299-timing-des-animations-et-des-transitions-en-css3.html"&gt;Timing des animations et des transitions en CSS3&lt;/a&gt; &lt;/li&gt;

      &lt;li&gt;Les évènements sont relativement limités selon la spécification CSS3 Animations. Joe Lambert propose alors une solution intéressante pour lever un évènement sur chacun des keyframes pour mieux suivre le déroulement de l’animation : &lt;a href="http://blog.joelambert.co.uk/2011/05/20/css-animation-keyframe-events-javascript-solution/"&gt;CSS Animation Keyframe Events (Javascript solution)&lt;/a&gt;&amp;#160; &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;David Rousset&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10244424" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/CSS3/">CSS3</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/IE10/">IE10</category></item><item><title>Introduction to CSS3 Animations</title><link>http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-to-css3-animations.aspx</link><pubDate>Mon, 05 Dec 2011 23:08:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10244420</guid><dc:creator>David Rousset</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10244420</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-to-css3-animations.aspx#comments</comments><description>&lt;meta content="IE=edge" http-equiv="X-UA-Compatible" /&gt;&lt;script&gt;
$(function() {
// run the currently selected effect
function runEffect(target) {
// get effect type from 
var selectedEffect = "clip";

var options = {};

// run the effect
target.toggle(500 );
};

$("#properties").hide();
$("#types").hide();

// set effect from select menu value
$( "#propertiesLink" ).click(function() {
runEffect($("#properties"));
return false;
});

$( "#typesLink" ).click(function() {
runEffect($("#types"));
return false;
});
});
&lt;/script&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6443.TestAnimations_5F00_4312DF8D.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 0px 0px 10px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="TestAnimations" border="0" alt="TestAnimations" align="right" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2727.TestAnimations_5F00_thumb_5F00_59194B1F.jpg" width="300" height="201" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Today’s HTML5 applications can provide awesome experiences thanks to the new CSS3 specifications. One of them is &lt;b&gt;CSS3 Animations&lt;/b&gt;. It can help you building rich animations on HTML elements. This can provide interesting feedbacks to the users and enables fast &amp;amp; fluid UIs. As those new animations are most of time hardware accelerated by the GPU, they definitely raise up the quality bar of the new generation of HTML5 applications.&lt;/p&gt;  &lt;p&gt;According to the “CSS Animation Module Level 3” specification on the &lt;a href="http://www.w3.org/TR/css3-animations/"&gt;W3C site&lt;/a&gt;, CSS3 Animations &lt;i&gt;introduces defined animations, which specify the values that CSS properties will take over a given time interval. This specification is an extension to CSS Transitions&lt;/i&gt;.&lt;/p&gt;  &lt;p&gt;As CSS3 Animation is an &lt;b&gt;extension to CSS3 Transitions&lt;/b&gt;, you should first read the article of my colleague David Catuhe on Transitions here: &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2011/11/01/css3-transitions.aspx"&gt;Introduction to CSS3 Transitions&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;We’ll see in this article an interesting demo highlighting the potential of CSS3 animations, how to build simple animations &amp;amp; how to handle fallback in JavaScript:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="#intro"&gt;CSS3 Animations&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#support"&gt;Browsers Support&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#fallback"&gt;CSS3 Animations JavaScript fallback library&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#conclusion"&gt;Conclusion&lt;/a&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Let’s first start by quickly demonstrating what CSS3 Animations are. Here is a sample animation of a StarWars AT-AT which uses CSS3 Animations to animate parts of the transport (and which will fall back to JavaScript if your browser doesn’t support CSS3 Animations): &lt;/p&gt; &lt;iframe style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="570" src="http://david.blob.core.windows.net/html5/css3atat/index.htm" width="716" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;You can test this sample also in a separate window here: &lt;a title="http://david.blob.core.windows.net/html5/css3atat/index.htm" href="http://david.blob.core.windows.net/html5/css3atat/index.htm"&gt;http://david.blob.core.windows.net/html5/css3atat/index.htm&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; this sample has been tested successfully with native animations under IE10 PP3/PP4, Chrome 15, Firefox 8 &amp;amp; iPad 2 and with JS fallback under IE9 desktop &amp;amp; mobile (Windows Phone). For an unknown reason, it behaves in weird way under Opera 11.50 but works fine with the 11.60. Moreover, our lovely blogging platform is most of the time forcing the IE9 rendering engine via a meta tag. To force it back to the IE10 standards mode, press the F12 key and change the value of “Document Mode” back to IE10. Otherwise, view the demo in a separate window.&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;This sample is based on the awesome work done by &lt;a href="http://twitter.com/acalzadilla"&gt;Anthony Calzadilla&lt;/a&gt;. You can check other incredible demos on his website here: &lt;a href="http://www.anthonycalzadilla.com"&gt;http://www.anthonycalzadilla.com&lt;/a&gt; . I’m a huge fan of the &lt;a href="http://www.anthonycalzadilla.com/i-twitty-the-fool/"&gt;I twitty the fool&lt;/a&gt; sample using SVG &amp;amp; CSS3 Animation for instance. &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4643.wlEmoticon_2D00_winkingsmile_5F00_101C70F9.png" /&gt;&lt;/p&gt; &lt;a name="intro"&gt;   &lt;h2&gt;CSS3 Animations&lt;/h2&gt; &lt;/a&gt;  &lt;h3&gt;Introduction&lt;/h3&gt;  &lt;p&gt;Let’s first review on what you can play to build the animations. CSS3 Animations works basically on the same values as CSS3 Transition. &lt;/p&gt;  &lt;p&gt;Here they are: &lt;a id="typesLink"&gt;click here to display/hide them&lt;/a&gt;&lt;/p&gt;  &lt;ul id="types"&gt;   &lt;li&gt;&lt;strong&gt;color&lt;/strong&gt;: interpolated via red, green, blue and alpha components (treating each as a number, see below) &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;length&lt;/strong&gt;: interpolated as real numbers. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;percentage&lt;/strong&gt;: interpolated as real numbers. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;integer&lt;/strong&gt;: interpolated via discrete steps (whole numbers). The interpolation happens in real number space and is converted to an integer using &lt;code&gt;floor()&lt;/code&gt;. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;number&lt;/strong&gt;: interpolated as real (floating point) numbers. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;transform list&lt;/strong&gt;: see CSS Transforms specification: &lt;a href="http://www.w3.org/TR/css3-2d-transforms/"&gt;http://www.w3.org/TR/css3-2d-transforms/&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;rectangle&lt;/strong&gt;: interpolated via the x, y, width and height components (treating each as a number). &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;visibility&lt;/strong&gt;: interpolated via a discrete step. The interpolation happens in real number space between 0 and 1, where 1 is &amp;quot;visible&amp;quot; and all other values are &amp;quot;hidden&amp;quot;. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;shadow&lt;/strong&gt;: interpolated via the color, x, y and blur components (treating them as color and numbers where appropriate). In the case where there are lists of shadows, the shorter list is padded at the end with shadows whose color is transparent and all lengths (x, y, blur) are 0. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;gradient&lt;/strong&gt;: interpolated via the positions and colors of each stop. They must have the same type (radial or linear) and same number of stops in order to be animated. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;paint server&lt;/strong&gt; (SVG): interpolation is only supported between: gradient to gradient and color to color. They then work as above. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;space-separated list of above&lt;/strong&gt;: If the lists have the same number of items, each item in the list is interpolated using the rules above. Otherwise, no interpolation. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;a shorthand property&lt;/strong&gt;: If all the parts of a shorthand can be animated, then interpolation is performed as if each property was individually specified. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;And the following properties must be supported for animations: &lt;a id="propertiesLink"&gt;click here to display/hide them&lt;/a&gt;&lt;/p&gt;  &lt;ul id="properties"&gt;   &lt;li&gt;background-color (&lt;em&gt;color&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;background-image (&lt;em&gt;only gradients&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;background-position (&lt;em&gt;percentage and length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;border-bottom-color (&lt;em&gt;color&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;border-bottom-width (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;border-color (&lt;em&gt;color&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;border-left-color (&lt;em&gt;color&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;border-left-width (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;border-right-color (&lt;em&gt;color&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;border-right-width (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;border-spacing (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;border-top-color (&lt;em&gt;color&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;border-top-width (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;border-width (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;bottom (&lt;em&gt;length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;color (&lt;em&gt;color&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;crop (&lt;em&gt;rectangle&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;font-size (&lt;em&gt;length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;font-weight (&lt;em&gt;number&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;grid-* (&lt;em&gt;various&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;height (&lt;em&gt;length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;left (&lt;em&gt;length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;letter-spacing (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;line-height (&lt;em&gt;number, length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;margin-bottom (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;margin-left (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;margin-right (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;margin-top (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;max-height (&lt;em&gt;length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;max-width (&lt;em&gt;length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;min-height (&lt;em&gt;length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;min-width (&lt;em&gt;length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;opacity (&lt;em&gt;number&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;outline-color (&lt;em&gt;color&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;outline-offset (&lt;em&gt;integer&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;outline-width (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;padding-bottom (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;padding-left (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;padding-right (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;padding-top (&lt;em&gt;length&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;right (&lt;em&gt;length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;text-indent (&lt;em&gt;length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;text-shadow (&lt;em&gt;shadow&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;top (&lt;em&gt;length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;vertical-align (&lt;em&gt;keywords, length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;visibility (&lt;em&gt;visibility&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;width (&lt;em&gt;length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;word-spacing (&lt;em&gt;length and percentage&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;z-index (&lt;em&gt;integer&lt;/em&gt;) &lt;/li&gt;    &lt;li&gt;zoom (&lt;em&gt;number&lt;/em&gt;) &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;&lt;/h3&gt;  &lt;h3&gt;SVG&lt;/h3&gt;  &lt;p&gt;The properties of SVG objects are animatable when they are defined as &lt;b&gt;animatable:true&lt;/b&gt; in the SVG specification: &lt;a href="http://www.w3.org/TR/SVG/struct.html"&gt;http://www.w3.org/TR/SVG/struct.html&lt;/a&gt;. But at the time where this article is written, I didn’t manage to combine CSS3 Animation directly on SVG elements in any of the latest browsers versions. Today’s samples on the web are then doing a little trick: they are embedding SVG resources into different DIV animated by CSS3 like the &lt;a href="http://www.anthonycalzadilla.com/i-twitty-the-fool/"&gt;I twitty the fool&lt;/a&gt; sample. &lt;/p&gt;  &lt;h3&gt;Declarations&lt;/h3&gt;  &lt;p&gt;To declare an animation in a CSS file, here is the kind of generic code you’ll need to write:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@keyframes &lt;/span&gt;name_of_the_animation {
  &lt;span style="color: red"&gt;&lt;font color="#000000"&gt;from&lt;/font&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;{
   &lt;font color="#ff0000"&gt;property_to_animate:&lt;/font&gt; initial_value&lt;/span&gt;;
  }
  50% {
     &lt;span style="color: red"&gt;&lt;font color="#ff0000"&gt;property&lt;/font&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;font color="#ff0000"&gt;_to_animate:&lt;/font&gt; intermediate_value&lt;/span&gt;;
  }
  &lt;span style="color: maroon"&gt;to &lt;/span&gt;{
    &lt;span style="color: red"&gt;&lt;font color="#ff0000"&gt;property&lt;/font&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;font color="#ff0000"&gt;_to_animate:&lt;/font&gt; final_value&lt;/span&gt;;
  }
}&lt;/pre&gt;

&lt;p&gt;Which could also be written like that:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@keyframes &lt;/span&gt;name_of_the_animation {
  0% {
   &lt;span style="color: red"&gt;&lt;font color="#ff0000"&gt;property&lt;/font&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;font color="#ff0000"&gt;_to_animate:&lt;/font&gt; initial_value&lt;/span&gt;;
  }
  50% {
     &lt;span style="color: red"&gt;&lt;font color="#ff0000"&gt;property&lt;/font&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;font color="#ff0000"&gt;_to_animate:&lt;/font&gt; intermediate_value&lt;/span&gt;;
  }
  100% {
    &lt;span style="color: red"&gt;&lt;font color="#ff0000"&gt;property&lt;/font&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;font color="#ff0000"&gt;_to_animate:&lt;/font&gt; final_value&lt;/span&gt;;
  }
}&lt;/pre&gt;

&lt;p&gt;This animation definition declares 3 steps 0, 50 &amp;amp; 100%. You should at least set a &lt;i&gt;&lt;strong&gt;from&lt;/strong&gt;&lt;/i&gt; (or 0%) and a &lt;i&gt;&lt;strong&gt;to&lt;/strong&gt;&lt;/i&gt; (or 100%) steps to build a correct animation (minimum 2 steps thus). Once done, you may add as many keyframes as you’d like between 0 and 100% to handle precisely the various steps of your animations. &lt;/p&gt;

&lt;p&gt;Once the definition declared, you can affect it to an element using the classical CSS3 selectors and you’ll need also to configure the animation options. Here the kind of generic blocks you’ll see:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#id_of_the_html_element &lt;/span&gt;{
    &lt;span style="color: red"&gt;animation-name&lt;/span&gt;: &lt;span style="color: blue"&gt;name_of_the_animation&lt;/span&gt;;
    &lt;span style="color: red"&gt;animation-duration&lt;/span&gt;: &lt;span style="color: blue"&gt;number_of_seconds s&lt;/span&gt;;
    &lt;span style="color: red"&gt;animation-iteration-count&lt;/span&gt;: &lt;span style="color: blue"&gt;number | infinite&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;To better understand, let’s review a real sample. First of all, as the CSS3 Animations specification is still in a draft stage, you’ll need to use the appropriate vendor prefix. Let’s use IE10 as a sample with the –ms prefix then. Let’s now see how the head of our AT-AT is moving. &lt;/p&gt;

&lt;p&gt;Here’s the animation declaration:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@-ms-keyframes &lt;/span&gt;rotate-skull {
    0% {
        &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(0deg)
    &lt;/span&gt;}
    25% {
        &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(15deg)
    &lt;/span&gt;}
    50% {
        &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(-5deg)
    &lt;/span&gt;}
    55% {
        &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(0deg)
    &lt;/span&gt;}
    75% {
        &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(-10deg)
    &lt;/span&gt;}
    100% {
        &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(0deg)
    &lt;/span&gt;}
} &lt;/pre&gt;

&lt;p&gt;We’ve got 6 steps (0, 25, 50, 55, 75 &amp;amp; 100%) working on the CSS3 2D transform attributes by changing the value of the rotation.&lt;/p&gt;

&lt;p&gt;The animation is then applied via this CSS rule:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#skull 
&lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-animation-name&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate-skull&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-animation-duration&lt;/span&gt;: &lt;span style="color: blue"&gt;7s&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-animation-iteration-count&lt;/span&gt;: &lt;span style="color: blue"&gt;infinite&lt;/span&gt;;       
}&lt;/pre&gt;

&lt;p&gt;We’re targeting the &amp;lt;div&amp;gt; element having the “id=&lt;strong&gt;skull&lt;/strong&gt;” and we’re applying the animation named “&lt;b&gt;rotate-skull&lt;/b&gt;” on it. The animation will have to be completed in &lt;b&gt;7s&lt;/b&gt; and be played an &lt;b&gt;infinite&lt;/b&gt; number of times.&lt;/p&gt;

&lt;p&gt;Here is the living result if your browser supports CSS3 Animations:&lt;/p&gt;
&lt;iframe style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="200" src="http://david.blob.core.windows.net/html5/css3atat/AnimSkullATAT.htm" width="400" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;We could have written this rule in a shorter manner using the animation shorthand property:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;#skull &lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-animation&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate-skull 7s infinite&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;The animations will be triggered as soon as a matching rule is applied. You can then play or stop animations simply via &lt;b&gt;JavaScript&lt;/b&gt; or via CSS3 to play with the &lt;b&gt;classes affected to a tag&lt;/b&gt;.&lt;/p&gt;

&lt;h3&gt;Non-linear animations&lt;/h3&gt;

&lt;p&gt;The “animation-timing-function” property can be used if you want non-linear animations. You can even mix the type of timing functions during each keyframe. &lt;/p&gt;

&lt;p&gt;Basically, CSS3 animations will use &lt;a href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves"&gt;cubic bezier curve&lt;/a&gt; to smooth the animation by computing different speed over its duration.&lt;/p&gt;

&lt;p&gt;The following functions are supported:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;linear&lt;/em&gt;: Constant speed &lt;/li&gt;

  &lt;li&gt;&lt;em&gt;cubic-bezier&lt;/em&gt;: Speed will be computed according to a cubic bezier curve define by two control points : P0 and P1 (so you will have to define 4 values here : P0x, P0y and P1x, P1y. &lt;/li&gt;

  &lt;li&gt;&lt;em&gt;ease&lt;/em&gt;: Speed will be computed with cubic-bezier(0.25, 0.1, 0.25, 1) &lt;/li&gt;

  &lt;li&gt;&lt;em&gt;ease-in&lt;/em&gt;: Speed will be computed with cubic-bezier(0.42, 0, 1, 1) &lt;/li&gt;

  &lt;li&gt;&lt;em&gt;ease-inout&lt;/em&gt;: Speed will be computed with cubic-bezier(0.42, 0, 0.58, 1) &lt;/li&gt;

  &lt;li&gt;&lt;em&gt;ease-out&lt;/em&gt;: Speed will be computed with cubic-bezier(0, 0, 0.58, 1) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is a simulation tool written by &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2011/11/01/css3-transitions.aspx"&gt;David Catuhe&lt;/a&gt; that uses pure JavaScript to show the impact of each timing function:&lt;/p&gt;
&lt;iframe style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="650" src="http://www.catuhe.com/msdn/transitions/easingfunctions.htm" width="100%"&gt;&lt;/iframe&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; this tool uses in-line SVG supported by Firefox, Chrome, Opera 11.60 &amp;amp; IE9/10. It won’t work properly under Opera 11.50 &amp;amp; Safari on iPad thus.&lt;/p&gt;

&lt;p&gt;This is an awesome tool using SVG. You can even play with your mouse on the custom function to edit the curve. If you’d like to know more about this tool, please again have a look to David’s article.&lt;/p&gt;

&lt;p&gt;If your browser supports CSS3 animations, let’s now see a simple demo using &lt;strong&gt;easing functions to animate a canvas tag&lt;/strong&gt; containing an animated sprite with CSS3.&lt;/p&gt;

&lt;p&gt;Here is the CSS3 animations code that will be used in this demo:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@-ms-keyframes &lt;/span&gt;demo {
    &lt;span style="color: red"&gt;&lt;font color="#000000"&gt;from&lt;/font&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;{
    &lt;font color="#ff0000"&gt;-ms-animation-timing-function&lt;/font&gt;: ease&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;translateX(0px)&lt;/span&gt;;
    }
    50% {
    &lt;span style="color: red"&gt;-ms-animation-timing-function&lt;/span&gt;: &lt;span style="color: blue"&gt;ease-in&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;translateX(300px)&lt;/span&gt;;
    }
    &lt;span style="color: maroon"&gt;to &lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-animation-timing-function&lt;/span&gt;: &lt;span style="color: blue"&gt;ease-inout&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-transform&lt;/span&gt;: &lt;span style="color: blue"&gt;translateX(900px)&lt;/span&gt;;
    }
}

&lt;span style="color: maroon"&gt;#testCanvas
&lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-animation-delay&lt;/span&gt;: &lt;span style="color: blue"&gt;0s&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-animation-duration&lt;/span&gt;: &lt;span style="color: blue"&gt;6s&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-animation-iteration-count&lt;/span&gt;: &lt;span style="color: blue"&gt;infinite&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-animation-name&lt;/span&gt;: &lt;span style="color: blue"&gt;demo&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;As well as all the vendor prefixes variations to make it works also in Google Chrome &amp;amp; Mozilla Firefox. And here’s the living output:&lt;/p&gt;
&lt;iframe style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="90" src="http://david.blob.core.windows.net/html5/css3animcanvas/sprites.htm" width="1000"&gt;&lt;/iframe&gt;

&lt;p&gt;If your browser doesn’t support CSS3 Animation but support canvas, the sprite’s running animation should be displayed but the character won’t move through the width of the screen. &lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/b&gt; if you’d like to know more about canvas and sprites animation, you can have a look to this article: &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/07/21/html5-gaming-animating-sprites-in-canvas-with-easeljs.aspx"&gt;HTML5 Gaming: animating sprites in Canvas with EaselJS&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Delay&lt;/h3&gt;

&lt;p&gt;The “animation-delay” property simply allows an animation to begin execution some time after it is applied.&lt;/p&gt;

&lt;h3&gt;Events&lt;/h3&gt;

&lt;p&gt;3 &lt;b&gt;events&lt;/b&gt; could be raised during an animation. They are named “Animation&lt;em&gt;Start&lt;/em&gt;”, “Animation&lt;i&gt;End&lt;/i&gt;” and “Animation&lt;em&gt;Iteration&lt;/em&gt;”. Depending on your browser, the correct name will be for instance:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Chrome:&lt;i&gt; webkitAnimationEnd&lt;/i&gt; &lt;/li&gt;

  &lt;li&gt;Firefox: &lt;i&gt;mozAnimationEnd&lt;/i&gt; &lt;/li&gt;

  &lt;li&gt;Internet Explorer:&lt;i&gt; MSAnimationEnd&lt;/i&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The event will give you the following details:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;i&gt;animationName&lt;/i&gt;: name of the animation which raised the event &lt;/li&gt;

  &lt;li&gt;&lt;i&gt;elapsedTime&lt;/i&gt;: the amount of time the animation has been running, in seconds &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an usage sample for IE10:&lt;/p&gt;

&lt;pre class="code"&gt;elementToAnimate.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSAnimationEnd&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    alert(&lt;span style="color: maroon"&gt;&amp;quot;the end !&amp;quot;&lt;/span&gt;);
}, &lt;span style="color: blue"&gt;false&lt;/span&gt;);&lt;/pre&gt;

&lt;h3&gt;More about CSS3 animations&lt;/h3&gt;

&lt;p&gt;CSS3 animations are really useful for 2 main reasons:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;Hardware acceleration:&lt;/b&gt; CSS3 Animations are most of the time directly handled by the GPU and could produce smoother results. This could then be a very interesting approach for mobile devices. &lt;/li&gt;

  &lt;li&gt;&lt;b&gt;Better separation between code and design&lt;/b&gt;: I know there is some debates on this point but with David, we think that a developer shouldn’t be aware of animations or anything related to design as much as possible. In the same way the designer/artist must not be aware of JavaScript. CSS3 offers then this possibility and could let the designers work with their classical tools to generate the appropriate animations on elements, between screens, etc. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To highlight this importance in performance, the following HTML5 game I wrote using a full frame &amp;lt;canvas&amp;gt;: &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx"&gt;HTML5 Platformer&lt;/a&gt; run at 60 fps in IE9/IE10 on my PC but at 10 fps max on a iPad 2. This is because its CPU is much more limited and the iPad is currently not hardware-accelerating &amp;lt;canvas&amp;gt;. Using CSS3 Transitions/Animations to animate several smaller &amp;lt;canvas&amp;gt; elements could provide a huge performance boost for this game. Think about it when you’re targeting mobile devices!&lt;/p&gt;
&lt;a name="support"&gt;
  &lt;h2&gt;Browsers Support&lt;/h2&gt;
&lt;/a&gt;

&lt;p&gt;Since the Platform Preview 3 of IE10 available in the &lt;a href="http://msdn.microsoft.com/en-us/windows/apps/br229516"&gt;Windows Developer Preview&lt;/a&gt;, we’re supporting CSS3 Animations. And as you can see on the following report produced by &lt;a href="http://caniuse.com/#search=CSS3 animation"&gt;caniuse.com&lt;/a&gt;, the CSS3 animations are now supported on a wide range of browsers:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8546.clip_5F00_image002_5F00_3DD1FC3C.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6303.clip_5F00_image002_5F00_thumb_5F00_0EBF9A98.jpg" width="761" height="275" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But as the specification is not finished yet (&lt;em&gt;working draft&lt;/em&gt;), you must use vendor’s prefixes such as –ms-, –moz-, –webkit-, –o- to make a cross-browsers compatible application.&lt;/p&gt;

&lt;p&gt;But the question could be: how to handle browsers that don’t support this new feature?&lt;/p&gt;

&lt;p&gt;First option is to just do nothing. Thanks to the beauty of graceful degradation, you could just let the user only see a static image if you’ve worked correctly. This is for instance the case of these 2 original samples of Anthony: &lt;a href="http://www.anthonycalzadilla.com/i-twitty-the-fool/"&gt;I Twitty the Fool!&lt;/a&gt; and &lt;a href="http://www.anthonycalzadilla.com/css3-ATAT/"&gt;Pure CSS3 AT-AT Walker&lt;/a&gt; . When watched in IE9, it looks like we only have a static image. When watched in IE10, the very same code shows nice animations. IE10 users will then have an enhanced version while IE9 will still be able to view and use properly the website. The more modern your browser is, the more visual bonus you will have.&amp;#160; &lt;/p&gt;

&lt;p&gt;The second option is to detect the feature via a JS library like Modernizr and try to offer the same animation via a JavaScript library that will mimic the animations. This is what we usually call a fallback mechanism. Unfortunately, I haven’t found today a working &amp;amp; complete JS library that could replace CSS3 animations when not supported by the browser.&lt;/p&gt;

&lt;p&gt;I have then written a sample JS library more or less specifically designed for the AT-AT sample.&lt;/p&gt;
&lt;a name="fallback"&gt;
  &lt;h2&gt;CSS3 Animations JavaScript fallback library&lt;/h2&gt;
&lt;/a&gt;

&lt;p&gt;Animations are nothing more than a series of transitions separated by a certain duration defined via the keyframes. I’ve then reused the concepts built by David Catuhe in his transitions helper library. I let you reviewing his article to check the base of the concepts behind the code.&lt;/p&gt;

&lt;p&gt;On my side, I’ve added some support to animate the CSS3 2D Transform rotation &amp;amp; translation values and a way to iterate through the keyframes. &lt;/p&gt;

&lt;p&gt;Here is the main part of the library you need to review:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Animation object
// It need the HTML targeted element, the name of the animation, its duration &amp;amp; iteration count and
// the keyframes contained in an array object
// View the animation simply as a sequence of transitions played a certain number of times
&lt;/span&gt;ANIMATIONSHELPER.animation = &lt;span style="color: blue"&gt;function &lt;/span&gt;(target, name, duration, iterationcount, keyframes) {
    &lt;span style="color: #006400"&gt;// saving the properties values
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.name = name;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.duration = duration;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.iterationcount = iterationcount;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.target = target;

    &lt;span style="color: blue"&gt;var &lt;/span&gt;elapsedtime = 0;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;keyframeduration = 0;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;elapsedtime = 0;

    &lt;span style="color: #006400"&gt;// Transforming the percentage of each keyframe into duration value
    &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i = 0; i &amp;lt; keyframes.length; i++) {
        keyframeduration = ((keyframes[i].percentage * duration) / 100) - elapsedtime;
        keyframes[i].duration = keyframeduration;
        elapsedtime += keyframeduration;
    }

    &lt;span style="color: blue"&gt;this&lt;/span&gt;.currentTransition = { isPlaying: &lt;span style="color: blue"&gt;false &lt;/span&gt;};
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.keyframes = keyframes;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.keyframesCount = keyframes.length;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.currentKeyFrameIndex = 0;

    &lt;span style="color: #006400"&gt;// The nextTransition() function return the next transition to run
    // based on the current keyframe to play
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.nextTransition = &lt;span style="color: blue"&gt;function &lt;/span&gt;(keyframe, ease, customEaseP1X, customEaseP1Y, customEaseP2X, customEaseP2Y) {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;properties = [];
        &lt;span style="color: blue"&gt;var &lt;/span&gt;finalValues = [];
        &lt;span style="color: blue"&gt;var &lt;/span&gt;transition;

        &lt;span style="color: #006400"&gt;// Compared to the original TRANSITIONSHELPER of David Catuhe
        // We need a specific code to play with the CSS3 2D Transform properties values
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(keyframe.propertyToAnimate === &lt;span style="color: maroon"&gt;&amp;quot;transform&amp;quot;&lt;/span&gt;) {
            &lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i = 0; i &amp;lt; keyframe.transformType.length; i++) {
                properties.push(keyframe.transformType[i].type);
                &lt;span style="color: blue"&gt;if &lt;/span&gt;(keyframe.transformType[i].type == &lt;span style="color: maroon"&gt;&amp;quot;rotate&amp;quot;&lt;/span&gt;) {
                    finalValues.push({ deg: keyframe.transformType[i].value1 });
                }
                &lt;span style="color: blue"&gt;else &lt;/span&gt;{
                    finalValues.push({ x: keyframe.transformType[i].value1, y: keyframe.transformType[i].value2 });
                }
            }

            &lt;span style="color: #006400"&gt;// Create a new transition
            &lt;/span&gt;transition = {
                name: &lt;span style="color: blue"&gt;this&lt;/span&gt;.name + &lt;span style="color: blue"&gt;this&lt;/span&gt;.currentKeyFrameIndex,
                target: &lt;span style="color: blue"&gt;this&lt;/span&gt;.target,
                properties: properties,
                finalValues: finalValues,
                originalValues: ANIMATIONSHELPER.extractValues(target.style[ANIMATIONSHELPER.currentTransformProperty], &lt;span style="color: blue"&gt;this&lt;/span&gt;.name),
                duration: keyframe.duration,
                startDate: (&lt;span style="color: blue"&gt;new &lt;/span&gt;Date).getTime(),
                currentDate: (&lt;span style="color: blue"&gt;new &lt;/span&gt;Date).getTime(),
                ease: ease,
                customEaseP1X: customEaseP1X,
                customEaseP2X: customEaseP2X,
                customEaseP1Y: customEaseP1Y,
                customEaseP2Y: customEaseP2Y,
                isPlaying: &lt;span style="color: blue"&gt;true&lt;/span&gt;,
                type: &lt;span style="color: maroon"&gt;&amp;quot;transform&amp;quot;
            &lt;/span&gt;};

            &lt;span style="color: blue"&gt;return &lt;/span&gt;transition;
        }
        &lt;span style="color: #006400"&gt;// If it's a classic property to animate, we're using more or less the TRANSITIONSHELPER as-is
        &lt;/span&gt;&lt;span style="color: blue"&gt;else &lt;/span&gt;{
            &lt;span style="color: blue"&gt;return &lt;/span&gt;TRANSITIONSHELPER.transition(&lt;span style="color: blue"&gt;this&lt;/span&gt;.target, keyframe.propertyToAnimate, keyframe.value, keyframe.duration, TRANSITIONSHELPER.easingFunctions.linear);
        }
    };

    &lt;span style="color: #006400"&gt;// each animation object has a tick function
    // that will be called every 17 ms (to target 60 fps)
    // This ticker is monitoring the current state of the transition and
    // create a new transition as soon as the old one is finished/dead
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.tick = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.iterationcount &amp;gt; 0) {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentTransition.isPlaying) {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.currentTransition = &lt;span style="color: blue"&gt;this&lt;/span&gt;.nextTransition(&lt;span style="color: blue"&gt;this&lt;/span&gt;.keyframes[&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentKeyFrameIndex], ANIMATIONSHELPER.easingFunctions.linear);
                &lt;span style="color: #006400"&gt;// We're using our own global ticker only for the 2D transformations
                // Otherwise, we're using the one from the TRANSITIONSHELPER library
                &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentTransition.type === &lt;span style="color: maroon"&gt;&amp;quot;transform&amp;quot;&lt;/span&gt;) {
                    ANIMATIONSHELPER.currentTransitions.push(&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentTransition);
                }
                &lt;span style="color: blue"&gt;this&lt;/span&gt;.currentKeyFrameIndex++;

                &lt;span style="color: #006400"&gt;// We've reached the last keyframe (100%). We're starting back from the beginning
                &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.currentKeyFrameIndex &amp;gt;= &lt;span style="color: blue"&gt;this&lt;/span&gt;.keyframesCount) {
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.currentKeyFrameIndex = 0;
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;.iterationcount--;
                }
            }
        }
    };
};&lt;/pre&gt;

&lt;p&gt;The first part of the code is iterating through each keyframe to compute the exact duration specified by each percentage. We’re then defining a nextTransition() function that will dynamically build the next transition to play based on the current index into the keyframes collection. At last, we’ve got a tick() function that will monitor the current state of the transition applied. Once the transition is finished or dead, it asks for the next transition, push it to the stack of transitions to be played and moves the indexes. &lt;/p&gt;

&lt;p&gt;This tick() function is called thanks to this code:&lt;/p&gt;

&lt;pre class="code"&gt;ANIMATIONSHELPER.launchAnimation = &lt;span style="color: blue"&gt;function &lt;/span&gt;(animation) {
    &lt;span style="color: #006400"&gt;// Launching the tick service if required
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(ANIMATIONSHELPER.tickIntervalID == 0) {
        ANIMATIONSHELPER.tickIntervalID = setInterval(ANIMATIONSHELPER.tick, 17);
    }

    &lt;span style="color: #006400"&gt;// Little closure to launch the tick method on the appropriate animation instance
    &lt;/span&gt;setInterval(&lt;span style="color: blue"&gt;function &lt;/span&gt;() { animation.tick(); }, 17);
};&lt;/pre&gt;

&lt;p&gt;At last, we have this kind of code that helps us building the keyframes:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Object to build a new generic keyframe (not working on the CSS3 2D Transform properties thus)
&lt;/span&gt;ANIMATIONSHELPER.keyframe = &lt;span style="color: blue"&gt;function &lt;/span&gt;(percentage, propertyToAnimate, value) {
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.percentage = percentage;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.propertyToAnimate = propertyToAnimate;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.value = value;
};

&lt;span style="color: #006400"&gt;//Objects to build specific rotation keyframes
&lt;/span&gt;ANIMATIONSHELPER.rotationkeyframe = &lt;span style="color: blue"&gt;function &lt;/span&gt;(percentage, value) {
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.percentage = percentage;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.propertyToAnimate = &lt;span style="color: maroon"&gt;&amp;quot;transform&amp;quot;&lt;/span&gt;;
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.transformType = [];
    &lt;span style="color: blue"&gt;this&lt;/span&gt;.transformType.push(&lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.transformType(&lt;span style="color: maroon"&gt;&amp;quot;rotate&amp;quot;&lt;/span&gt;, value));
};&lt;/pre&gt;

&lt;p&gt;To highlight its usage, let’s recreate the previous simple CSS3 Animation skull sample with this library :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// number of times you'd like the animations to be run
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;iterationsNumber = 100;

&lt;span style="color: blue"&gt;var &lt;/span&gt;skullElement = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;skull&amp;quot;&lt;/span&gt;);
&lt;span style="color: blue"&gt;var &lt;/span&gt;keyframes = [];
keyframes.push(&lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.rotationkeyframe(25, 15));
keyframes.push(&lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.rotationkeyframe(50, -5));
keyframes.push(&lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.rotationkeyframe(55, 0));
keyframes.push(&lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.rotationkeyframe(75, -10));
keyframes.push(&lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.rotationkeyframe(100, 0));

&lt;span style="color: blue"&gt;var &lt;/span&gt;animation1 = &lt;span style="color: blue"&gt;new &lt;/span&gt;ANIMATIONSHELPER.animation(skullElement, &lt;span style="color: maroon"&gt;&amp;quot;rotate-skull&amp;quot;&lt;/span&gt;, 7000, 
                                                iterationsNumber, keyframes);

ANIMATIONSHELPER.launchAnimation(animation1, ANIMATIONSHELPER.easingFunctions.linear);&lt;/pre&gt;

&lt;p&gt;And here is the result that will now work in every browser supporting CSS3 2D Transform:&lt;/p&gt;
&lt;iframe style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="200" src="http://david.blob.core.windows.net/html5/css3atat/indexSkullJS.htm" width="400" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;At last, the very first sample demonstrated at the beginning of this article uses Modernizr to check the support for CSS3 Animations. If it’s not the case, it loads the code that will mimic the keyframes defined in the file master.css, moz-master.css &amp;amp; ms-master.css :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// Checking if CSS3 animations is supported
&lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(!Modernizr.cssanimations) {
    &lt;span style="color: #006400"&gt;// if so, we can use our JS fallback library
    &lt;/span&gt;supportElement.innerHTML = &lt;span style="color: maroon"&gt;&amp;quot;CSS3 Animations &amp;lt;strong&amp;gt;are not supported&amp;lt;/strong&amp;gt;&amp;quot;&lt;/span&gt;;
    LoadJSAnimationsFallback();
}
&lt;span style="color: blue"&gt;else &lt;/span&gt;{
    &lt;span style="color: #006400"&gt;// if CSS3 animation is supported, we have nothing to do. 
    // The *master.css stylesheets will be automatically applied &amp;amp; used.
    &lt;/span&gt;supportElement.innerHTML = &lt;span style="color: maroon"&gt;&amp;quot;CSS3 Animations &amp;lt;strong&amp;gt;are supported&amp;lt;/strong&amp;gt;&amp;quot;&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;The &lt;em&gt;LoadJSAnimationsFallback()&lt;/em&gt; function is defined into &lt;em&gt;jsfallback-master.js&lt;/em&gt; which simply contains all the keyframes declarations and the 19 animations needed to mimic the behavior created by Anthony in pure CSS3. In this approach, the designer then needs to rewrite all rules using the library. Another approach could be to parse one of the CSS file using an XHR call and to create dynamically the JavaScript calls to the library. This needs more work as you almost need to reimplement the CSS3 animations specifications in JavaScript! &lt;/p&gt;

&lt;p&gt;You now have an idea on the way to build a fallback mechanism to support more browsers while starting to use the latest CSS3 specifications. &lt;/p&gt;

&lt;p&gt;You can download the files for the main sample here: &lt;a title="http://david.blob.core.windows.net/html5/css3atat/CSS3ATATNonMinified.zip" href="http://david.blob.core.windows.net/html5/css3atat/CSS3ATATNonMinified.zip"&gt;http://david.blob.core.windows.net/html5/css3atat/CSS3ATATNonMinified.zip&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It contains the unminified versions of the animationsHelper.js, transitionsHelper.js, jsfallback-master.js JavaScript files as well as the various CSS3 declinaison files for the main vendors prefixes. &lt;/p&gt;
&lt;a name="conclusion"&gt;
  &lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;/a&gt;

&lt;p&gt;CSS3 Animations is a powerful technology to push HTML5 applications to a new level. It offers interesting scenarios. Designers could use it to create a new generation of UI screens with smooth &amp;amp; fluid animations without the need of developers. As it’s hardware-accelerated most of the time, developers should also pay attention to this specification. At last, both could collaborate. Designers could work on a series of predefined animations covering most scenarios. Developers could then create JavaScript libraries that will implement those animations. This library could offer in a transparent way 2 implementations: a dynamic generation of CSS3 on the fly or a fallback for older browsers. &lt;/p&gt;

&lt;h3&gt;Going further&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Article about CSS3 Transitions by David Catuhe: &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2011/11/01/css3-transitions.aspx"&gt;Introduction to CSS3 Transitions&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;CSS3 Animations specifications: &lt;a title="http://www.w3.org/TR/css3-animations/" href="http://www.w3.org/TR/css3-animations/"&gt;http://www.w3.org/TR/css3-animations/&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;IE Test Drive on CSS3 animations: &lt;a title="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_animations.htm" href="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_animations.htm"&gt;http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_animations.htm&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;Others useful posts: 
    &lt;ul&gt;
      &lt;li&gt;Events are relatively limited in the CSS3 Animation spec. Joe Lambert is proposing an interesting solution to trigger events on each keyframe: &lt;a href="http://blog.joelambert.co.uk/2011/05/20/css-animation-keyframe-events-javascript-solution/"&gt;CSS Animation Keyframe Events (Javascript solution)&lt;/a&gt;&amp;#160; &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;David Rousset&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10244420" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/CSS3/">CSS3</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/IE10/">IE10</category></item><item><title>Vidéo, slides et ressources de ma session sur le développement d’un jeu de plateforme en HTML5</title><link>http://blogs.msdn.com/b/davrous/archive/2011/11/21/vid-233-o-slides-et-ressources-de-ma-session-sur-le-d-233-veloppement-d-un-jeu-de-plateforme-en-html5.aspx</link><pubDate>Mon, 21 Nov 2011 18:14:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10239204</guid><dc:creator>David Rousset</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10239204</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2011/11/21/vid-233-o-slides-et-ressources-de-ma-session-sur-le-d-233-veloppement-d-un-jeu-de-plateforme-en-html5.aspx#comments</comments><description>&lt;script src="http://david.blob.core.windows.net/videos/video-js/video.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;
    
 VideoJS.setupAllWhenReady();
&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;  &lt;p&gt;Si vous n’avez pas pu assister à ma session sur le développement d’un jeu de plateforme en HTML5/Canvas pendant notre évènement Microsoft Days 2011 ou si vous souhaitez revoir la session, en voici un enregistrement :&lt;/p&gt; &lt;!-- Begin VideoJS --&gt; &lt;div class="video-js-box"&gt;     &lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;     &lt;video id="example_video_1" class="video-js" width="640" height="360" controls="controls"
        preload="auto" poster="http://david.blob.core.windows.net/videos/DevJeuxHTML5.png"&gt;         &lt;source src="http://david.blob.core.windows.net/videos/DevelopperUnJeuEnHTML5.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /&gt;         &lt;source src="http://david.blob.core.windows.net/videos/DevelopperUnJeuEnHTML5.webm" type='video/webm; codecs="vp8, vorbis"' /&gt;         &lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;         &lt;object id="flash_fallback_1" class="vjs-flash-fallback" width="640" height="360"
            type="application/x-shockwave-flash" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"&gt;             &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;             &lt;param name="allowfullscreen" value="true" /&gt;             &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/DevJeuxHTML5.png&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/DevelopperUnJeuEnHTML5.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;             &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;             &lt;img src="http://david.blob.core.windows.net/videos/DevJeuxHTML5.png" width="640" height="360" alt="Poster Image" title="No video playback capabilities." /&gt;         &lt;/object&gt;     &lt;/video&gt;     &lt;!-- Download links provided for devices that can't play video in the browser. --&gt;     &lt;p class="vjs-no-video"&gt;         &lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/videos/DevelopperUnJeuEnHTML5.mp4"&gt;             MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/DevelopperUnJeuEnHTML5.webm"&gt;WebM&lt;/a&gt;&lt;br&gt;         &lt;!-- Support VideoJS by keeping this link. --&gt;         &lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS     &lt;/p&gt; &lt;/div&gt; &lt;!-- End VideoJS --&gt;  &lt;p&gt;   &lt;br /&gt;Au format HTML5 &lt;strong&gt;&amp;lt;video&amp;gt;&lt;/strong&gt; h264/webm bien sûr. J’utilise d’ailleurs au passage le player &lt;a href="http://videojs.com/"&gt;VideoJS&lt;/a&gt; que je vous conseille et qui propose de jolies CSS et un fallback automatique pour les anciens navigateurs.&lt;/p&gt;  &lt;p&gt;Voici les &lt;strong&gt;exemples que je vous ai montrés pendant cette heure&lt;/strong&gt; de session :&lt;/p&gt;  &lt;p&gt;- Pour comparer les performances d’animations entre SVG et Canvas sur vos navigateurs : &lt;a href="http://themaninblue.com/experiment/AnimationBenchmark/canvas/?particles=1000"&gt;1000 balles en Canvas&lt;/a&gt; et &lt;a href="http://themaninblue.com/experiment/AnimationBenchmark/svg/?particles=1000"&gt;1000 balles en SVG&lt;/a&gt;.     &lt;br /&gt;- Les framework de jeux &lt;a href="http://www.melonjs.org/"&gt;MelonJS&lt;/a&gt; (qui marche désormais sous IE9), &lt;a href="http://impactjs.com/"&gt;ImpactJS&lt;/a&gt; avec cette &lt;a href="http://html5-benchmark.com/"&gt;démo/benchmark&lt;/a&gt; et &lt;a href="http://easeljs.com/"&gt;EaselJS&lt;/a&gt; avec ce jeu de Tower Defense : &lt;a href="http://www.pirateslovedaisies.com/"&gt;Pirates Love Daisies&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Ensuite, cette session reprenais surtout en très grande partie &lt;strong&gt;les 3 tutoriaux&lt;/strong&gt; que j’ai publiés ici :&lt;/p&gt;  &lt;p&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/07/22/jeux-html5-animation-de-sprites-dans-l-233-l-233-ment-canvas-gr-226-ce-224-easeljs.aspx"&gt;Jeux HTML5: animation de sprites dans l’élément Canvas grâce à EaselJS&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/08/22/jeux-html5-construction-des-objets-principaux-amp-gestion-des-collisions-avec-easeljs.aspx"&gt;Jeux HTML5: construction des objets principaux &amp;amp; gestion des collisions avec EaselJS&lt;/a&gt;     &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-portage-complet-du-jeu-xna-vers-lt-canvas-gt-gr-226-ce-224-easeljs.aspx"&gt;HTML5 Platformer: portage complet du jeu XNA vers &amp;lt;canvas&amp;gt; grâce à EaselJS&lt;/a&gt; où vous pouvez d’ailleurs télécharger le source code complet du jeu.&lt;/p&gt;  &lt;p&gt;Pour finir, voici &lt;strong&gt;quelques ressources complémentaires&lt;/strong&gt; que je vous conseille :&lt;/p&gt;  &lt;p&gt;- Pour aller plus loin sur la boucle “d’update”, on pourrait utiliser les Web Workers. Vous trouverez une introduction ici : &lt;a title="http://blogs.msdn.com/b/davrous/archive/2011/07/08/introduction-aux-web-workers-d-html5-le-multithreading-version-javascript.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/07/08/introduction-aux-web-workers-d-html5-le-multithreading-version-javascript.aspx"&gt;Introduction aux Web Workers d’HTML5 : le multithreading version JavaScript&lt;/a&gt;     &lt;br /&gt;- Il existe des moteurs physiques “open source” pour JavaScript dont le plus connu est Box2D que vous pouvez voir ici : &lt;a title="http://box2d-js.sourceforge.net/" href="http://box2d-js.sourceforge.net/"&gt;Box2DJS - Physics Engine for JavaScript&lt;/a&gt;     &lt;br /&gt;- &lt;a href="https://twitter.com/#!/sethladd"&gt;Seth Ladd&lt;/a&gt;, un évangéliste de chez Google, s’est d’ailleurs amusé à combiner Web Workers et Box2D. Je vous conseille son excellente série de tutoriaux sur Box2D dont celui qui traite des Web Workers : &lt;a href="http://blog.sethladd.com/2011/09/box2d-and-web-workers-for-javascript.html"&gt;Box2D and Web workers for JavaScript developers&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Pour finir, vous trouverez les slides de cette session ici :&lt;/p&gt; &lt;iframe height="327" src="http://r.office.microsoft.com/r/rlidPowerPointEmbed?p1=1&amp;amp;p2=1&amp;amp;p3=SDEE4BD0F5EA745C6!2173&amp;amp;p4=&amp;amp;kip=1" frameborder="0" width="402" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;   &lt;br /&gt;Et également sur slideshare ici : &lt;a title="Développement d&amp;#39;un jeu de plateforme en html5" href="http://www.slideshare.net/davrous/dveloppement-dun-jeu-de-plateforme-en-html5"&gt;Développement d'un jeu de plateforme en html5&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;J’espère maintenant avoir suscité des vocations pour un jour vous recroiser riche et célèbre grâce à votre jeu vidéo HTML5 ! &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4657.wlEmoticon_2D00_winkingsmile_5F00_58DFD0DE.png" /&gt;&lt;/p&gt;  &lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10239204" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Canvas/">Canvas</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/WebWorkers/">WebWorkers</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/MSDays/">MSDays</category></item><item><title>Tutorial HTML5: découverte des tags sémantiques, d’un soupçon de CSS3 et de Modernizr</title><link>http://blogs.msdn.com/b/davrous/archive/2011/08/25/tutorial-html5-d-233-couverte-des-tags-s-233-mantiques-d-un-soup-231-on-de-css3-et-de-modernizr.aspx</link><pubDate>Thu, 25 Aug 2011 13:33:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10200303</guid><dc:creator>David Rousset</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/davrous/rsscomments.aspx?WeblogPostID=10200303</wfw:commentRss><comments>http://blogs.msdn.com/b/davrous/archive/2011/08/25/tutorial-html5-d-233-couverte-des-tags-s-233-mantiques-d-un-soup-231-on-de-css3-et-de-modernizr.aspx#comments</comments><description>&lt;p&gt;Pendant l’été, avec &lt;a href="http://blogs.technet.com/b/stanislas/"&gt;Stanislas Quastana&lt;/a&gt; et &lt;a href="http://blogs.msdn.com/b/eternalcoding/"&gt;David Catuhe&lt;/a&gt;, nous avons publié 3 cahiers de vacances autour d’HTML5 sur notre plateforme MSDN : &lt;a title="http://msdn.microsoft.com/fr-fr/ie/hh237531" href="http://msdn.microsoft.com/fr-fr/ie/hh237531"&gt;Focus sur HTML5&lt;/a&gt; . Mon cahier abordait les tags sémantiques d’HTML5, un peu de CSS3 et comment rendre le tout compatible même avec IE8 en utilisant Modernizr. Je vous propose de le découvrir ici à nouveau. Vous pouvez télécharger les 2 autres cahiers consacrés à la balise audio/vidéo d’HTML5 et à la création d’un jeu de casse-brique avec Canvas et SVG sur notre &lt;a href="http://msdn.microsoft.com/fr-fr/ie/hh237531"&gt;site MSDN&lt;/a&gt;. Vous pouvez également télécharger ce même tutorial au même endroit aux formats PDF et DOCX. &lt;/p&gt; &lt;a title="Couverture Cahier HTML5" href="http://msdn.microsoft.com/fr-fr/ie/hh237531"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 0px 10px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="Couverture Cahier HTML5" src="http://farm7.static.flickr.com/6086/6076482919_55832defdf.jpg" width="354" height="500" /&gt;&lt;/a&gt;   &lt;h2&gt;Introduction&lt;/h2&gt;  &lt;p&gt;L’objectif de cet exercice est de découvrir votre première page HTML5 utilisant quelques tags sémantiques ainsi qu’un peu de CSS3. Nous allons également voir, en utilisant certaines bonnes pratiques, comment commencer à utiliser ces nouvelles technologies tout en continuant de bien supporter d’anciens navigateurs comme IE8. &lt;/p&gt;  &lt;h3&gt;Prérequis à l’atelier&lt;/h3&gt;  &lt;p&gt;1 – Visual Studio 2010 SP1    &lt;br /&gt;2 – Web Standards Update : &lt;a href="http://visualstudiogallery.msdn.microsoft.com/a15c3ce9-f58f-42b7-8668-53f6cdc2cd83"&gt;http://visualstudiogallery.msdn.microsoft.com/a15c3ce9-f58f-42b7-8668-53f6cdc2cd83&lt;/a&gt;     &lt;br /&gt;3 – Internet Explorer 9 ou tout autre navigateur supportant le HTML 5     &lt;br /&gt;4 – Téléchargez les sources pour commencer ce cahier ici : &lt;a href="http://david.blob.core.windows.net/html5/CahierVacancesHTML5.zip"&gt;CahierVacancesHTML5.zip&lt;/a&gt; et rendez-vous dans le répertoire « &lt;b&gt;&lt;i&gt;DebutCahier&lt;/i&gt;&lt;/b&gt; »&lt;/p&gt;  &lt;p&gt;Vous pouvez également bien entendu utiliser votre IDE préféré (VI, Notepad++, etc.) à la place de Visual Studio 2010 pour suivre ces exercices. Vous n’aurez pas beaucoup de mal à vous adapter je pense.&lt;/p&gt;  &lt;h3&gt;Les tags sémantiques&lt;/h3&gt;  &lt;p&gt;Avant l’arrivée des tags sémantiques d’HTML5, nous avions l’habitude de construire notre page avec un entête, un pied de page et une barre de navigation à l’aide de &amp;lt;div&amp;gt; habillée par CSS via l’affectation de classes. &lt;/p&gt;  &lt;p&gt;Cela marchait très bien mais le problème d’une balise &amp;lt;div&amp;gt; est qu’elle n’a pas de sens. Ce n’est pas forcément grave dans de nombreux cas mais ici pour la structure de notre page, cela peut être vite embêtant en terme de sémantique et d’accessibilité. Si l’accessibilité d’HTML5 vous intéresse d’ailleurs, je vous conseille un article que j’ai écrit à ce sujet : &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/02/21/slides-et-ressources-de-la-session-accessibilit-233-d-html5-et-silverlight-des-techdays-2011.aspx"&gt;Techdays 2011 – slides et ressources de la session Accessibilité d’HTML5 et Silverlight&lt;/a&gt; . Je vous conseille vivement aussi l’excellent article de Jean-Pierre Vincent en complément : &lt;a title="http://braincracking.org/2011/02/19/etat-des-lieux-de-l%e2%80%98accessibilite-de-html5/" href="http://braincracking.org/2011/02/19/etat-des-lieux-de-l%e2%80%98accessibilite-de-html5/"&gt;Etat des lieux de l‘accessibilité de HTML5&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;En gros, cela donne ce genre de résultat entre HTML4 et HTML5 :&lt;/p&gt;  &lt;p&gt;&lt;img src="http://farm6.static.flickr.com/5292/5465134921_7207b230e1.jpg" /&gt;&lt;/p&gt;  &lt;p&gt;Pour avoir une meilleure idée de leurs utilisations, vous pouvez lire les spécifications du W3C: &lt;a title="http://www.w3.org/TR/html5/sections.html#sections" href="http://www.w3.org/TR/html5/sections.html#sections"&gt;http://www.w3.org/TR/html5/sections.html#sections&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Dans notre cas, nous allons partir de cette page nommée « &lt;b&gt;&lt;i&gt;Accueil.html&lt;/i&gt;&lt;/b&gt; » qui utilise ces nouveaux tags sémantiques HTML5 :&lt;/p&gt; &lt;a title="CahierHTML5_001 by Internet Explorer 9, on Flickr" href="http://www.flickr.com/photos/60699397@N08/6076555531/"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="CahierHTML5_001" src="http://farm7.static.flickr.com/6183/6076555531_d9f66a03c9.jpg" width="500" height="265" /&gt;&lt;/a&gt;   &lt;p&gt;&lt;b&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/b&gt; cette page a été générée à partir du modèle de base proposé par &lt;a href="http://www.asp.net/mvc"&gt;ASP.NET MVC3&lt;/a&gt; qui supporte désormais les tags sémantiques HTML5.&lt;/p&gt;  &lt;h2&gt;1. Parcours de la page avec la barre F12&lt;/h2&gt;  &lt;p&gt;Pour mieux comprendre comment cette page est structurée, nous allons utiliser la barre de développement intégrée à IE9. Pour cela, ouvrez la page « &lt;i&gt;Accueil.html&lt;/i&gt; » dans Internet Explorer 9 et appuyez simplement sur la touche F12. Si vous connaissez l’outil Firebug pour Firefox, c’est tout simplement son équivalent nativement présent avec Internet Explorer. &lt;/p&gt;  &lt;p&gt;Une fois la barre de développement affichée, cliquez sur le pointeur de sélection :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6560.CahierHTML5_5F00_002_5F00_03ED2E1B.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_002" border="0" alt="CahierHTML5_002" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4428.CahierHTML5_5F00_002_5F00_thumb_5F00_74D64F40.png" width="500" height="70" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Puis visez le bas de la page où se trouve notre magnifique développeur sur la plage (ou sur la page si vous voulez !).&lt;/p&gt;  &lt;p&gt;Vous obtiendrez le résultat suivant :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0702.CahierHTML5_5F00_003_5F00_68DA74E6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_003" border="0" alt="CahierHTML5_003" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6165.CahierHTML5_5F00_003_5F00_thumb_5F00_17044AD4.png" width="617" height="480" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;La partie que vous avez sélectionnée s’entoure d’un liseré bleu. Ensuite, on voit bien 3 parties différentes qui structurent notre page : &lt;b&gt;&amp;lt;header&amp;gt;&lt;/b&gt;, &lt;b&gt;&amp;lt;section&amp;gt;&lt;/b&gt; et &lt;b&gt;&amp;lt;footer&amp;gt;&lt;/b&gt; où se trouve logiquement notre pied de page. &lt;/p&gt;  &lt;p&gt;Amusez-vous ensuite à parcourir le reste de la page de la même manière. Vous verrez qu’à chaque fois cela vous positionne directement au bon endroit. La structure HTML apparaît à gauche et cela vous affiche également le style CSS actuellement affecté à cet élément sur la droite. &lt;/p&gt;  &lt;p&gt;En parcourant le code de la page, vous noterez un élément indispensable si vous vous lancez dans l’aventure HTML5 :&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;!&lt;/span&gt;&lt;span style="color: maroon"&gt;DOCTYPE &lt;/span&gt;&lt;span style="color: red"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;La mise en place de cette balise DOCTYPE simplifiée par rapport à ce que vous avez peut-être déjà vu est indispensable si vous souhaitez qu’IE9+ bascule sur son moteur de rendu HTML5. Si vous ne commencez pas par cette balise, en commençant directement avec la balise &amp;lt;html&amp;gt; par exemple, IE9 basculera dans son mode « Quirks » et ne prendra donc pas en charge les nouveaux éléments HTML5 (video, canvas, etc.). &lt;/p&gt;

&lt;p&gt;Pour vérifier le mode de rendu actuellement utilisé par IE9, vous pouvez à nouveau le faire grâce à la touche F12. Vérifiez ensuite le mode de document. Observez cet exemple :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6558.CahierHTML5_5F00_004_5F00_0FA2754D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_004" border="0" alt="CahierHTML5_004" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0211.CahierHTML5_5F00_004_5F00_thumb_5F00_529E43BA.png" width="500" height="76" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dans cette copie d’écran, nous sommes en mode « &lt;strong&gt;Quirks&lt;/strong&gt; » et nous allons avoir des soucis avec l’affichage d’HTML5. Vous pouvez alors forcer le mode en « &lt;strong&gt;IE9 Standards&lt;/strong&gt; » avec la barre F12 ou corriger le code du site pour utiliser la balise DOCTYPE tout simplement.&lt;/p&gt;

&lt;h2&gt;2. Utilisation de F12 pour modifier dynamiquement le CSS&lt;/h2&gt;

&lt;p&gt;A l’aide de la barre F12, modifiez le style &lt;b&gt;CSS3&lt;/b&gt; actuellement mis en place pour que le coin arrondi inférieur gauche de l’élément &lt;b&gt;&amp;lt;footer&amp;gt;&lt;/b&gt; passe de 4px à 100px. &lt;/p&gt;

&lt;p&gt;Pour cela, via la barre F12, positionnez-vous à nouveau sur l’élément &amp;lt;footer&amp;gt; et cherchez la propriété &lt;b&gt;border-bottom-left-radius &lt;/b&gt;pour passer sa valeur de 4 à 100 pixels. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5670.CahierHTML5_5F00_005_5F00_5159AADB.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_005" border="0" alt="CahierHTML5_005" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3022.CahierHTML5_5F00_005_5F00_thumb_5F00_6C25D0E7.png" width="500" height="102" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Vous pouvez également cliquez sur l’onglet CSS de la barre de développement et choisir la bonne feuille de style. Cela implique donc que vous sachiez déjà où vous cherchez. Ensuite, utilisez la zone de recherche pour trouver la propriété qui vous intéresse :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5001.CahierHTML5_5F00_006_5F00_1CD8D893.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_006" border="0" alt="CahierHTML5_006" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6562.CahierHTML5_5F00_006_5F00_thumb_5F00_1B280CBF.png" width="500" height="143" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Vous devriez voir alors instantanément le résultat de votre modification dans la page :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6253.CahierHTML5_5F00_007_5F00_2817DCDD.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_007" border="0" alt="CahierHTML5_007" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3438.CahierHTML5_5F00_007_5F00_thumb_5F00_1894CB0E.png" width="640" height="89" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Le coin inférieur gauche du pied de page a bien été davantage arrondi. La barre F12 est donc très pratique pour tester en live quelques modifications. Vous pouvez même ajouter de nouvelles règles CSS ou des attributs à une règle existante via cette même barre.&lt;/p&gt;

&lt;p&gt;Sans le savoir vous avez par ailleurs déjà joué avec l’une des nouveautés de CSS3 présente dans le module &lt;a href="http://www.w3.org/TR/css3-background/"&gt;CSS3 Background &amp;amp; Borders&lt;/a&gt; du W3C. Félicitations ! &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5282.wlEmoticon_2D00_winkingsmile_5F00_4262107C.png" /&gt;&lt;/p&gt;

&lt;p&gt;Ce module n’est pas le plus critique de CSS3 mais c’est l’un des plus simples à comprendre et à expérimenter. Il permet tout simplement d’arrondir les coins de n’importe quel élément HTML ainsi que de positionner également une ombre portée via la propriété &lt;b&gt;&lt;i&gt;box-shadow&lt;/i&gt;&lt;/b&gt;. Retrouvez davantage d’informations en Français sur notre site MSDN ici : &lt;a href="http://msdn.microsoft.com/fr-fr/ie/ff468705#_CSS3_BG_Borders"&gt;Module CSS3 Arrière-plans et bordures&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;3. Modification de la feuille de style avec Visual Studio 2010&lt;/h2&gt;

&lt;p&gt;A l’aide de Visual Studio 2010, ouvrez le fichier « &lt;b&gt;&lt;i&gt;Site.css&lt;/i&gt;&lt;/b&gt; ». Commencez par bien vérifier que vous êtes actuellement en train de valider du CSS3 et non pas du CSS 2.1 :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8712.CahierHTML5_5F00_008_5F00_453D84E7.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_008" border="0" alt="CahierHTML5_008" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7144.CahierHTML5_5F00_008_5F00_thumb_5F00_3B28E3BC.png" width="640" height="452" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;La validation et auto-complétion d’HTML5 et de CSS3 vous est offerte par l’installation du prérequis &lt;a href="http://visualstudiogallery.msdn.microsoft.com/a15c3ce9-f58f-42b7-8668-53f6cdc2cd83"&gt;Web Standards Update&lt;/a&gt;. Si vous ne l’avez pas installé, ce n’est pas grave. Visual Studio sous-lignera simplement les propriétés CSS3 en rouge puisqu’il ne les connait pas sans cette extension.&lt;/p&gt;

&lt;p&gt;Une fois la feuille de style ouverte, modifiez une fois pour toute le style du &amp;lt;footer&amp;gt; pour avoir notre coin arrondi inférieur gauche de 100 pixels :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;footer&lt;/span&gt;, 
&lt;span style="color: maroon"&gt;#footer 
&lt;/span&gt;{
    &lt;span style="color: red"&gt;background&lt;/span&gt;: &lt;span style="color: blue"&gt;url(ImagePiedPage.png) no-repeat left bottom&lt;/span&gt;;
    &lt;span style="color: red"&gt;background-color&lt;/span&gt;: &lt;span style="color: blue"&gt;#fff&lt;/span&gt;;
    &lt;span style="color: red"&gt;color&lt;/span&gt;: &lt;span style="color: blue"&gt;#999&lt;/span&gt;;
    &lt;span style="color: red"&gt;padding&lt;/span&gt;: &lt;span style="color: blue"&gt;0&lt;/span&gt;;
    &lt;span style="color: red"&gt;text-align&lt;/span&gt;: &lt;span style="color: blue"&gt;center&lt;/span&gt;;
    &lt;span style="color: red"&gt;line-height&lt;/span&gt;: &lt;span style="color: blue"&gt;10em&lt;/span&gt;;
    &lt;span style="color: red"&gt;margin&lt;/span&gt;: &lt;span style="color: blue"&gt;0 0 30px 0&lt;/span&gt;;
    &lt;font style="background-color: #ffff00"&gt;&lt;span style="color: red"&gt;border-radius&lt;/span&gt;: &lt;span style="color: blue"&gt;0 0 4px 100px&lt;/span&gt;;&lt;/font&gt;
}&lt;/pre&gt;

&lt;p&gt;Au passage, on va en profiter pour faire une ombre portée justement pour faire un effet de halo autour de nos boutons de navigation contenu dans la balise &lt;b&gt;&amp;lt;nav&amp;gt; &lt;/b&gt;du coup. Voici la partie de CSS qui nous intéresse :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;ul#menu li a &lt;/span&gt;{
    &lt;span style="color: red"&gt;padding&lt;/span&gt;: &lt;span style="color: blue"&gt;10px 20px&lt;/span&gt;;
    &lt;span style="color: red"&gt;font-weight&lt;/span&gt;: &lt;span style="color: blue"&gt;bold&lt;/span&gt;;
    &lt;span style="color: red"&gt;text-decoration&lt;/span&gt;: &lt;span style="color: blue"&gt;none&lt;/span&gt;;
    &lt;span style="color: red"&gt;line-height&lt;/span&gt;: &lt;span style="color: blue"&gt;2.8em&lt;/span&gt;;
    &lt;span style="color: red"&gt;background-color&lt;/span&gt;: &lt;span style="color: blue"&gt;#e8eef4&lt;/span&gt;;
    &lt;span style="color: red"&gt;color&lt;/span&gt;: &lt;span style="color: blue"&gt;#034af3&lt;/span&gt;;
    &lt;span style="color: red"&gt;border-radius&lt;/span&gt;: &lt;span style="color: blue"&gt;4px 4px 0 0&lt;/span&gt;;
    &lt;font style="background-color: #ffff00"&gt;&lt;span style="color: red"&gt;box-shadow&lt;/span&gt;: &lt;span style="color: blue"&gt;0 0 20px rgba(0,0,0,0.5)&lt;/span&gt;;&lt;/font&gt;
}&lt;/pre&gt;

&lt;p&gt;Et cela devrait vous donner ce magnifique résultat :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7120.CahierHTML5_5F00_009_5F00_6A2B1F93.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_009" border="0" alt="CahierHTML5_009" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1781.CahierHTML5_5F00_009_5F00_thumb_5F00_276BD45B.png" width="640" height="390" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;C’est peut-être subtil mais vous devriez le voir. Amusez-vous par exemple, via la barre F12, à activer/désactiver l’application de cette attribut pour voir la différence.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6746.CahierHTML5_5F00_010_5F00_59AD5A65.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_010" border="0" alt="CahierHTML5_010" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0880.CahierHTML5_5F00_010_5F00_thumb_5F00_1FBE1779.png" width="400" height="116" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;4. Afficher la page correctement sous IE8&lt;/h2&gt;

&lt;p&gt;Si vous testez le rendu sous Internet Explorer 8 en forçant par exemple le moteur de rendu associé avec la barre F12 d’IE9 : &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1362.CahierHTML5_5F00_011_5F00_1E797E9A.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_011" border="0" alt="CahierHTML5_011" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5582.CahierHTML5_5F00_011_5F00_thumb_5F00_24542233.png" width="500" height="130" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Votre page devrait être toute cassée :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1460.CahierHTML5_5F00_012_5F00_6D6C6BA1.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_012" border="0" alt="CahierHTML5_012" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7142.CahierHTML5_5F00_012_5F00_thumb_5F00_51E7699E.png" width="640" height="387" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pour quelles raisons ? Tout simplement parce que les balises &lt;strong&gt;&amp;lt;header&amp;gt;&lt;/strong&gt;, &lt;strong&gt;&amp;lt;nav&amp;gt;&lt;/strong&gt; et &lt;strong&gt;&amp;lt;footer&amp;gt;&lt;/strong&gt; que nous utilisons actuellement sont des nouvelles balises HTML5 qu’IE8 ne connait pas. Or, IE8 et inférieurs ont la mauvaise habitude d’ignorer purement et simplement les tags qu’ils ne connaissent pas en ne les créant pas dans le DOM. Du coup, si vous comptiez sur ces tags pour appliquer vos feuilles de style, cela casse tout votre design de page. &lt;/p&gt;

&lt;p&gt;La 1&lt;sup&gt;ère&lt;/sup&gt; solution consiste simplement créer ces nouveaux tags dans le DOM (Document Object Model) d’IE par JavaScript avec un code équivalent à celui-là :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &lt;/span&gt;document.createElement(&lt;span style="color: maroon"&gt;&amp;quot;header&amp;quot;&lt;/span&gt;);
    document.createElement(&lt;span style="color: maroon"&gt;&amp;quot;footer&amp;quot;&lt;/span&gt;);
    document.createElement(&lt;span style="color: maroon"&gt;&amp;quot;section&amp;quot;&lt;/span&gt;);
    document.createElement(&lt;span style="color: maroon"&gt;&amp;quot;nav&amp;quot;&lt;/span&gt;);
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;IE8 ne connaitra pas pour autant leurs significations mais le fait de les rendre présentes dans le DOM nous permettra d’appliquer désormais correctement le style associé à ces nouvelles balises.&lt;/p&gt;

&lt;p&gt;Ainsi, si vous mettez ce code tout en haut de la page « &lt;i&gt;Accueil.html&lt;/i&gt; », l’affichage sous IE8 devient magiquement correct :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3426.CahierHTML5_5F00_013_5F00_62133197.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_013" border="0" alt="CahierHTML5_013" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2330.CahierHTML5_5F00_013_5F00_thumb_5F00_3F02C027.png" width="640" height="387" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nous avons simplement perdus les bords arrondis et les effets d’ombre portée. Ces effets ne seront alors affichés qu’aux navigateurs les plus récents comme « bonus visuels ». Mais notre site continuera d’être fonctionnel pour les navigateurs les plus anciens. Cette approche est la base de ce que nous appelons le &lt;b&gt;« &lt;i&gt;graceful degradation&lt;/i&gt;&lt;/b&gt; » en Anglais ou dégradation élégante. CSS par nature se prête très bien à cet exercice. Cela vous permet ainsi de commencer à utiliser des nouveautés de CSS3 sans pour autant vous couper des navigateurs les plus anciens. &lt;/p&gt;

&lt;h2&gt;5. Moderniser vos sites avec Modernizr&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://www.modernizr.com"&gt;Modernizr&lt;/a&gt; est une librairie JavaScript qui va nous permettre 2 choses :&lt;/p&gt;

&lt;p&gt;1 – Créer toutes les nouvelles balises HTML5 pour les anciens navigateurs pour nous pour éviter d’avoir à faire ce que nous avons fait juste avant 
  &lt;br /&gt;2 – De faire ce que l’on appelle du « &lt;b&gt;feature detection&lt;/b&gt; » en Anglais ou détection de fonctionnalités supportées par le navigateur.&lt;/p&gt;

&lt;p&gt;Cette librairie est désormais présente par défaut dans les modèles de projets d’ASP.NET MVC3. &lt;/p&gt;

&lt;p&gt;Pour le 1&lt;sup&gt;er&lt;/sup&gt; point, reprenez le code de la page « &lt;i&gt;Accueil.html&lt;/i&gt; » et remplacez ce bloc :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &lt;/span&gt;document.createElement(&lt;span style="color: maroon"&gt;&amp;quot;header&amp;quot;&lt;/span&gt;);
    document.createElement(&lt;span style="color: maroon"&gt;&amp;quot;footer&amp;quot;&lt;/span&gt;);
    document.createElement(&lt;span style="color: maroon"&gt;&amp;quot;section&amp;quot;&lt;/span&gt;);
    document.createElement(&lt;span style="color: maroon"&gt;&amp;quot;nav&amp;quot;&lt;/span&gt;);
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Juste par cette ligne :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;script &lt;/span&gt;&lt;span style="color: red"&gt;src&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;./Scripts/modernizr-1.7.min.js&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Et le tour est joué ! Votre page utilisant les nouveaux tags HTML5 fonctionne toujours bien sous IE8.&lt;/p&gt;

&lt;p&gt;Mais ce n’est pas tout. Modernizr va vous permettre de tester les capacités du navigateur par code JavaScript et d’adapter le rendu en fonction de cela. &lt;/p&gt;

&lt;p&gt;Une fois la librairie chargée, en mode de rendu IE9, appuyez sur la touche F12 et regardez ce qui a été ajouté à l’élément racine &amp;lt;html&amp;gt; :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8713.CahierHTML5_5F00_014_5F00_0E1E06E1.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_014" border="0" alt="CahierHTML5_014" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6562.CahierHTML5_5F00_014_5F00_thumb_5F00_7AFCDA34.png" width="500" height="69" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On voit que l’attribut « &lt;i&gt;&lt;strong&gt;class&lt;/strong&gt;&lt;/i&gt; » a été rempli en fonction de ce que votre navigateur supporte. &lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/b&gt; il est cependant important de noter que Modernizr n’effectue finalement qu’un simple test binaire. Il répond à la question « votre navigateur supporte-t-il XXX ? » (Oui/Non). Ce n’est pas un test qualitatif pour savoir ensuite si votre navigateur supporte toutes les fonctionnalités associées et surtout si l’implémentation de cette fonctionnalité est correcte ou pas.&lt;/p&gt;

&lt;p&gt;Utilisons maintenant Modernizr pour un cas que je trouve intéressant. IE9 supporte désormais le format vectoriel de dessin SVG. Cela nous permet ainsi d’envisager d’afficher des diagrammes, schéma ou toute autre forme d’image en vectoriel pour augmenter la qualité visuelle de nos pages. Oui mais que se passe-t-il pour les anciens navigateurs ne supportant pas SVG ? Et bah nous allons leur donner une version PNG de la même image. &lt;/p&gt;

&lt;p&gt;Reprenez la page « &lt;i&gt;Accueil.html&lt;/i&gt; » et ajoutez cette déclaration d’image sous l’unique paragraphe de notre section « &lt;i&gt;main&lt;/i&gt; » :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;img &lt;/span&gt;&lt;span style="color: red"&gt;src&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=imageThreadJS &lt;/span&gt;&lt;span style="color: red"&gt;alt&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Diagramme illustrant le cote mono-thread de JavaScript&amp;quot; /&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Nous préparons ici une zone qui contiendra notre image. Nous allons y stocker l’illustration issue de l’article suivant : &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/07/08/introduction-aux-web-workers-d-html5-le-multithreading-version-javascript.aspx"&gt;Introduction aux Web Workers d’HTML5 : le multithreading version JavaScript&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ensuite, insérez ce bloc de code à la fin de la page « &lt;i&gt;Accueil.html&lt;/i&gt; » juste avant la fermeture de la balise &amp;lt;body&amp;gt; :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &lt;/span&gt;var &lt;span style="color: blue"&gt;img&lt;/span&gt;ThreadJS = document.getElementById(&amp;quot;ima&lt;span style="color: maroon"&gt;geThreadJS&amp;quot;);
    &lt;/span&gt;if (Mode&lt;span style="color: blue"&gt;rn&lt;/span&gt;izr.svg) {
        imgThreadJS.src = &amp;quot;http://davi&lt;span style="color: maroon"&gt;d.blob.core.windows.net/html5/SVGSingleThreadJS.svg&amp;quot;;

    }
    &lt;/span&gt;else {
        imgT&lt;span style="color: blue"&gt;hrea&lt;/span&gt;dJS.src = &amp;quot;http://david.blob.core.&lt;span style="color: maroon"&gt;windows.net/html5/SVGSingleThread.png&amp;quot;;
    }
&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Ce code s’occupe de retrouver votre élément de type image puis en fonction de ce que Modernizr nous aura indiqué, nous irons chercher soit la version vectorielle de l’image (.SVG) soit la version bitmap de l’image (.PNG). &lt;/p&gt;

&lt;p&gt;Voici ainsi le résultat avec le moteur d’IE9 Standard :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2845.CahierHTML5_5F00_015_5F00_52EA2B15.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_015" border="0" alt="CahierHTML5_015" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5670.CahierHTML5_5F00_015_5F00_thumb_5F00_2FD9B9A5.png" width="500" height="401" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Et voici le résultat avec le moteur d’IE8 :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8625.CahierHTML5_5F00_016_5F00_4005819E.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="CahierHTML5_016" border="0" alt="CahierHTML5_016" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5008.CahierHTML5_5F00_016_5F00_thumb_5F00_4AE262E6.png" width="500" height="401" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/b&gt; la détection de fonctionnalités est clairement l’approche que vous devez désormais avoir sur toutes vos nouvelles créations. Ne faites surtout plus de détection de version de navigateurs (ou « &lt;i&gt;user-agent sniffing&lt;/i&gt; » en Anglais). &lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;En définitive, si IE9 ou un autre navigateur moderne comme Chrome, Firefox ou Opera arrive sur la page, ils pourront profiter d’une version du site plus moderne visuellement avec du CSS3 et du SVG. &lt;/p&gt;

&lt;p&gt;Si IE8 ou un autre navigateur plus ancien arrive sur la page, l’affichage sera peut-être moins aguichant avec une version PNG des images et moins d’effets visuels mais le site continuera d’être fonctionnel. &lt;/p&gt;

&lt;p&gt;C’est clairement dans cette direction que vous devrez travailler si vous souhaitez commencer à mettre en production du HTML5/CSS3 &amp;amp; Cie sur vos sites. &lt;/p&gt;

&lt;h3&gt;Ressources complémentaires&lt;/h3&gt;

&lt;p&gt;· &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/05/20/slides-et-exemples-de-ma-pr-233-sentation-des-microsoft-days-et-du-remix11-sur-html5.aspx"&gt;HTML5: Etat des lieux et projection vers l’avenir&lt;/a&gt; 

  &lt;br /&gt;· &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/05/09/introduction-aux-apis-graphiques-d-html5-svg-amp-canvas-1-4.aspx"&gt;Introduction aux APIs graphiques d’HTML5: SVG &amp;amp; Canvas &lt;/a&gt;

  &lt;br /&gt;· &lt;a href="http://blogs.msdn.com/b/iefrance/archive/2011/03/25/microsoft-techdays-2011-la-vid-233-o-de-la-session-introduction-224-html5-est-en-ligne.aspx"&gt;TechDays 2011 : Introduction à HTML5&lt;/a&gt; 

  &lt;br /&gt;· &lt;a href="http://blogs.msdn.com/b/iefrance/archive/2011/02/08/techdays-2011-les-slides-de-la-session-introduction-224-html5.aspx"&gt;TechDays 2011 - les slides de la session Introduction à HTML5&lt;/a&gt; 

  &lt;br /&gt;· &lt;a href="http://blogs.technet.com/b/stanislas/archive/2010/11/04/mais-qui-construit-l-html5.aspx"&gt;Mais qui construit l'HTML5 ?&lt;/a&gt; 

  &lt;br /&gt;· &lt;a href="http://blogs.msdn.com/b/iefrance/archive/2011/02/28/html5-respect-des-standards-tests-et-marketing.aspx"&gt;HTML5 : respect des standards, tests et marketing&lt;/a&gt; 

  &lt;br /&gt;· &lt;a href="http://dev.w3.org/html5/spec/Overview.html"&gt;Site web du W3C pour HTML5&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Fun&lt;/h3&gt;

&lt;p&gt;On s’est bien marrés avec David et Stanislas en réalisant une vidéo de teasing où on fait les andouilles avec chapeaux de paille et shorts de bain. Je ne résiste pas au plaisir de vous la partager à nouveau (en HTML5 h264/WebM bien sûr!) :&lt;/p&gt;
&lt;video poster="http://www.catuhe.com/msdn/poster.png" width="512" controls&gt;&lt;source type="video/mp4" src="http://www.catuhe.com/msdn/teasingcahier.mp4"&gt;&lt;source type="video/webm" src="http://www.catuhe.com/msdn/teasingcahier.webm"&gt;&lt;/video&gt;

&lt;p&gt;&lt;br/&gt;Et spéciale décidasse à ma grand-mère g33k !&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10200303" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Internet+Explorer+9/">Internet Explorer 9</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Tutorial/">Tutorial</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Visual+Studio+2010/">Visual Studio 2010</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/CSS3/">CSS3</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/SVG/">SVG</category><category domain="http://blogs.msdn.com/b/davrous/archive/tags/Modernizr/">Modernizr</category></item></channel></rss>
