<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>I like all things JavaScript and HTML5. I am the creator of Crafty and work for Mozilla.

Follow me on Twitter @louisstowFollow me on Github git.io/louis</description><title>Louis Stowasser</title><generator>Tumblr (3.0; @louisstow)</generator><link>http://louisstowasser.com/</link><item><title>Generate Table of Contents from Heading Tags in JavaScript</title><description>&lt;p&gt;I recently needed a way to generate a Table of Contents in some documentation. I wanted it to be automatic so I could freely write without having to worry about updating the table of contents. This turned out to be more difficult than I intended with very little available through Google. So I wrote my own function and making it available here for free!&lt;/p&gt;

&lt;script src="https://gist.github.com/louisstow/5052318.js" type="text/javascript"&gt;&lt;/script&gt;&lt;h3&gt;Usage&lt;/h3&gt;

&lt;p&gt;Set the &lt;code&gt;innerHTML&lt;/code&gt; of a DOM node to the string returned from &lt;code&gt;generateTOC&lt;/code&gt; where you want the Table of Contents to appear. Pass the parent DOM node into the function and optionally a start tag number if you want to start the table of contents at &lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt; instead of &amp;#8220;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;//save references to our DOM nodes
var navNode = document.getElementById("nav");
var parentNode = document.getElementById("content");

//generate the TOC and set the nav innerHTML to it
var generatedHTML = generateTOC(parentNode);
navNode.innerHTML = generatedHTML;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Feel free to direct all questions to the gist.&lt;/p&gt;</description><link>http://louisstowasser.com/post/44170412926</link><guid>http://louisstowasser.com/post/44170412926</guid><pubDate>Thu, 28 Feb 2013 08:53:00 +1000</pubDate><category>javascript</category><category>toc</category><category>html</category><category>heading</category><category>tutorial</category><dc:creator>craftyjs</dc:creator></item><item><title>Advergaming - The feedback loop between advertisers and players</title><description>&lt;p&gt;&lt;img src="http://media.tumblr.com/426feff1d3bb05b65ac4636f5a882833/tumblr_inline_minqs63jVg1qz4rgp.png" alt="Feedback loop"/&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Advergaming:&lt;/strong&gt; The feedback loop of players leading to advertisers which benefit and lead to more players. Rinse repeat.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As an incentive to play a game, you have the potential of earning benefits. I don&amp;#8217;t mean simply gambling; I&amp;#8217;m talking about participation in a game leading to real-world rewards from either other players or advertisers with a vested interest.&lt;/p&gt;

&lt;p&gt;The more players a game has, the more valuable it would be for advertisers. The more advertisers are involved in the game, the more incentives there are to play the game thus spawning more players&amp;#8230; and so on.&lt;/p&gt;

&lt;p&gt;There are three ways to integrate this into a game that I can think of:&lt;/p&gt;

&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sponsorship -&lt;/strong&gt; a player is &amp;#8216;sponsored&amp;#8217; by an advertiser to display an ad in-game or through an avatar.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Acquisition -&lt;/strong&gt; in-game properties or items owned by a player can be bought by an advertiser to display ads or an external link.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Campaign -&lt;/strong&gt; advertisers can offer prizes to winners in a game run by the advertiser complete with their branding.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;&lt;a href="http://pixenomics.com"&gt;Pixenomics&lt;/a&gt; is game modelled after &lt;code&gt;Acquisition&lt;/code&gt;. Players own pixels on a large canvas which can be bought by advertisers seeking that space on the board for ads.&lt;/p&gt;

&lt;p&gt;To kickstart the loop you need an amount of players that is large enough to get the interest of advertisers. To get players, especially organically, the game must be fun with or without other players (something &lt;a href="http://pixenomics.com"&gt;Pixenomics&lt;/a&gt; is lacking).&lt;/p&gt;

&lt;p&gt;As this is just a concept I have no real studies or real-world examples to show but I would be interested in seeing how an idea like this could be executed.&lt;/p&gt;</description><link>http://louisstowasser.com/post/43781903674</link><guid>http://louisstowasser.com/post/43781903674</guid><pubDate>Sat, 23 Feb 2013 15:12:00 +1000</pubDate><dc:creator>craftyjs</dc:creator></item><item><title>Custom Canvas Drawing in CraftyJS</title><description>&lt;p&gt;A lot of people have asked about this and I thought it&amp;#8217;s about time I write up a quick example for custom drawing on the canvas in a way that doesn&amp;#8217;t break the redraw regions.&lt;/p&gt;

&lt;p&gt;The first thing to ensure is that the &lt;strong&gt;entity&amp;#8217;s width and height is large enough to encapsulate the entire drawing&lt;/strong&gt; so the redraw region manager knows how much to clear.&lt;/p&gt;

&lt;p&gt;The second thing to do is &lt;strong&gt;overwrite the &lt;code&gt;draw&lt;/code&gt; method&lt;/strong&gt;. In there we can do our custom 2D canvas drawing.&lt;/p&gt;

&lt;p&gt;My example is a Circle drawer. It requires a radius and color:&lt;/p&gt;

&lt;iframe style="width: 100%; height: 300px" src="http://jsfiddle.net/KfDY2/2/embedded/" allowfullscreen="allowfullscreen" frameborder="0"&gt;&lt;/iframe&gt;

&lt;p&gt;As you can see I set the width and height to the size of the circle (&lt;code&gt;radius * 2&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;I also create a &lt;code&gt;draw&lt;/code&gt; method which draws a circle at the entity&amp;#8217;s &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; position with an offset of the the &lt;code&gt;radius&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s as simple as that. We can have some fun with the custom renderer by adding the &lt;code&gt;Tween&lt;/code&gt; component and decreasing the radius over 500 frames.&lt;/p&gt;

&lt;iframe style="width: 100%; height: 300px" src="http://jsfiddle.net/KfDY2/1/embedded/" allowfullscreen="allowfullscreen" frameborder="0"&gt;&lt;/iframe&gt;</description><link>http://louisstowasser.com/post/21479078234</link><guid>http://louisstowasser.com/post/21479078234</guid><pubDate>Sat, 21 Apr 2012 14:31:00 +1000</pubDate><category>crafty</category><category>canvas</category><category>html5</category><category>drawing</category><dc:creator>craftyjs</dc:creator></item><item><title>External Documentation Proposal for Exposed APIs</title><description>&lt;p&gt;I have been playing around with various methods of documentation and for a while I thought the way to go was inline documentation where the documentation exists within the source code, but I&amp;#8217;ve noticed a few flaws in this approach.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Who is the target reader?&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Inline documentation doesn&amp;#8217;t make sense if the end user has no knowledge or interest in the source. It should exist to teach the reader how and why the code works from the perspective of someone interested in the internals. For a developer who just wants to make use of the API, why include it with the source?&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Forcing Object-Oriented-ness&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;JSDoc in particular generates documentation similar to JavaDoc; a strictly Object Oriented language. This doesn&amp;#8217;t cross over well when you have things such as chaining, currying or other JavaScript oddities.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;The solution&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://twitter.com/#!/DamonOehlman"&gt;Damon Oehlman&lt;/a&gt; wrote about &lt;a href="https://github.com/DamonOehlman/damonoehlman.github.com/issues/4"&gt;using a Domain Specific Language (DSL)&lt;/a&gt; in an external document for API documentation. In his example developers would use some specific representations of how to use the API using text.&lt;/p&gt;

&lt;p&gt;I imagine a structure where the documentation mimics the source code file structure, but for every code file a documentation file exists in its place. These files will be a superset of Markdown with extra formatting to denote namespaces, signature overloading, types and internal links. A generator would then convert the structure into HTML pages.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ll start with an example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#Core.Crafty()
&amp;gt;Crafty(selectors:string) =&amp;gt; &amp;lt;Core.Entity&amp;gt;
&amp;gt;Crafty(entityID:number)  =&amp;gt; &amp;lt;Entity&amp;gt;
Select a set of or single entities by components or an entity's ID.

Crafty uses syntax similar to jQuery by having a selector engine to 
select entities by their components. Selecting by multiple components
is done by seperating with a comma or a space. A comma is similar
to OR where the entities can match one or more of the components. 
A space is similar to AND where entities have to match all the 
components.

##Example
    Crafty("MyComponent")
    Crafty("Hello 2D Component")
    Crafty("Hello, 2D, Component")

The first selector will return all entities that has the component 
MyComponent. The second will return all entities that has Hello 
and 2D and Component whereas the last will return all entities that
has at least one of those components (or).

**See also: &amp;lt;Crafty.map.search&amp;gt;**
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In Markdown, a line starting with a single &lt;code&gt;#&lt;/code&gt; means Heading 1. This will also denote a &lt;strong&gt;&lt;em&gt;unit&lt;/em&gt;&lt;/strong&gt; of code to document; such as a function, namespace or variable. It will also be used as the path for any other references in the documentation.&lt;/p&gt;

&lt;p&gt;Grouping can be done by creating a path with a dot &lt;code&gt;.&lt;/code&gt; as the separator. This could be used for categorising units of code or specifying a namespace path or even both at the same time!&lt;/p&gt;

&lt;p&gt;As per Damon&amp;#8217;s example, the greater than symbol &lt;code&gt;&amp;gt;&lt;/code&gt; denotes a method signature where you specify the arguments as &lt;code&gt;name:type&lt;/code&gt; (name is optional). The return type is specified after &lt;code&gt;=&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In my example the return type is wrapped in &amp;lt;angled brackets&amp;gt;. This represents an internal link to another &lt;strong&gt;&lt;em&gt;unit&lt;/em&gt;&lt;/strong&gt;. You may either specify the full path (as specified after the &lt;code&gt;#&lt;/code&gt;) or use a subset of the path (assuming no collision) and the generator will pick it up.&lt;/p&gt;

&lt;p&gt;Special files could be used for an Introduction, License information and even tutorials.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#Tutorial.RPG Demo
My tutorial formatted in Markdown!
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The output of this format would be a hierarchy of &lt;strong&gt;&lt;em&gt;units&lt;/em&gt;&lt;/strong&gt; where each unit has its own HTML page. Templates for headers and footers would allow stronger customisation.&lt;/p&gt;

&lt;p&gt;I would be interested in hearing some ideas on the subject. I think external documentation can create a greater separation between how to use the code and how the code works. It avoids huge source code files and can let the developers document in the format that suits the project.&lt;/p&gt;</description><link>http://louisstowasser.com/post/21373380293</link><guid>http://louisstowasser.com/post/21373380293</guid><pubDate>Thu, 19 Apr 2012 18:16:00 +1000</pubDate><category>documentation</category><category>api</category><category>docs</category><category>markdown</category><dc:creator>craftyjs</dc:creator></item><item><title>HashBBG.com Sneak Peek</title><description>&lt;p&gt;I had a go playing around with Drupal for the new and improved &lt;a href="http://hashbbg.com"&gt;#BBG&lt;/a&gt; community site. It was surprisingly easy to get started and build a dynamic site. The content type feature was very helpful for customizing the data that BBG members will be posting.&lt;/p&gt;

&lt;p&gt;The current content types are:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Projects&lt;/strong&gt;: This is if members have created a project and want to share it. You can specify the repo and homepage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Links&lt;/strong&gt;: Sharing relevant links for HTML5 game development.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Text Posts&lt;/strong&gt;: Purely text for those who don&amp;#8217;t want a full blog but feel like writing about what they are working on.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Screenshots&lt;/strong&gt;: An image and short description of the latest preview for any work in progress projects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Poll&lt;/strong&gt;: A standard poll to get a general opinion from the community.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;All these posts will be aggregated under the members page as well as categorised for newcomers. This entire site was very quick to put together thanks to some great Drupal modules, not to mention a handy skill to learn for any future dynamic sites.&lt;/p&gt;

&lt;p&gt;I have included a screenshot and will upload the site in the next couple of days or so.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://i.imgur.com/zr6Uv.png"&gt;&lt;img src="http://i.imgur.com/zr6Uv.png" width="500"/&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://louisstowasser.com/post/20769335140</link><guid>http://louisstowasser.com/post/20769335140</guid><pubDate>Mon, 09 Apr 2012 17:59:00 +1000</pubDate><dc:creator>craftyjs</dc:creator></item><item><title>A new direction for #BBG</title><description>&lt;p&gt;If you haven&amp;#8217;t heard of &lt;strong&gt;#BBG&lt;/strong&gt;, &lt;a href="http://bit.ly/ircbbg"&gt;check it out now&lt;/a&gt;! It&amp;#8217;s an IRC channel on &lt;code&gt;freenode.net&lt;/code&gt; dedicated to browser based games (regardless of your chosen tech) and boasts a variety of industry professionals from authors to engine developers.&lt;/p&gt;

&lt;p&gt;We have a site dedicated to the community at &lt;a href="http://hashbbg.com"&gt;hashbbg.com&lt;/a&gt; but we think it&amp;#8217;s time for a revamp.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Categories&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;First of all we want to add categories on the home page so newcomers can see the latest and greatest games, tutorials, podcasts, blogs etc from the community and find out the developers responsible. The best part is they can then chat to the developers on #BBG!&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Profile Page&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Members should be able to post links to anything new they are working on or have recently created. This would be posted on their profile page as well as in a feed on the home page (and a tweet from &lt;a href="http://twitter.com/HashBBG"&gt;@HashBBG&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Events&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;We will need to add sections for the various events such as the BBGMeetup and BBGChallenge. The BBGMeetup will be more frequent once we secure some members who want to participate regularly.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Ask an HTML5 Dev&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Myself and &lt;a href="http://twitter.com/andrew_j_baker2"&gt;Andrew J Baker&lt;/a&gt; started a series on &lt;a href="http://www.html5grind.com/2011/08/06/ask-an-html5-dev-how-do-you-profile-your-code/"&gt;HTML5Grind&lt;/a&gt; where the community would decide on a question to ask professional HTML5 developers and we would compile a list of responses from members. We intend to bring that back.&lt;/p&gt;

&lt;p&gt;Essentially we want a place where BBG members can post the amazing stuff they&amp;#8217;re working on and where newcomers can discover the great developers behind the work. The site will be a community effort so any help is appreciated.&lt;/p&gt;</description><link>http://louisstowasser.com/post/20337345669</link><guid>http://louisstowasser.com/post/20337345669</guid><pubDate>Mon, 02 Apr 2012 15:44:01 +1000</pubDate><category>html5</category><category>gamedev</category><category>bbg</category><category>browser games</category><category>community</category><category>irc</category><dc:creator>craftyjs</dc:creator></item><item><title>Recent Posts widget in Tumblr</title><description>&lt;p&gt;Pure JavaScript and less than 600 bytes. This will create an unordered list of recent posts from the blog of your choosing in a div that will replace the script tag.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Unminified (864 bytes):&lt;/strong&gt;&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;script type="text/javascript"&amp;gt;
(function(blog, limit) {
limit = +limit || 10;

var scriptTags = document.getElementsByTagName('script');
var scriptNode = scriptTags[scriptTags.length - 1];
var recent = document.createElement("div");
scriptNode.parentNode.appendChild(recent);
recent.setAttribute("class", "widget");
recent.setAttribute("id", "TumblrRecentPosts");

var script = document.createElement("script");
script.src = "http://" + blog + "/api/read/json";
script.onload = function(data) {
    if(!tumblr_api_read) return;

    var response = tumblr_api_read.posts;
    var post;
    var len = Math.min(response.length, limit);
    var html = "&amp;lt;ul&amp;gt;";

    for(var i = 0; i &amp;lt; len; ++i) {
        post = response[i];
        html += "&amp;lt;li&amp;gt;&amp;lt;a href='" + (post['url-with-slug'] || post.url) + "'&amp;gt;" + 
            post['regular-title'] + "&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;";
    }

    recent.innerHTML = html;
};

document.body.appendChild(script);

})("louisstow.tumblr.com", 30); //enter your settings here
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;&lt;strong&gt;Minified (573 bytes):&lt;/strong&gt;&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;script type="text/javascript"&amp;gt;
(function(d,e){var  e=+e||10,
a=document.getElementsByTagName("script"),
a=a[a.length-1],b=document.createElement("div");
a.parentNode.appendChild(b);b.setAttribute("class","widget");
b.setAttribute("id","TumblrRecentPosts");a=document.createElement("script");
a.src="http://"+d+"/api/read/json";a.onload=function(){if(tumblr_api_read){
for(var a=tumblr_api_read.posts,c,d=Math.min(a.length,e),f="&amp;lt;ul&amp;gt;",g=0;
g&amp;lt;d;++g)c=a[g],f+="&amp;lt;li&amp;gt;&amp;lt;a href='"+(c["url-with-slug"]||c.url)+"'&amp;gt;"+
c["regular-title"]+"&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;";b.innerHTML= f}};
document.body.appendChild(a)})
("louisstow.tumblr.com",30); //enter your settings here
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Place the &lt;code&gt;script&lt;/code&gt; tag where you want the unordered list to be in your HTML document. Enter the blog URL in the arguments and specify a limit to the number of posts to list (default being 10). My blog is &lt;code&gt;louisstow.tumblr.com&lt;/code&gt; or &lt;code&gt;louisstowasser.com&lt;/code&gt; and I specified a limit of 30 posts.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;It uses the old Tumblr API (accessed via &lt;code&gt;http://{Tumblr URL}/api/read/json&lt;/code&gt;) and runs it as a script. The script sets a global variable called &lt;code&gt;tumblr_api_read&lt;/code&gt;. This is a large object which includes public blog information and posts.&lt;/p&gt;

&lt;p&gt;Replacing the script tag is done by grabbing all script tags through &lt;code&gt;document.getElementsByTagName("script")&lt;/code&gt; where the last script will be the one currently executing (the one we want to replace). We can then append our created &lt;code&gt;div&lt;/code&gt; to the parent of the script tag.&lt;/p&gt;</description><link>http://louisstowasser.com/post/20208939711</link><guid>http://louisstowasser.com/post/20208939711</guid><pubDate>Sat, 31 Mar 2012 14:04:00 +1000</pubDate><category>recent posts</category><category>widget</category><category>tumblr</category><dc:creator>craftyjs</dc:creator></item><item><title>Self promotion should be encouraged</title><description>&lt;p&gt;The web seems to favour curation over creation. Self promotion is generally frowned upon and most will tell you sharing a mix of other&amp;#8217;s links and your own is more acceptable; but why? This only encourages curation and stunts creation.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Content is king&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Once upon a time this was the mantra of the web. Content above all else is most important. By this logic it doesn&amp;#8217;t matter where the content came from, as long as it is good quality content.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Self promotion is not always spam&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Some regard self promotion as a form of spam. Spam implies the content is unwanted which to me depends on the quality and frequency as opposed to whether the owner submited it for self gain.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Curation promotes reposts and stale content&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;We should be actively seeking new and quality content rather than sharing an already popular link otherwise known as reposts.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Good content goes to waste&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;It is very hard for content creators to get noticed. Think of how many blogs, tech articles, tutorials, videos, stories, games, music, tools, software, services or webcomics exist on the web. Some of them might be good, some might be great and not all of them will be discovered by curators.&lt;/p&gt;</description><link>http://louisstowasser.com/post/20196545657</link><guid>http://louisstowasser.com/post/20196545657</guid><pubDate>Sat, 31 Mar 2012 10:19:00 +1000</pubDate><dc:creator>craftyjs</dc:creator></item><item><title>Different monetization methods for HTML5 games and apps</title><description>&lt;p&gt;Monetization is one of many challenges when creating a game or app in HTML5. After all the effort it would only be fair to recieve minor compensation to keep development alive. The problem is deciding how to earn money from your creation while not affecting it&amp;#8217;s growth.&lt;/p&gt;

&lt;p&gt;A standard method is to offer a freemium model (free with ads, pay for more content). Another is in-game purchases. I was thinking about various other ways it could be done where the player has more incentive to pay.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Raffle&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Players would have to buy the game to enter (say for $1). The prize could be 10% of the proceeds or any other reward. Players can win by beating a level first or holding the highest score by a certain date.&lt;/p&gt;

&lt;p&gt;It would encourage players to buy the game, play it and most of all share it with friends as it would increase the winnings.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;In-game product placement&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;This is just another form of advertising but more subtle than an attention grabbing advertisment blocking half the screen. In-game items that advertise a brand name would be less obtrusive and most likely more effective. Finding sponsors wouldn&amp;#8217;t be easy but there are other sources such as affiliate marketing (see &lt;a href="https://affiliate-program.amazon.com/"&gt;Amazon Affiliate Program&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Sell unobfuscated and commented source code&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;With HTML5 games and apps the source code will always be there for all to see even if obfuscated. One may as well either publicly release it or offer the full commented and styled source code for a fee, should developers want to learn or expand on it.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Merchandise&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Companies like &lt;a href="http://cafepress.com"&gt;CafePress&lt;/a&gt; offer the ability to customise T shirts, stickers, posters and various types of merchandise to sell to loyal fans or even as a prize for the aforementioned raffle.&lt;/p&gt;

&lt;p&gt;There is definitely room for some creative forms of monetization that benefit the developer as well as the player. I would be interested in hearing other ideas.&lt;/p&gt;</description><link>http://louisstowasser.com/post/20111630185</link><guid>http://louisstowasser.com/post/20111630185</guid><pubDate>Thu, 29 Mar 2012 20:38:00 +1000</pubDate><category>html5</category><category>javascript</category><category>gamedev</category><category>monetization</category><category>apps</category><category>games</category><dc:creator>craftyjs</dc:creator></item><item><title>Simulating a player</title><description>&lt;p&gt;Automated tests are a great way to do a sanity check against any changes you feel might affect other areas. You can quickly run some tests and ensure components do as they&amp;#8217;re expected. This doesn&amp;#8217;t cross over well into game development because other factors come into play such as input, randomization, networking and other variables that affect the program.&lt;/p&gt;

&lt;p&gt;What&amp;#8217;s really needed is to be able to simulate a player and observing the outcome exactly as it was when it was logged. To do this, every single variable that affects the game state has to be logged with a timestamp so it can be played back at the exact same interval. This includes randomly generated numbers, click or keyboard events, network data, time etc etc.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Benchmarking&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;There are more use cases than just automated tests. You can use it for benchmarking so that every platform you test will involve the same gameplay and actions. Domsz has done this for his game engine, &lt;a href="http://html5-benchmark.com/"&gt;ImpactJS&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Validate High Scores&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Blindly accepting any high score as valid can and probably will lead to people sending requests with an obviously fake score. Sending the data to the server and replaying it to see what the end result is can be used to determine whether they cheated or not.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Multiplayer&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Simulating the input on the server can be used for multiplayer games to keep two or more players in sync and prevent players from cheating. There&amp;#8217;s obviously more to it than that but it&amp;#8217;s an idea.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Gameplay&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;It&amp;#8217;s now a common gameplay component to allow players to replay part of the game or for a stylised effect such as killcam.&lt;/p&gt;

&lt;p&gt;For games that are heavily randomly generated (which a lot are), there is the option to save the seed used so all that is needed is to use the same seed when replaying to generate the same random numbers. Not all random functions provide this feature (JavaScript doesn&amp;#8217;t). Another way around this is to log the generated value so when you replay it, use the same number that was generated last time.&lt;/p&gt;

&lt;p&gt;There is a great post about implementing such as thing known as &lt;a href="http://oddlabs.com/blog/?p=20"&gt;Deterministic Games&lt;/a&gt;. Unfortunately it is mainly relevant to the LWJGL framework.&lt;/p&gt;</description><link>http://louisstowasser.com/post/19668916090</link><guid>http://louisstowasser.com/post/19668916090</guid><pubDate>Wed, 21 Mar 2012 15:16:00 +1000</pubDate><category>deterministic games</category><category>simulation</category><category>gamedev</category><dc:creator>craftyjs</dc:creator></item><item><title>Performance framework proof-of-concept</title><description>&lt;p&gt;Performance is a very important factor for JavaScript games. It becomes
a crucial factor when you bring mobile devices into the mix.&lt;/p&gt;

&lt;p&gt;Luckily we have some great tools for testing different methods of coding
such as &lt;a href="http://jsperf.com"&gt;JSPerf&lt;/a&gt;. This lets developers test code snippets
across multiple browsers to compare.&lt;/p&gt;

&lt;p&gt;On the same vein, &lt;a href="https://github.com/facebook/jsgamebench"&gt;JSGameBench&lt;/a&gt; stress tests rendering methods including WebGL, Canvas and DOM.&lt;/p&gt;

&lt;p&gt;At Game Closure we want to look deeper and more thorough so I&amp;#8217;ve been thinking
about different ways to design a framework that will allow us to run tests
with an assortment of different methods and combinations. With JSPerf one has
to write individual test cases for every combination. Here is my proposal:&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Templates&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Code to test should have some templates that form the basis of what we&amp;#8217;re testing. 
It is similar to startup and teardown methods but finer grained.
You may want to move some startup code outside of the template to avoid it being
benchmarked unnecessarily.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Placeholders&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;This is the key component to the power of this testing framework. Add
placeholders in the template code that will be replaced based on
the combinations being tested. The placeholders are denoted by a
comment followed by a colon and the name of the placeholder.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function renderDOM() {
    dom.style.left = /*:x*/;
    dom.style.top = /*:y*/;
}

function renderCanvas() {
    ctx.drawImage(
        /*:type*/,
        /*:x*/,
        /*:y*/
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This looks like gibberish now but starts to make sense when you create
a list of different values for these placeholders in the form of an
object where the key is the name of the placeholder and the value
is an array of possible combinations to test:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;{
    x: [
        "~~x", 
        "x", 
        "Math.floor(x)"
    ],

    y: [
        "~~y", 
        "y", 
        "Math.floor(y)"
    ], 

    type: [
        "cnv", 
        "img"
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The test framework will use all the possible combinations of these values
testing to see which performs the best. You can also specify which functions
to test against. In our case the two functions are &amp;#8220;renderDOM&amp;#8221; and &amp;#8220;renderCanvas&amp;#8221;.
This means it will generate 36 combinations of the placeholders and functions.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Test it!&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Running a test requires the startup code, a template defined with relevant placeholders
and then an object with the combinations of values. You can optionally specify an
amount of iterations to run (it defaults to 1000).&lt;/p&gt;

&lt;p&gt;The above test gives us this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;~~x, ~~y, cnv, renderDOM | 28ms
~~x, ~~y, cnv, renderCanvas | 1222ms
~~x, ~~y, img, renderDOM | 18ms
~~x, ~~y, img, renderCanvas | 8ms
~~x, y, cnv, renderDOM | 33ms
~~x, y, cnv, renderCanvas | 1234ms
~~x, y, img, renderDOM | 33ms
~~x, y, img, renderCanvas | 8ms
~~x, Math.floor(y), cnv, renderDOM | 18ms
~~x, Math.floor(y), cnv, renderCanvas | 1237ms
~~x, Math.floor(y), img, renderDOM | 18ms
~~x, Math.floor(y), img, renderCanvas | 8ms
x, ~~y, cnv, renderDOM | 25ms
x, ~~y, cnv, renderCanvas | 1305ms
x, ~~y, img, renderDOM | 24ms
x, ~~y, img, renderCanvas | 7ms
x, y, cnv, renderDOM | 54ms
x, y, cnv, renderCanvas | 1322ms
x, y, img, renderDOM | 55ms
x, y, img, renderCanvas | 7ms
x, Math.floor(y), cnv, renderDOM | 25ms
x, Math.floor(y), cnv, renderCanvas | 1301ms
x, Math.floor(y), img, renderDOM | 26ms
x, Math.floor(y), img, renderCanvas | 8ms
Math.floor(x), ~~y, cnv, renderDOM | 18ms
Math.floor(x), ~~y, cnv, renderCanvas | 1238ms
Math.floor(x), ~~y, img, renderDOM | 18ms
Math.floor(x), ~~y, img, renderCanvas | 8ms
Math.floor(x), y, cnv, renderDOM | 36ms
Math.floor(x), y, cnv, renderCanvas | 1235ms
Math.floor(x), y, img, renderDOM | 34ms
Math.floor(x), y, img, renderCanvas | 7ms
Math.floor(x), Math.floor(y), cnv, renderDOM | 18ms
Math.floor(x), Math.floor(y), cnv, renderCanvas | 1235ms
Math.floor(x), Math.floor(y), img, renderDOM | 18ms
Math.floor(x), Math.floor(y), img, renderCanvas | 7ms
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;A few things to note is my method of benchmarking is currently
very naive as this is a proof-of-concept. I will be looking into
more solid forms detailed in this &lt;a href="http://calendar.perfplanet.com/2010/bulletproof-javascript-benchmarks/"&gt;great post&lt;/a&gt;.
The other thing to note is some of these tests are essentially duplicates. The
renderDOM method doesn&amp;#8217;t use the &lt;code&gt;type&lt;/code&gt; placeholder so it generates combinations
that have already been run. This isn&amp;#8217;t really a problem and is more to
do with how you define your templates and placeholders.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Analysing the data&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Once we have this data we need a way to understand it and derive facts. I imagine a big table with the placeholders, functions and result as the columns and the combinations as the rows. You will be able to filter by placeholder values and sort ascending or descending on the result column.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Browsers&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Running these tests against different browsers can be useful to determine cross-browser optimization or things to avoid. It is therefore important to be able to view and compare all the results and how they performed on which browsers. To display this in a table, the execution time column would have to include the result from different browsers. This could be done by adding a column for each browser result and keeping the main result as an average.&lt;/p&gt;

&lt;p&gt;These ideas are still very early stage and I have only recently managed to get code executing from placeholders and generating combinations. I will do more research to determine how it can be more useful for existing projects and how to best display the data. Maybe even a GUI along the lines of JSPerf could make it more helpful.&lt;/p&gt;</description><link>http://louisstowasser.com/post/19503795723</link><guid>http://louisstowasser.com/post/19503795723</guid><pubDate>Sun, 18 Mar 2012 18:32:00 +1000</pubDate><dc:creator>craftyjs</dc:creator></item><item><title>Entity Component Systems: Inheritance vs Composition</title><description>&lt;p&gt;My methodology of choice for game development is something known as an
Entity Component System. Entities are game objects, they have no
functionality until you apply components. This avoids long chains of
inheritance so is easier to maintain and reuse.&lt;/p&gt;

&lt;p&gt;There are two ways to implement Entity Component Systems, through 
composition or inheritance.&lt;/p&gt;

&lt;p&gt;Crafty uses an entity component system through &lt;strong&gt;inheritance&lt;/strong&gt;. An entity
starts its life as a simple object, when you add a component the entity
inherits all the functionality. It is similar to one layer of multiple
inheritance (without the diamond problem) or mixins.&lt;/p&gt;

&lt;p&gt;This makes abstraction easier where components can reference any other
components without needing to know which component it is so long as they
both implement the same interface. Crafty does this for the DOM and 
Canvas components.&lt;/p&gt;

&lt;p&gt;There is an obvious problem with the lack of namespacing: naming collisions.
I personally haven&amp;#8217;t come across this yet (probably because I know the names
of the internals) but it seems others have. It&amp;#8217;s also not very elegant as your
entities end up as big blob objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Composition&lt;/strong&gt; seems to be the preferred way of doing things.
Through composition you would create an instance of the component and give
the entity a reference to it. This may seem elegant but how do components
talk to each other? The only way to go about component communication
is by giving the component a reference back to the entity.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;CompA = Class(Component, function() {
    this.method = function() {
        this.owner.getComponent("CompB").method();
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We can get a direct reference to another component through the entity (&lt;code&gt;this.owner&lt;/code&gt;) and
we have component communication. But there are a few problems with this solution.
First of all it&amp;#8217;s hideously verbose but worst of all it creates a tight coupling 
between CompA and CompB. What if we change the name or can&amp;#8217;t be sure what the 
component will be (say if there were two components that implement the same interface)?&lt;/p&gt;

&lt;p&gt;The solution to this is messages or events. Tell the entity the component wants
to send a message to all other components that want to listen. Other components
can register a callback to those messages and decide what to do.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;CompA = Class(Component, function() {
    this.method = function() {
        this.owner.sendMessage("doSomething");
    }
});

CompB = Class(Component, function() {
    this.method = function() {
        this.owner.recieveMessage("doSomething", this.doSomethingHandler);
    }

    this.doSomethingHandler = function() {
        //no coupling! :)
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now the components are completely seperate from each other and can be individually
replaced without worrying about dependencies. I mentioned my distaste for verbose
solutions but luckily in the land of JavaScript we can make nice short cuts.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;CompB = Class(Component, function() {
    this.onDoSomething = function() {
        //no coupling! :)
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The message dispatcher will just see if any components have a function called &amp;#8220;on&amp;#8221; + 
the message name and execute it.&lt;/p&gt;

&lt;p&gt;While this approach is very elegant and decoupled it&amp;#8217;s not a perfect solution. 
What about a component that changes the position of the entity. Sending a message
each time gets tedious especially if that component is never going to change or be
replaced (such as a Position component). In these situations keeping a reference
isn&amp;#8217;t so bad:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;CompB = Class(Component, function() {
    this.init = function() {
        this.Position = this.owner.getComponent("Position");
    }

    this.onDoSomething = function() {
        this.Position.x += 10;
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;My personal preference is through composition and message passing. It seems to be
more flexible and has no real drawbacks.&lt;/p&gt;</description><link>http://louisstowasser.com/post/19279778476</link><guid>http://louisstowasser.com/post/19279778476</guid><pubDate>Wed, 14 Mar 2012 15:36:00 +1000</pubDate><category>entity component</category><category>gamedev</category><category>javascript</category><category>inheritance</category><category>composition</category><dc:creator>craftyjs</dc:creator></item><item><title>Pointer Lock for building an FPS</title><description>&lt;p&gt;Now that Pointer Lock (formerly known as Mouse Lock) is semi-available in Chrome I decided to have a play with it.&lt;/p&gt;

&lt;p&gt;My friend &lt;a href="https://twitter.com/#!/andrew_j_baker2/"&gt;Andrew Baker&lt;/a&gt; has a very easy to use &lt;a href="http://steppe.fleetingfantasy.com/"&gt;2.5D renderer&lt;/a&gt; and a first person demo to go with it. I went about adding mouse support for the demo.&lt;/p&gt;

&lt;p&gt;Firstly you need to enable Pointer Lock in &lt;strong&gt;about:flags&lt;/strong&gt;. Put that in the address bar then scroll down to &amp;#8220;Enable Pointer Lock&amp;#8221; and relaunch Chrome.&lt;/p&gt;

&lt;p&gt;While reading the &lt;a href="https://developer.mozilla.org/en/API/Mouse_Lock_API"&gt;Pointer Lock API on MDN&lt;/a&gt; I noticed that Chrome requires the page to be in the fullscreen state. This is simple enough (note that &lt;code&gt;element&lt;/code&gt; is a DOMElement such as a canvas node):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;element.webkitRequestFullScreen()
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This revealed a problem. None of the keyboard events worked and the docs never mentioned this. After searching for a while I came across &lt;a href="http://blog.tojicode.com/2011/09/state-of-javascript-fullscreen-api.html"&gt;Brandon&amp;#8217;s blog post&lt;/a&gt; on the subject. To allow the keyboard events to work in fullscreen mode, you have to pass in the &lt;code&gt;ALLOW_KEYBOARD_INPUT&lt;/code&gt; constant:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;element.webkitRequestFullScreen(element.ALLOW_KEYBOARD_INPUT)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To request a pointer lock on an element, you must use &lt;code&gt;navigator.pointer.lock&lt;/code&gt;. In Chrome this is under the namespace &lt;code&gt;navigator.webkitPointer&lt;/code&gt;. To normalise this you will want to add the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;navigator.pointer = navigator.pointer || navigator.webkitPointer;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So after the request for fullscreen mode has been called we can request the pointer lock.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;navigator.pointer.lock(element, 
    function() { 
        console.log("Request Succeeded") 
    }, 
    function() { 
        console.log("Request Failed") 
    }
);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In my version of Chrome (17.0.963.79 on Windows 7) I noticed that neither of these callbacks were called. The second thing I noticed was &lt;strong&gt;a.&lt;/strong&gt; the cursor wasn&amp;#8217;t hidden and &lt;strong&gt;b.&lt;/strong&gt; the cursor wasn&amp;#8217;t actually locked and it could move out of the bounds of the element. The only feature that actually worked were the mouse events (&lt;code&gt;movementX/Y&lt;/code&gt;). To make use of this, just bind the element to the &lt;code&gt;mousemove&lt;/code&gt; event and the movementX/Y values will be in the event object:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var sensitivity = 0.4; //the lower the less sensitive
element.addEventListener("mousemove", function(e) {
    var pos = {
        movementX: e.movementX || e.webkitMovementX,
        movementY: e.movementY || e.webkitMovementY,
    };

    if(pos.movementX &amp;lt; 0) {
        Mars.turnLeft((-pos.movementX) * sensitivity);
    } else {
        Mars.turnRight(pos.movementX * sensitivity);
    }
}, false);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If the movementX value was negative then the mouse was moved to the left. The values are actually the change in position since it was moved or the delta. By adding a sensitivity multiplier you can manipulate how much of an effect the movement values have on the view.&lt;/p&gt;

&lt;p&gt;These new event values are great but isn&amp;#8217;t useful if the mouse isn&amp;#8217;t actually locked. I will have a play with non-stable versions of Chrome to see if it has been implemented but for now it&amp;#8217;s not very helpful.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://webtop.co/PointerLock/steppe.html"&gt;Checkout the latest demo from this article&lt;/a&gt; and tell me if it works on your browser or not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; I installed Chrome Beta (18.0.1025.56) and I can confirm it works perfectly :) The cursor is hidden and locked. Should be in the next release very soon! I look forward to the opportunities this creates for HTML5 games.&lt;/p&gt;</description><link>http://louisstowasser.com/post/19222862470</link><guid>http://louisstowasser.com/post/19222862470</guid><pubDate>Tue, 13 Mar 2012 14:34:00 +1000</pubDate><category>pointer lock</category><category>html5</category><category>javascript</category><category>fps</category><category>gamedev</category><dc:creator>craftyjs</dc:creator></item><item><title>Fixing CSS through a UI library</title><description>&lt;p&gt;I believe CSS is one of the best methods of building interfaces. If you&amp;#8217;ve used Swing, Tkinter or the like you will probably agree with me. The ability to style rectangles through selectors really segregates the data from the view.&lt;/p&gt;

&lt;p&gt;That being said there are many things I would change and have been doing so through a User Interface library (to be implemented in the Game Closure SDK).&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;1. Positions and Dimensions&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;With CSS you can set the position and dimensions in a few different units, the most useful being pixels (&lt;code&gt;px&lt;/code&gt;) and percentages (&lt;code&gt;%&lt;/code&gt;). There have been many occasions where I needed to use both in a calculation. For instance having a box with a height of &lt;code&gt;100%&lt;/code&gt; minus a few pixels. To do this in CSS you would need to either use JavaScript or change the structure of the HTML.&lt;/p&gt;

&lt;p&gt;My UI lib will take a basic expression such as: &lt;code&gt;100% - 30px&lt;/code&gt;. I was even toying with the idea of allowing developers to pass a callback for even more control over how it is calculated.&lt;/p&gt;

&lt;p&gt;CSS manages flow and automatically positions elements based on it&amp;#8217;s surrounding elements. This is very helpful when building a website. But building a user interface&amp;#8230; not so much. My UI lib treats every element as if it had &lt;code&gt;position: absolute&lt;/code&gt; applied. This may sound painful but it is made easier by the fact you can position elements using percentages and calculations. For instance imagine a UI with two columns:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;column1 = new Panel({
    left: 0,
    top: 0,
    width: "50%",
    height: "100%"
});

column2 = new Panel({
    left: "50%",
    top: 0,
    width: "50%",
    height: "100%"
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Easy!&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;2. The Box Model&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;This has recently become more of a known issue. The W3C box model is plain silly and believe it or not IE got it right (in my opinion). The W3C box model states that the width of an element is the inner most content. The IE box model states the width includes it&amp;#8217;s border, padding and inner content. Confusing? See the diagram below:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://upload.wikimedia.org/wikipedia/commons/b/bd/W3C_and_Internet_Explorer_box_models.png" alt="Box Models"/&gt;&lt;/p&gt;

&lt;p&gt;My UI lib takes the IE approach. This means you can set the width to a logical unit and change the border and padding to your hearts content without worrying about changing the width to match. You can actually use the IE box model in your CSS today by using &lt;code&gt;box-sizing: border-box&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can see a not so recent &lt;a href="http://webtop.co/ui/"&gt;live demo here&lt;/a&gt;. The currently supported properties are: borderColor, borderSize, borderRadius, backgroundColor, headerColor, padding, margin, fontSize, fontFamily, fontColor, textBaseline, lineHeight, opacity, width, height, left and top with more to come!&lt;/p&gt;</description><link>http://louisstowasser.com/post/19149918121</link><guid>http://louisstowasser.com/post/19149918121</guid><pubDate>Mon, 12 Mar 2012 09:58:27 +1000</pubDate><category>css</category><category>ui lib</category><category>box model</category><category>canvas</category><category>html5</category><dc:creator>craftyjs</dc:creator></item><item><title>Unobtrusive Game Engines</title><description>&lt;p&gt;We&amp;#8217;ve suddenly seen an uprising up HTML5 game engines over the last year.
To me not many of them stand out and that&amp;#8217;s a personal opinion. Maybe
because the things I look for in an engine is not actually an engine but
a library. The best engine is the one I can replace.&lt;/p&gt;

&lt;p&gt;I don&amp;#8217;t like the idea of being tightly coupled to a game engine. Too much
of the code base becomes unknown and at risk of deprecation or API changes.
I also don&amp;#8217;t want to be forced to use a methodology (MVC, entity component).
This is probably why we have so many engines. Every developer has their own
style and if they can&amp;#8217;t reflect that in an engine they get frustrated and 
make one that can.&lt;/p&gt;

&lt;p&gt;Take the UNIX philosphy: Rule of Separation: Separate policy from 
mechanism; separate interfaces from engines. 
&lt;a href="http://www.faqs.org/docs/artu/ch01s06.html"&gt;http://www.faqs.org/docs/artu/ch01s06.html&lt;/a&gt; &amp;#8216;Basics of the Unix Philosophy&amp;#8217;&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s my wishlist of the perfect game engine which from now on I shall call
library.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;1. Hook for tick and render&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;This is the most basic requirement for creating a game. An unobtrusive API
might be:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Game.tick(function(dt, frameNumber) {
    //register a callback on tick
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The render hook would be similar:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Game.render(function(ctx) {

});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The important thing here is that I still have control and I can easily
replace the library with something else that implements the same basic API.
Heck, I could write a basic wrapper should another engine not implement it.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;2. Input&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;An abstract layer for inputs that can generalise touch and mouse events
and even keyboard events.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Game.input(function(type, e) {
    //type = Click, Down, Up, Key
    //e = Event object includes position in form of Point
    //    or key code for keyboard events
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Generally you want to know if an entity lies within the position from
the event. Which leads us to our next feature.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;3. Maths&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Some basic algorithms commonly used in 2D games such as &lt;a href="http://www.sevenson.com.au/actionscript/sat/"&gt;SAT collision&lt;/a&gt;, 
polygons, points, rects, spatial data structures but again no dependence 
on how the entities are stored.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;//Point = {x: Number, y: Number}
Game.math.pointInRect(Point, Rect);

//Rect = {x: Number, y: Number, w: Number, h: Number}
Game.math.collision(Rect, Rect[]);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;However you organise game objects it should be simple enough to export it
to the Rect interface if it isn&amp;#8217;t stored like that already.&lt;/p&gt;

&lt;p&gt;For determining if the user clicked/touched our entity:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Game.input(function(type, e) {
    if(Game.math.pointInRect(e.point, entity.rect)) {
        //clicked/touched
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Even if this is too verbose it is simple enough for the developer to write
another abstraction that suits them.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;4. Mobile Support&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Most mobile browsers are capable of rendering the Canvas element. The 
issues arrive with resolution, aspect ratio and sizing the stage.&lt;/p&gt;

&lt;p&gt;We don&amp;#8217;t want an implementation that will be obtrusive so this can&amp;#8217;t be an
automatic fix.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;if(Game.isMobile) {
    Game.maintainRatio(DOMElement);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This would detect if the user is on a mobile device, make the specified
element &amp;#8220;fullscreen&amp;#8221; by scaling it as big as possible while maintaining the
aspect ratio and using a black background for a letterbox effect.&lt;/p&gt;

&lt;p&gt;Again, the problem here is this doesn&amp;#8217;t match all solutions and is the
reason this can&amp;#8217;t happen automatically. What if the game was meant to
stretch?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Game.stretch(DOMElement);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will make the specified element as big as the window (so it doesn&amp;#8217;t
matter if it&amp;#8217;s on mobile or not).&lt;/p&gt;

&lt;p&gt;To find out the size of the stage:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Game.width; //Number
Game.height; //Number
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;&lt;strong&gt;5. Modular&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;I see mobile support as more of a module or extension than part of the
core. Therefore the game library should allow extensions.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Game.extend({
    maintainRation: function(el) {},
    stretch: function(el) {}
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I haven&amp;#8217;t actually written this library, it&amp;#8217;s just my ideas for a game
library that would be flexible enough so developers can add their own
touch to it without being forced into a style or methodology they dislike.
Would love to hear feedback about this concept.&lt;/p&gt;

&lt;p&gt;Some initial code for proof of concept is up here: &lt;a href="https://github.com/louisstow/Game"&gt;&lt;a href="https://github.com/louisstow/Game"&gt;https://github.com/louisstow/Game&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://louisstowasser.com/post/19103446204</link><guid>http://louisstowasser.com/post/19103446204</guid><pubDate>Sun, 11 Mar 2012 15:19:00 +1000</pubDate><category>html5</category><category>javascript</category><category>game engine</category><category>game lib</category><dc:creator>craftyjs</dc:creator></item><item><title>The Return of Adventure Games</title><description>&lt;p&gt;Growing up I never really took a shine to adventure games. I was very impatient and didn&amp;#8217;t like to be mentally bested by a game. Only recently am I starting to see the appeal. My girlfriend is creating an &lt;a href="http://gamethesis.tumblr.com"&gt;HTML5 adventure game&lt;/a&gt; for her thesis (using Crafty) so I was introduced to the greats such as Day of the Tentacle.&lt;/p&gt;

&lt;p&gt;It would be a sin to not mention the massive success of &lt;a href="http://www.kickstarter.com/projects/66710809/double-fine-adventure"&gt;Double Fine&amp;#8217;s new adventure game project&lt;/a&gt;. This alone shows how nostalgic this genre is to many many gamers.&lt;/p&gt;

&lt;p&gt;This led me to think about implementing the genre for mobile devices and browsers. The genre is almost perfect for casual gaming. You can solve small puzzles in pockets of spare time and none of the immersion is lost.&lt;/p&gt;

&lt;p&gt;This then led me to think about a framework for building adventure games where various callbacks would help construct the puzzles and gameplay. Typically adventure games are built up of:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Scenes&lt;/li&gt;
&lt;li&gt;Actors&lt;/li&gt;
&lt;li&gt;Items&lt;/li&gt;
&lt;li&gt;Dialogue&lt;/li&gt;
&lt;li&gt;Actions&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Scenes&lt;/strong&gt; being small rooms or areas the player can explore to find items and solve puzzles. Callbacks for scenes would include entering a scene, exiting a scene.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var Intro = Class(Scene, function(supr) {
    this.init = function(opts) {};

    this.onEnter = function(previousScene) {};
    this.onExit = function(nextScene) {};
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Actors&lt;/strong&gt; would be NPCs that can initiate dialogue and potentially reveal information or a piece of the puzzle if the player says the correct things. Actors could also be part of the scene that isn&amp;#8217;t an item but reacts when used with an item.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var NPC = Class(Actor, function(supr) {
    this.init = function(opts) {}

    this.onPush = function() {};
    this.onPull = function() {};
    this.onOpen = function() {};
    this.onClose = function() {};
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Items&lt;/strong&gt; are things inside scenes that progress the plot and can be used to solve smaller puzzles. These usually have the biggest impact on gameplay and contribution towards a resolution. Some callbacks for items would be using an item, combining an item with another item or combining an item with an actor.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var MyItem = Class(Item, function(supr) {
    this.init = function(opts) {};

    this.onUse = function() {};
    this.onCombineItem = function(otherItem) {};
    this.onCombineActor = function(otherActor) {};
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Dialogue&lt;/strong&gt; usually has a few options about what you want to say to an actor which will either trigger another line from an actor, conclude the conversation or progress the plot. You could make some lines of dialogue have the same effect or a line of dialogue could be key to solving a puzzle. Callbacks would be when the player selects a line of dialogue.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var TalkingDude = Class(Actor, function() {
    this.onDialogue = function(lineSpoken) {};
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Actions&lt;/strong&gt; are how the player interacts with items, scenes and actors. Callbacks would be placed on Actors and Items for various actions such as open, close, push, pull, use, etc etc.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var MyItem = Class(Item, function(supr) {
    this.init = function(opts) {};

    this.onPush = function() {};
    this.onPull = function() {};
    this.onOpen = function() {};
    this.onClose = function() {};
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I know this isn&amp;#8217;t anything concrete but it is my interpretation of building an adventure game with the intention of modular and ultimate reuse. I intend to do more tinkering to come up with some working demos and maybe even design a JSON format to build scenes and lines of dialogue.&lt;/p&gt;</description><link>http://louisstowasser.com/post/19049602694</link><guid>http://louisstowasser.com/post/19049602694</guid><pubDate>Sat, 10 Mar 2012 18:46:00 +1000</pubDate><dc:creator>craftyjs</dc:creator></item><item><title>Welcome!</title><description>&lt;p&gt;Hello all. I&amp;#8217;ve decided to beef up my personal brand recognition, rather than networking under the guise of &amp;#8220;that Crafty dude&amp;#8221;.&lt;/p&gt;

&lt;p&gt;It also allows me to post interesting things about the web but not necessarily related to Crafty.&lt;/p&gt;

&lt;p&gt;Still trying to figure out how this will all be formatted (such as code snippets) so bare with me while I learn how to blog.&lt;/p&gt;

&lt;p&gt;Bye!&lt;/p&gt;</description><link>http://louisstowasser.com/post/19047957081</link><guid>http://louisstowasser.com/post/19047957081</guid><pubDate>Sat, 10 Mar 2012 17:27:43 +1000</pubDate><dc:creator>craftyjs</dc:creator></item></channel></rss>
