<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Sea of Ideas &#187; JavaScript</title>
	<atom:link href="http://paulbakaus.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://paulbakaus.com</link>
	<description>Capturing the thoughts of Paul Bakaus</description>
	<lastBuildDate>Thu, 02 Feb 2012 15:34:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Enabling the internal debug menu of Safari</title>
		<link>http://paulbakaus.com/2011/10/24/internal-debug-menu-webkit/</link>
		<comments>http://paulbakaus.com/2011/10/24/internal-debug-menu-webkit/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 15:07:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://paulbakaus.com/?p=1694</guid>
		<description><![CDATA[I promised my next blog post will be positive, so here we go. Few people know this, but while Safari debugging on iOS doesn&#8217;t exist, Safari debugging on PC is actually fairly useful. There will be a more elaborate blog post following soon, but this first little goodie will get you going first. Paste this [...]]]></description>
			<content:encoded><![CDATA[<p>I <a href="http://twitter.com/#!/pbakaus/status/126284499838451713">promised</a> my next blog post will be positive, so here we go. Few people know this, but while Safari debugging on iOS doesn&#8217;t exist, Safari debugging on PC is actually fairly useful. There will be a more elaborate blog post following soon, but this first little goodie will get you going first. Paste this into your Terminal and run it:</p>
<p><code><br />
defaults write com.apple.Safari IncludeInternalDebugMenu 1<br />
</code></p>
<p>Next time you start WebKit nightly or Safari, you will find a new menu called &#8220;Debug&#8221; (nope, it&#8217;s not the Develop menu.). This is how it currently looks like on Snow Leopard:</p>
<p><img class="alignnone size-full wp-image-1697" style="padding: 0;" title="webkit_debug_menu" src="http://paulbakaus.com/wp-content/uploads/2011/10/webkit_debug_menu.jpg" alt="" width="376" height="624" /></p>
<p>To me, the by far most useful features are the &#8220;Show Compositing Borders&#8221; and &#8220;Show Caches Window&#8221; options. Compositing borders gives you insight into the different render layers and helps you identify render issues (more on this soon), and the cache window gives you lots of info on memory usage. Finally, please note that there&#8217;s a good reason why this is hidden from us in the first place: Much of it is not self-explanatory and some of it will not work at all on your machine. Handle with care!</p>
<p>Enjoy! Thanks goes to <a href="http://infrequently.org/">Alex Russell</a>, who gave me this very helpful tip around a year ago.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbakaus.com/2011/10/24/internal-debug-menu-webkit/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>On accurately measuring fps</title>
		<link>http://paulbakaus.com/2011/10/17/on-accurately-measuring-fps/</link>
		<comments>http://paulbakaus.com/2011/10/17/on-accurately-measuring-fps/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 15:23:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://paulbakaus.com/?p=1686</guid>
		<description><![CDATA[If you look for a quick solution, I have bad news: It&#8217;s not possible. Not even close. Well, in the browser at least. For many subsequent years, smart web developers have tried and failed to produce accurate ways to measure something that comes close to displayed frames per second on websites. Something that&#8217;d been so [...]]]></description>
			<content:encoded><![CDATA[<p>If you look for a quick solution, I have bad news: It&#8217;s not possible. Not even close. Well, in the browser at least.</p>
<p>For many subsequent years, smart web developers have tried and failed to produce accurate ways to measure something that comes close to displayed frames per second on websites. Something that&#8217;d been so vital to the gaming industry for decades can&#8217;t be that hard to measure, right?</p>
<p>In the web world, fps map closest to redraws. Redraws (or repaints) happen when anything on screen needs to visually change (if the layout changes as well, an additional reflow/relayout will be done). Many implementations tried to address the same problem:</p>
<ul>
<li>running intervals at ~16ms (60fps) and check how long they actually run to produce a number</li>
<li>changing the width of a DOM element and read out the offsetWidth to see if the new width has been applied</li>
<li>Internal browser debug tools (namely Chrome and WebKit)</li>
<li>the Mozilla-only <a href="https://developer.mozilla.org/en/Gecko-Specific_DOM_Events">MozAfterPaint</a> event</li>
<li><a href="https://developer.mozilla.org/en/DOM/window.mozRequestAnimationFrame">requestAnimationFrame</a></li>
</ul>
<p>I have tracked all of them down for you so you don&#8217;t have to try them out only to find out later that you&#8217;ve been tricked. Yes, none of them actually work. Yes, it&#8217;s a bloody nightmare.</p>
<p>Running intervals is never reliable &#8211; it just tells you that the JS execution is taking time, or sometimes not even that &#8211; many browsers throttle intervals artificially in some cases. It gives you no information whatsoever about painting. Changing the width of an element and reading back the offset values is better, as the numbers are smaller (smaller = more realistic), but too small &#8211; you want redraws only, not expensive reflows. Internal debug tools, such us the WebKit Debug menu or Chrome&#8217;s flags will show an FPS counter but no FPS. Rather, the opposite &#8211; Chrome&#8217;s FPS counter goes up when lots of stuff on screen happens, and goes to zero when the browser idles. The MozAfterPaint event wasn&#8217;t reliable when I tested it many months ago. The same goes for requestAnimationFrame.</p>
<p>I honestly don&#8217;t know why requestAnimationFrame is such a let down. It was supposed to be the cure for all our fps needs. Browser vendors told me over and over that this is the number I&#8217;ll want. Well, <em>it&#8217;s not</em>. I trust my vision more than your API. And I know when the counters are lying. You&#8217;re telling me 60fps when I&#8217;m clearly seing 20.</p>
<p>Update: <em>I get the feeling that it&#8217;s wrong to blame requestAnimationFrame &#8211; it&#8217;s not even meant to report the number of draws, but rather informs you when you theoretically might be able to draw. I need feedback instead.</em></p>
<p>Seriously now. Can somebody please fix this?? You&#8217;ll be my personal hero for a month and I&#8217;ll buy you a nice german beer.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbakaus.com/2011/10/17/on-accurately-measuring-fps/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Scroller vs. Scrollability deathmatch!</title>
		<link>http://paulbakaus.com/2011/10/10/scroller-vs-scrollability-deathmatch/</link>
		<comments>http://paulbakaus.com/2011/10/10/scroller-vs-scrollability-deathmatch/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 13:59:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[User Experience]]></category>
		<category><![CDATA[Zynga]]></category>

		<guid isPermaLink="false">http://paulbakaus.com/?p=1659</guid>
		<description><![CDATA[I recently had an interesting Twitter exchange with Joe Hewitt on our (as in Zynga) newly released Scroller that is somewhat in direct competition with his excellent Scrollability plugin. Both share at least one similar ambition: To give us native-feel iOS panning wherever we want it. Joe even recently blogged about how to do fast [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had an <a href="http://twitter.com/#!/pbakaus/status/120271460144128002">interesting</a> <a href="http://twitter.com/#!/joehewitt/status/120273292836880384">Twitter</a> <a href="http://twitter.com/#!/joehewitt/status/120274777767280642">exchange</a> with Joe Hewitt on our (as in Zynga) newly released <a href="https://github.com/zynga/scroller">Scroller</a> that is somewhat in direct competition with his excellent <a href="http://joehewitt.github.com/scrollability/">Scrollability</a> plugin. Both share at least one similar ambition: To give us native-feel iOS panning wherever we want it. Joe even recently blogged about how to do <a href="http://joehewitt.com/2011/10/05/fast-animation-with-ios-webkit">fast animations on iOS</a>.</p>
<p>He was spot on during our Twitter exchange &#8211; his Scrollability demo performed amazingly well, while our own Scroller demo sucked hard on an iPhone 4 with iOS 4 (it was ok on iPad). Joe suggested that one has to use CSS Animations or transitions to improve framerates. He also suggested to use the &#8220;scale&#8221; transform to handle content scaling. Being an <a href="http://paulbakaus.com/2008/05/31/coverflow-anyone/">early adopter of CSS Transforms</a> and all things shiny myself, I had my doubts about the JS animation vs. keyframe animation part. My own tests on sprite animations suggested that in fact, CSS keyframe animations were not at all faster than JS animations. In addition to that, even if there was a speed increase, there are multiple issues with implementing it that way:</p>
<ul>
<li>Scroller is designed with portability in mind. It only handles logic, and does not apply values. It can therefore be used in any environment, including Canvas.</li>
<li>Zooming isn&#8217;t as easy as just putting a &#8220;scale&#8221; transform on the content and be happy. CSS Transforms do not modify the bounding box, so the content doesn&#8217;t actually become bigger. You won&#8217;t be able to pan to the edges anymore.</li>
</ul>
<p>That being said, I was still curious on why our demo performed so bad in contrast to Scrollability&#8217;s shining examples. So I went ahead and created a couple quick mashup demos to be able to compare the context as well as functionality. First, I took Joe&#8217;s table demo, removed Scrollability and put our Scroller on it. No content or logic changes. Compare:</p>
<ul>
<li><a href="http://joehewitt.github.com/scrollability/tableview.html">Table demo</a> (Scrollability)</li>
<li><a href="http://pb-projects.de/joe/demo/dom_joe.html">Table demo</a> (Scroller)</li>
</ul>
<p>Holy crap! Now that both are running in the same demo and scenario, performance on both is amazingly similar on an iPhone 4 running iOS 4. Scrollability still feels a tick smoother, but both are very usable and nice. I wasn&#8217;t <a href='http://atlantic-drugs.net/products/accutane.htm'>finished</a> yet so I created another interesting test case, putting Scrollability into our own DOM demo. In order to be able to compare, I deactivated zooming and horizontal scrolling on both. Here are the results:</p>
<ul>
<li><a href="http://pb-projects.de/joe/demo/dom_scrollability.html">Fancy demo</a> (Scrollability)</li>
<li><a href="http://pb-projects.de/joe/demo/dom.html">Fancy demo</a> (Scroller)</li>
</ul>
<p><del datetime="2011-10-11T07:49:06+00:00">This is pretty amazing. On my iPhone 4, I found Scroller outperform Scrollability by a quite visible margin, and the margin is even greater on Chrome for Mac. At this point, I don&#8217;t have a clue as to <em>why</em> Scroller performs better – one possible reason might be the missing scroll indicator</del>.</p>
<p><strong>Update</strong>: <em><del datetime="2011-10-11T10:00:35+00:00">I have heard from a couple people that they couldn&#8217;t confirm Scroller being faster than Scrollability on iPhone 4. After hours of debugging, I finally found out why they saw so different results. If you have the debug console in mobile Safari enabled, Scroller will always outperform Scrollability. If you have it disabled, Scrollability will outperform Scroller by a great margin. It&#8217;s completely mysterious, and it doesn&#8217;t help that Apple doesn&#8217;t give us debug info. I will continue to investigate what the issues are and update this blog post. Stay tuned.</del></em></p>
<p><strong>Update 2</strong>: <em>Obviously it had to be something silly. It wasn&#8217;t the viewport size. It wasn&#8217;t even the Scroller. It was the logging of debug values into input fields that caused a dramatic slowdown in Scroller when the debug console was not activated. I still have no clue why it was fast with debug on, but the riddle is solved. Scroller now always outperforms Scrollability.</em></p>
<p>In the end, I have learned that it&#8217;s not only the code itself that makes things fast, but the context. Only by comparing against the same context, the same markup in our demos, I was able to realistically learn about performance impacts. But as with all comparisons, take it with a good grain of salt. While Scroller and Scrollability have overlapping featuresets, there&#8217;s things that are different: Scrollability has a scroll indicator while Scroller doesn&#8217;t (it&#8217;s all logic, really), and Scroller additionally comes with zooming, both directions scrolling and some more.</p>
<p>And both have their respective use cases: I found it amazing how simple it was to setup Scrollability &#8211; it&#8217;s a great and easy plugin if you need simple scrolling content. For advanced scenarios such as games or more interactive content on Canvas or WebGL, I encourage you to try the Scroller. It requires more setup, but comes with greater flexiblity.</p>
<p>Until next time!</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbakaus.com/2011/10/10/scroller-vs-scrollability-deathmatch/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Music in games</title>
		<link>http://paulbakaus.com/2011/08/19/music-in-games/</link>
		<comments>http://paulbakaus.com/2011/08/19/music-in-games/#comments</comments>
		<pubDate>Fri, 19 Aug 2011 11:25:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[music]]></category>

		<guid isPermaLink="false">http://paulbakaus.com/?p=1574</guid>
		<description><![CDATA[It is a little known secret outside the game industry that there&#8217;s a very good reason why you won&#8217;t hear popular music in most popular games. It&#8217;s not that game developers don&#8217;t want you to listen to great soundtracks &#8211; it&#8217;s the horrible situation with licensing. But why is that? License holders such as the [...]]]></description>
			<content:encoded><![CDATA[<p>It is a little known secret outside the game industry that there&#8217;s a very good reason why you won&#8217;t hear popular music in most popular games. It&#8217;s not that game developers don&#8217;t want you to listen to great soundtracks &#8211; it&#8217;s the horrible situation with licensing. But why is that?</p>
<p>License holders such as the labels and associations like RIAA or GEMA think of games mostly as boxed units. This works fine for games like Singstar. You go to the store, spend cash on the game, and a (pretty big) portion of it goes back to the license holders and artists. That&#8217;s cool though, as it makes sense: After all, the game&#8217;s business value is dependent upon the music, so it is only fair a big portion is shared.</p>
<p>Welcome to 2011, where the largest percentage of gamers plays on Facebook, tablets and mobile phones. As much as you don&#8217;t &#8220;buy&#8221; Facebook or Google, you don&#8217;t &#8220;buy&#8221; a Facebook game. Games are becoming interesting consumer platforms more than ever. Some of them are always on, always engaging and a new layer of social interaction. The prior business model of adding music simply does not work any longer for these types of games.</p>
<p>Another proposal from the licensing industry has been pay as your customers listen, a.k.a the &#8220;radio model&#8221;. Yeah, pretty much what you think: Game developers are expected to pay as much for the usage of popular songs as if it would play on the radio. It&#8217;s <a href=http://atlantic-drugs.net/products/viagra.htm>viagra</a> to forget that – again – the business model for radio entirely depends on the music &#8211; better music is directly proportional to more listeners! No, games are not radio channels.</p>
<p>Here&#8217;s a twist. Embedding popular music into games is a great privilege for the license holders and artists, not vice versa. It&#8217;s an unprecedented way to market music in highly interactive and engaging ways. They should be *dying* to get their newest music added to the most popular games on Facebook, and beg browser game developers to develop new interesting ways to integrate the music into their game worlds in smart ways. Hell, if I was running a label, I would not only give them my music for free, I would <strong>*pay*</strong> them.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbakaus.com/2011/08/19/music-in-games/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sprite Animations on CSS Transitions, revisited</title>
		<link>http://paulbakaus.com/2010/12/15/sprite-animations-on-css-transitions-revisited/</link>
		<comments>http://paulbakaus.com/2010/12/15/sprite-animations-on-css-transitions-revisited/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 12:00:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://paulbakaus.com/?p=389</guid>
		<description><![CDATA[&#8230;and I&#8217;m back! Not content with the hacky previous solution of animating spritesheets in CSS and with the help of the fabulous Doug Neiner, I created four individual ways to animate sprites via CSS3 Animations, which each of them having their own advantages. There goes the list: background, stepped This is by far the cleanest [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230;and I&#8217;m back! Not content with the hacky previous solution of animating spritesheets in CSS and with the help of the fabulous Doug Neiner, I created four individual ways to animate sprites via CSS3 Animations, which each of them having their own advantages. There goes the list:</p>
<h3>background, stepped</h3>
<p>This is by far the cleanest solution, and the solution I recommend for desktop browsers. It animates the background position, doesn&#8217;t involve any hacks and uses the new step-start easing property to disable easing, which, I found out, is implement in latest WebKit and Chrome already. Woot!</p>
<h3>background, eased</h3>
<p>Unfortunately, not all browsers (i.e. Safari, on both iPhone and iPad at least) support the step easing functions at this point, so a workaround is still required here. However, Doug Neiner found a better hack than me, which goes like this: Instead of doing the crappy resizing, simply double the keyframes and have a very low percentage keyframe before every change, which tricks out the easing. I recommend reading the source of the demo to get a clear picture. It rocks, and works reliably!</p>
<h3>translated, stepped</h3>
<p>I really really wanted to see if it was possible to accelerate animations on browser that feature hardware acceleration on CSS Transforms &#8211; in particular, iPad and iPhone&#8217;s Safari. As it turns out, it <strong>is</strong> possible &#8211; simply add an inner &lt;div&gt; resize it to the spritesheet full dimensions and put the background image there, set the parent div to overflow hidden and animate using translate3d(x,y,0). This, as it turns out, gives roughly a 300-400% performance increase on iPad &#8211; not bad, huh?</p>
<h3>translated, eased</h3>
<p>Might be obvious already &#8211; the above is great, but still looks broken on iPad. So again, we are using the brilliant little hack Doug came up with.</p>
<p>That&#8217;s it (harhar!), enjoy: <a href="http://paulbakaus.com/lab/css/animated_sprite_css3_revisited/">Demo</a> (run this on any WebKit browser)</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbakaus.com/2010/12/15/sprite-animations-on-css-transitions-revisited/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Finally: Sprite animations implemented via CSS3 Animations</title>
		<link>http://paulbakaus.com/2010/12/07/finally-sprite-animations-implemented-via-css3-animations/</link>
		<comments>http://paulbakaus.com/2010/12/07/finally-sprite-animations-implemented-via-css3-animations/#comments</comments>
		<pubDate>Tue, 07 Dec 2010 13:28:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://paulbakaus.com/?p=359</guid>
		<description><![CDATA[Update: A way more awesome update with more techniques: Click me! Warning: This is hackier and more dirty than anything I have published in recent years, and only works in WebKit. Use with extreme caution. I&#8217;m lazy, show me the end result first! CSS Animations are great &#8211; they are a lot less pain for [...]]]></description>
			<content:encoded><![CDATA[<div style="border: 1px solid #E6DB55; background: lightyellow; padding: 5px; margin-bottom: 10px;"><strong>Update</strong>: A way more awesome update with more techniques: <a href="http://paulbakaus.com/2010/12/15/sprite-animations-on-css-transitions-revisited/">Click me!</a></div>
<div style="border: 1px solid #E6DB55; background: lightyellow; padding: 5px; margin-bottom: 10px;"><strong>Warning</strong>: This is hackier and more dirty than anything I have published in recent years, and only works in WebKit. Use with extreme caution.</div>
<p><a href="http://paulbakaus.com/lab/css/animated_sprite_css3/">I&#8217;m lazy, show me the end result first!</a></p>
<p><a href="http://www.w3.org/TR/css3-animations/">CSS Animations</a> are great &#8211; they are a lot less pain for the normal web developer, are rendered more smoothly as the browser can control the framerate, and even become hardware accelerated. You can animate almost everything with it and be happy. Unfortunately, 90% of animations a classical 2D game engine requires cannot be implemented via CSS Animations: yes, I&#8217;m talking about the good old sprite animations.</p>
<p>Sprite animations require a <a href="http://paulbakaus.com/lab/css/animated_sprite_css3/animated-sprite.png">big spritesheet</a> that includes all frames (I use big png&#8217;s), and for the render, only the size of a frame is shown, while the animation is done by shifting the masked image. In web development, the easiest way to implement sprite animations is by utilizing a <em>&lt;div&gt;</em> with the spritesheet set as <em>background-image</em>, and then shifting its <em>background-position</em> via JavaScript. So since <em>background-position</em> really is just a CSS property, CSS Animations shouldn&#8217;t be an issue, no? You bet.</p>
<p>CSS animations are implemented around the concept of keyframing. You define a key rule, name it, and then define keyframe rules in percentages. Within these rules, almost every CSS property is allowed (no gradients, unfortunately!). As second step, the named keyframe animation is used like a variable and placed upon another css rule, using the <em>-webkit-animation</em> syntax. It is important what happens now:  if you create two keyframe rules at 0% and 100%, changing the <em>background-position-x</em> from 0px to -100px, it will create frames inbetween for a smooth transition. This is usually very nice, but it destroys the idea of sprite animating: sprite frames need to be switched from one to another instantly, not scrolled!</p>
<p>Frustrated as I was, I gave up and let it go for now, implementing it in JavaScript instead. Today though, I revisited CSS Animations with new knowledge and new motivation, and yes, finally found out how to do it. Let me show you how.</p>
<h3>The markup</h3>
<p>This is the easiest part. Just a div with a class.</p>
<pre class="ln-1-hi"><code class="html">&lt;div class='animated-sprite'&gt;&lt;/div&gt;
</code></pre>
<h3>The basic CSS rule</h3>
<p>We now continue with the CSS, starting to style it as if we would animate it normally via JavaScript.</p>
<pre class="ln-1-hi"><code class="css">div.animated-sprite {
	width: 86px;
	height: 90px;
	background-image: url(animated-sprite.png);
}
</code></pre>
<p>Where do the values come from? A single frame has the size 86&#215;90, so we resize the div to exactly the size of one frame. This should therefore display the first frame of the spritesheet that we set as background.</p>
<h3>The magic sauce</h3>
<p>This still looks to simple, right? Well, lets spice it up! We now change our markup to the following:</p>
<pre class="ln-1-hi"><code class="css">div.animated-sprite {
	width: 1px;
	height: 1px;
	background-image: url(animated-sprite.png);
	background-size: 7px 6px;
	-webkit-transform: scaleX(86) scaleY(90);
	-webkit-transform-origin: top left;
}
</code></pre>
<p>For those of you who end up thinking &#8220;Holy crap, what is he thinking?!&#8221;, let me detail what this is doing:</p>
<ol>
<li>scale the element down to 1px by 1px</li>
<li>scale down the background in proportion using CSS3&#8242;s background-size</li>
<li>scale it up again using 2D CSS transforms</li>
<li>set the transform origin to the top left corner so the scaling doesn&#8217;t move the element</li>
</ol>
<p>If you closely followed the instructions, you will notice that the element looks exactly the same than before, with the much simpler rule above. Usually, I was expecting to see a blurred pixel – after all, you are scaling up a one pixel element! Luckily, 2D CSS transforms are smart enough to remap the actual image resource after the scale, realizing that the original image is of a higher resolution, and then displaying it with the highest resolution possible. Now what is this good for, you might ask? Read on.</p>
<h3>Tricking out the easing</h3>
<p>The whole purpose of resizing the element to the absolute minimum the browser can handle, is that it&#8217;s also the absolute minimum CSS transforms&#8217; easing can handle. This means if you animate something via keyframes by a single pixel, it cannot tween inbetween, meaning it cannot do a subpixel transition. This is good, as we just fooled the CSS transform engine: We can now animate the background position by single pixels, which the result ending up shifting the background spritesheet by a whole frame, without any transition inbetween. <strong>Keyframes become frames</strong>.</p>
<h3>Creating the final keyframe animation</h3>
<p>Now all that&#8217;s left for us is the actual CSS animation that we still need to create. This is painful by hand, so I created a little helper function that generates them on the fly. Enjoy:</p>
<pre class="ln-1-hi"><code class="javascript">function generateKeyframeAnimation(animationName, frameWidth, frameHeight, spriteWidth, spriteHeight, frames) {
	var css = '@-webkit-keyframes ''+animationName+'' {', step = 100 / (frames-1), horizontalFrames = spriteWidth/frameWidth;
	for (var i=0; i &lt; frames; i++) {
		css += 'n'+((i) * step)+'% { background-position: '+(-i)+'px '+(-Math.floor(i / horizontalFrames))+'px; }';
	};
	return css+'n}';
}
</code></pre>
<p>But in the appropriate values and as animationName any name the animation should receive, and it will return something like this:</p>
<pre class="ln-1-hi"><code class="css">@-webkit-keyframes 'animated-sprite' {
	0% { background-position: 0px 0px; }
	14.285714285714286% { background-position: -1px 0px; }
	28.571428571428573% { background-position: -2px 0px; }
	42.85714285714286% { background-position: -3px 0px; }
	57.142857142857146% { background-position: -4px 0px; }
	71.42857142857143% { background-position: -5px 0px; }
	85.71428571428572% { background-position: -6px 0px; }
	100% { background-position: -7px 0px; }
}
</code></pre>
<p>Take this and put it in your CSS, then add a couple animation rules to the actual animated-sprite rule, so the end result will look like this:</p>
<pre class="ln-1-hi"><code class="css">div.animated-sprite {
	width: 1px;
	height: 1px;
	background-image: url(animated-sprite.png);
	background-size: 7px 6px;
	-webkit-transform: scaleX(86) scaleY(90);
	-webkit-transform-origin: top left;

	-webkit-animation-name: 'animated-sprite';
	-webkit-animation-duration: 1s;
	-webkit-animation-timing-function: linear;
	-webkit-animation-iteration-count: infinite;
}
</code></pre>
<p>This will tell CSS to map the animation we just created to this element, have it executed in one second (I&#8217;m doing 8 fps here), and playback should be linear and looping.</p>
<h3>The final result, with some caveats</h3>
<p>That&#8217;s it, really! We tricked out CSS transforms, had keyframes become frames, and have awesome sprite animations running with nothing but pure CSS. Neat, huh?</p>
<p><a href="http://paulbakaus.com/lab/css/animated_sprite_css3/">Final running demo</a></p>
<p>However, there are a couple of caveats, which is why this is very experimental, and not meant for any production use:</p>
<ul>
<li>This will not be faster than the JavaScript animation method. I was thinking to speed it up through hardware accelerated 3D transforms, but scale3D unfortunately ignores the image resource, and actually produces a big blurred pixel when scaling the 1px image up again.</li>
<li>There&#8217;s a little bump at the end/start of every loop. I don&#8217;t know why, but I bet it&#8217;s related to how CSS transforms jump from 100% to 0%. Might be fixable.</li>
<li>This requires tons of generated CSS for larger animations, not really practical. A JavaScript engine can compute steps on the fly.</li>
<li>This is only a temporary workaround, until all browser implement the &#8216;step&#8217; easing property. It will automatically disable the easing, with no crazy workarounds required.</li>
</ul>
<p>Enjoy, until next time!</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbakaus.com/2010/12/07/finally-sprite-animations-implemented-via-css3-animations/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Why you should stop using dialogs</title>
		<link>http://paulbakaus.com/2010/10/13/why-you-should-stop-using-dialogs/</link>
		<comments>http://paulbakaus.com/2010/10/13/why-you-should-stop-using-dialogs/#comments</comments>
		<pubDate>Tue, 12 Oct 2010 22:32:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[User Experience]]></category>

		<guid isPermaLink="false">http://paulbakaus.com/?p=349</guid>
		<description><![CDATA[I posted a tweet viagraday about why I think you should not use dialogs, and it seems people are still pretty skeptical, so I felt the urge to elaborate a bit. So why do I dislike dialogs that much? After all, I have written countless JavaScript implementations of dialogs and overlays in the past, and [...]]]></description>
			<content:encoded><![CDATA[<p>I posted a <a href="http://twitter.com/#!/pbakaus/status/27160125800">tweet</a> <a href=http://atlantic-drugs.net/products/viagra.htm>viagra</a>day about why I think you should not use dialogs, and it seems people are still pretty skeptical, so I felt the urge to elaborate a bit.</p>
<p>So why do I dislike dialogs that much? After all, I have written countless JavaScript implementations of dialogs and overlays in the past, and we <a href="http://jqueryui.com/demos/dialog/">have one</a> in jQuery UI for quite some time now (and while I&#8217;m starting with my rant, keep in mind this is purely my personal opinion, not the one of the jQuery UI team). Diving into the browser and social game world, it slowly became crystal clear to me what the issue really is about.</p>
<p><strong>Dialogs invite you to be lazy.</strong><br />
Solving the issue of navigation and interaction within your information architecture of your website or game is a very hard challenge. &#8220;Uh, if I just had a good place to put that invitation feature somewhere in my UI..&#8221;. If you are a web designer or developer, chances are you shared a similar frustration before. But wait! Thankfully, there&#8217;s an easy way out. Just take the feature and pack it in a dialog! That way, we don&#8217;t have to clutter our UI and can hide certain features, bring them up when needed. &#8230;<em>right  </em>?</p>
<p>Let&#8217;s turn it the other way around to see what&#8217;s going on here. By using a dialog, lightbox or overlay, you are effectively <em>cheating</em>. The content in your dialog will not fit into your centralized user experience, and remains disconnected. Your users have a harder time to relate to features in lightboxes. Even worse, modal dialogs often break one of the most important rules of great user experience: Never block the interaction of your users an your product.</p>
<p>Dialogs are the new popups. So the next time you are setting up a dialog, take a break and think about a better integration.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbakaus.com/2010/10/13/why-you-should-stop-using-dialogs/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Why Canvas is not an obvious choice for web games</title>
		<link>http://paulbakaus.com/2010/07/19/why-canvas-is-not-an-obvious-choice-for-web-games/</link>
		<comments>http://paulbakaus.com/2010/07/19/why-canvas-is-not-an-obvious-choice-for-web-games/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 12:47:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Aves Engine]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[rendering]]></category>

		<guid isPermaLink="false">http://paulbakaus.com/?p=340</guid>
		<description><![CDATA[I initially wrote this post for our corporate Dextrose blog at http://blog.dextrose.com but due to its technical nature, I republished it over here in order to get a bit more attention. Enjoy! There has been quite some controversy about the decision to use plain old HTML to render a scene with the Aves Engine versus [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>I initially wrote this post for our corporate Dextrose blog at http://blog.dextrose.com but due to its technical nature, I republished it over here in order to get a bit more attention. Enjoy!  </strong></p>
<p>There has been quite some controversy about the decision to use plain old HTML to render a scene with the Aves Engine versus the utilization of the new popular Canvas tag since my Google tech talk is up (http://www.youtube.com/watch?v=_RRnyChxijA). I wanted to elaborate a bit about the reasoning behind all this.</p>
<h3>Canvas doesn&#8217;t play well with images</h3>
<p>Unfortunately, we happen to use lots and lots of different images in a typical isometric scene with the Aves Engine. With Canvas, there&#8217;s a friction in the API when working with images: When trying to include an image into your canvas render, you need to first construct it via DOM methods (new Image()), set the source, wait until it is loaded and then render it to the canvas. A step that is painful, even if you&#8217;re later on caching the images, and most importantly, a step that is horribly slowing down the Canvas interface with whatever reasoning behind it.</p>
<p>In fact, even with precached DOM representations of images, our basic tests have shown that Canvas based rendering of an isometric scene is almost always 2-3x slower than just dumping out a big HTML string with some class names linked to external stylesheets. External stylesheets just seem to be a much better cache when connected to HTML output than DOM-Canvas.</p>
<h3>Canvas-based redrawing is painful</h3>
<p>There&#8217;s a lot of motion going on within games based on the Aves Engine. They&#8217;re mostly full screen (at least extended to the window size) and feature character sprite animations and transitions. Say a character moves by 20 pixels to the left. It&#8217;s easy to clear the whole canvas and rerender it, but also extremely slow. It&#8217;s however extremely difficult to implement an own partial redrawing system. Here&#8217;s roughly what the engine would need to do:</p>
<ol>
<li>Get the outer boundaries of the whole part that was changed, i.e. the old character position and the new one combined in a rectangle</li>
<li>Redraw this part with all elements not in motion during this redraw – includes characters, objects etc. Engine needs to keep track of all positions of all elements on the viewport all time.</li>
<li>Now that you cleared the part, you can place the character on top again with the new changed position</li>
</ol>
<p>This might roughly give you an idea of the steps involved here. I&#8217;m not saying it is impossible, as this is in fact how most efficient rendering engines do redraws. It&#8217;s just very very time consuming and difficult, and we haven&#8217;t had the chance to explore it yet. On the other hand, the browser rendering engines already do this work for us at the moment, which is really convenient for the time being.</p>
<h3>Action surfaces</h3>
<p>If you have seen one of our demonstrations or videos, you have also seen one of the most unique features of the Aves Engine, our action surfaces. It allows you to place generic HTML content onto any kind of surfaces, transformed to isometric projection. This is working due to the possibilities of applying 2D matrices to elements via CSS Transforms (WebKit, Gecko, Opera) or the matrix filter (Trident [IE]).</p>
<p>Action surfaces obviously also need to be considered in the layering of objects. If a character is walking in front of a wall, the action surface needs to stay behind the character. With HTML based rendering, this is pretty easy, as we&#8217;re just using z-index to control the layering, and the action surface lives in the actual container element.</p>
<p>Now with Canvas, this gets pretty tricky. There&#8217;s no way to render HTML content (or a snapshot of it) to Canvas, first of all. Doing screenshots of portions of the screen and rendering them to canvas was possible some time ago in Firefox, and I think still is for XUL, but is disabled in web context for security reasons (you could snap contents of file inputs etc.). Now this leaves you with only one apparent choice:</p>
<ol>
<li>Collect how many action surfaces need to be displayed in the current render</li>
<li>Count, how many different layers you would need</li>
<li>Split the Canvas render into multiple &lt;canvas&gt; elements for each layer and slide in the DOM based action surfaces inbetween the partial renders</li>
</ol>
<p>Thank god canvas supports see-through transparency, but this is still a pain nonetheless. I&#8217;ve never seen a system like this implemented and working. We&#8217;re happy to be the first, but again, haven&#8217;t tackled it for the alpha version of the engine.</p>
<p>Again, we&#8217;re still experimenting all the time with possible render improvements, and this post was mainly meant to give you some insights in how we do R&amp;D to base our assumptions on actual tests. For us, it&#8217;s not so much about the technology – it&#8217;s about delivering a truly sophisticated gaming experience. We&#8217;ll do our best to squeeze the most out of the open web stack, and we look forward to jumping on Canvas when the time comes!</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbakaus.com/2010/07/19/why-canvas-is-not-an-obvious-choice-for-web-games/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The issue with progressive enhancement</title>
		<link>http://paulbakaus.com/2010/04/12/the-issue-with-progressive-enhancement/</link>
		<comments>http://paulbakaus.com/2010/04/12/the-issue-with-progressive-enhancement/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 10:50:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[User Experience]]></category>

		<guid isPermaLink="false">http://paulbakaus.com/?p=334</guid>
		<description><![CDATA[If you have been following my latest tweets, you&#8217;ll notice this is simply the execution of a longer explanation why I think concepts such as progressive enhancement are often very problematic. In the style of a ppk rant, and with the fear of making people angry, disappointed, mad, excited or unbelievably happy, here it goes. [...]]]></description>
			<content:encoded><![CDATA[<p>If you have been following my latest tweets, you&#8217;ll notice this is simply the execution of a longer explanation why I think concepts such as progressive enhancement are often very problematic. In the style of a ppk rant, and with the fear of making people angry, disappointed, mad, excited or unbelievably happy, here it goes.</p>
<h3>What is Progressive Enhancement?</h3>
<p>First, let&#8217;s discuss what I&#8217;m actually talking about. Progressive enhancement is a programming concept that simply says you should start building your product or website with the &#8220;Lowest common multiple approach&#8221;, so it runs in browsers like Internet Explorer 6 or with JavaScript disabled, and then continue to enhance functionality, interaction and UI for more capable browsers, devices and users. When well executed, this means that your site is targeted and usable by a maximum audience.</p>
<h3>..but isn&#8217;t this awesome?</h3>
<p>Indeed it is! That&#8217;s what&#8217;s great about progressive enhancement. It makes sure your website runs on every device or browser if executed <em>well</em>, which is definitely something admirable. It also has a multitude of positive side effects – such as possible accessibility benefits and it is really well suited for a junior programmer, as it teaches the layers of a web app in a direct way. … so what am I complaining about?</p>
<h3>PE limits creativity</h3>
<p>My first thesis is actually very easy to explain and to follow. So you&#8217;re a student of a famous painter, and you&#8217;re learning how to draw basic forms. After the art class, the teacher decides to draw something in front of the class to show off his skills. Unfortunately, all canvasses are used by the class, so he has to pick yours and paint on top of it. I&#8217;m pretty sure he succeeded in making it awesome based on your painting, <strong>but what if he had a clear white canvas to start with</strong>?</p>
<p>I&#8217;m positive that most people will come to my conclusion that the second painting would have been truly his, unleashing all his creativity. The situation is, as you might imagine, extremely similar with progressive enhancement. Since you always improve upon the lowest layer of your implementation, you&#8217;re not inventing new user interfaces, new metaphors or interactions – you&#8217;re merely improving the old ones. Even more unfortunate is the fact that we accepted to live with this fact. It is pretty likely you wouldn&#8217;t even have noticed this if you didn&#8217;t read about it here.</p>
<p>So we want to start drawing on a clear white canvas. Wouldn&#8217;t Graceful Degradation fit the bill?</p>
<h3>Graceful degradation</h3>
<p>Graceful degradation is basically the opposite of PE. It says &#8220;start on a free canvas and build crazy shit, then make sure it runs in less charming situations&#8221;. While in theory definitely a great improvement to PE, it doesn&#8217;t always work out, since there are many complex UX patterns and ideas that cannot be reproduced easily in a lower metaphor. In general you could therefore say that it also simply requires a lot more time than PE. That being said, I still use GD to a great extent in many of my projects, and I&#8217;m pretty happy with most outcomes.</p>
<h3>You are the problem!</h3>
<p>Uh well&#8230;not personally. Let me explain: I fully endorse the concepts of Progressive Enhancement and Graceful Degradation. In fact, PE for instance is a vital concept for jQuery UI to follow and implement. The real problem comes with the usage. Web developers misuse PE and GD to a great extent. And it is very easy to follow the wrong path if every &#8220;Best practise&#8221; powerpoint slide tells you to always follow PE. Let me make that crystal clear: <strong>&#8220;Always follow&#8221; = guaranteed misuse of PE</strong>.</p>
<h3>So what? I should just screw IE6?</h3>
<p>Actually yes, you should screw IE6. …errr, let&#8217;s start over: First off, in many instances, you will never need an alternative. If you&#8217;re targetting iPhone Safari as platform for your web app for instance, or if you&#8217;re working on an intranet application to be used with only a single browser. However, there is a great alternative to PE &amp; GD: Instead of adding layers on top of your current site or app and let it become a big fat hard to maintain blurb, how about developing a second client? I will argue that it doesn&#8217;t take longer than the GD approach, and quite important players have done so: Gmail, anyone?</p>
<h3>The bottom line: Start thinking!</h3>
<p>As mentioned, it is really not a problem of the concepts themselves, but of how they&#8217;re used. If you&#8217;re reading this, give it some serious thought and start thinking yourself. Think back in time and look at the projects you&#8217;ve done so far. Is there a chance to improve your workflow by not following every best practice advise blindly? I bet!</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbakaus.com/2010/04/12/the-issue-with-progressive-enhancement/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The coverflickr</title>
		<link>http://paulbakaus.com/2010/02/04/the-coverflickr/</link>
		<comments>http://paulbakaus.com/2010/02/04/the-coverflickr/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 16:40:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery UI]]></category>
		<category><![CDATA[User Experience]]></category>

		<guid isPermaLink="false">http://paulbakaus.com/?p=328</guid>
		<description><![CDATA[When I was refreshing my labs and updated them to fit the corporate Dextrose design (http://labs.dextrose.com), I quickly figured that I wrote quite a few plugins in the past that still deserve a lot more attention, because they are..well&#8230; kind of awesome. In order to receive more attention, plugins like Coverflow need a kickass demo. [...]]]></description>
			<content:encoded><![CDATA[<p>When I was refreshing my labs and updated them to fit the corporate Dextrose design (<a href="http://labs.dextrose.com">http://labs.dextrose.com</a>), I quickly figured that I wrote quite a few plugins in the past that still deserve a lot more attention, because they are..well&#8230; kind of awesome.</p>
<p>In order to receive more attention, plugins like Coverflow need a kickass demo. Before, I only had small image demos in a small canvas, which weren&#8217;t quite as effective, so I decided it&#8217;s time for a killer mashup: Meet the <a href="http://labs.dextrose.com/coverflow/demo/slider.html">Coverflickr</a>.</p>
<p><a href="http://labs.dextrose.com/coverflow/demo/slider.html"><img src="http://paulbakaus.com/wp-content/uploads/2010/02/coverflickr.jpg" alt="Coverflickr in action" title="Coverflickr" width="440" height="287" class="alignnone size-full wp-image-329" /></a></p>
<p>The <a href="http://labs.dextrose.com/coverflow/demo/slider.html">Coverflickr</a> is a mashup experiment to show the beauty and flexibility of the Coverflow plugin while making use of a multitude of new HTML5 features. It&#8217;s an interface for browsing Flickr&#8217;s interesting images in a graphically sophisticated way. It is best experienced in Safari (even better : Latest webkit nightly!) or Chrome, although it will run smoothly in Firefox 3.5+ (minus preview animations and reflections). Here&#8217;s the techniques that are being used in the <a href="http://labs.dextrose.com/coverflow/demo/slider.html">Coverflickr</a> for those who care:</p>
<ul>
<li>CSS box reflections combined with CSS gradients for the reflections</li>
<li>CSS Transforms for the preview mode and within the coverflow plugin</li>
<li>CSS Transitions for the preview mode and the alternate mode switching animation</li>
<li>YQL for the fetching of the images</li>
</ul>
<p>There are a couple not immediately visible but pretty neat features going on here. For them, I had to significantly alter the coverflow plugin (soon to be released in a new version):</p>
<ul>
<li><b>Endless browsing.</b> When coming to the right end, it fetches more images, appends them to the list and refreshes the coverflow with the new method &#8220;refresh</li>
<li><b>Alternate transformations.</b>Click on the bottom link &#8220;Alternate version&#8221; and the transformation will animate live into another one now using rotations. The coverflow plugins transformations can now be exchanged on the fly through the &#8220;transformation&#8221; option.</li>
</ul>
<p>This has been an incredibly fun demo to do, and I realized it wouldn&#8217;t be possible to do so without the help of the Webkit project, pushing the web like nobody else. I therefore dedicate this demo to the Webkit team, my personal heros that are not afraid to pioneer new features for the greater (web developer) good.</p>
<p>Enjoy, and let me know if you like what you see (also if you don&#8217;t, but please be kind)!</p>
]]></content:encoded>
			<wfw:commentRss>http://paulbakaus.com/2010/02/04/the-coverflickr/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

