<?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>mandarin</title>
	<atom:link href="http://mandarin.no/feed/" rel="self" type="application/rss+xml" />
	<link>http://mandarin.no</link>
	<description>I make games!</description>
	<lastBuildDate>Wed, 10 Apr 2013 09:41:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Change Unity&#8217;s default MonoBehaviour template</title>
		<link>http://mandarin.no/change-unitys-default-monobehaviour-template/</link>
		<comments>http://mandarin.no/change-unitys-default-monobehaviour-template/#comments</comments>
		<pubDate>Wed, 10 Apr 2013 09:41:50 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[tips]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[code template]]></category>
		<category><![CDATA[monobehaviour]]></category>
		<category><![CDATA[unity]]></category>

		<guid isPermaLink="false">http://mandarin.no/?p=349</guid>
		<description><![CDATA[If you&#8217;re like me and like your tab indents to use spaces rather than tabs, and you always remove the standard comments above Start and Update, then this little tips might be useful. Go to /Applications/Unity and Show Package Contents on the Unity.app. Navigate to Contents/Resources/ScriptTemplates. Here, you&#8217;ll find all the template Unity uses. Edit [...]]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;re like me and like your tab indents to use spaces rather than tabs, and you always remove the standard comments above Start and Update, then this little tips might be useful.</p>
<p>Go to /Applications/Unity and Show Package Contents on the Unity.app. Navigate to Contents/Resources/ScriptTemplates. Here, you&#8217;ll find all the template Unity uses. Edit as you wish!</p>
<p>Note: I&#8217;m pretty certain these files will be overwritten the next time you update Unity.</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/change-unitys-default-monobehaviour-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Better handling of behaviours in ImpactJS</title>
		<link>http://mandarin.no/better-handling-of-behaviours-in-impactjs/</link>
		<comments>http://mandarin.no/better-handling-of-behaviours-in-impactjs/#comments</comments>
		<pubDate>Mon, 04 Feb 2013 16:56:59 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[ImpactJS]]></category>
		<category><![CDATA[behaviour]]></category>
		<category><![CDATA[director]]></category>
		<category><![CDATA[entities]]></category>
		<category><![CDATA[impactjs]]></category>
		<category><![CDATA[levels]]></category>
		<category><![CDATA[sharing data]]></category>

		<guid isPermaLink="false">http://mandarin.no/?p=333</guid>
		<description><![CDATA[For the JIPPI project we made a game with a fairly standard setup with a menu that links to a couple of levels. We started off by adding functionality to the main class and then switching between update loops based on which level you&#8217;re at. This will quickly become difficult to maintain. Instead, we opted [...]]]></description>
				<content:encoded><![CDATA[<p>For the <a title="JIPPI" href="http://mandarin.no/game/jippi/">JIPPI</a> project we made a game with a fairly standard setup with a menu that links to a couple of levels. We started off by adding functionality to the main class and then switching between update loops based on which level you&#8217;re at. This will quickly become difficult to maintain.</p>
<p>Instead, we opted for a more Unity&#8217;ish approach (where you use GameObjects to add behaviour to the scene. And these GameObjects are placed in the scene. A bit like working with ActionsScript 1 and 2 -if anyone still remembers, where you put some AS-code in a MovieClip and put that in the scene). We created behaviour entities that we placed in the levels. These were never rendered, but provided an update loop that kept the level running, and the main file clean.</p>
<p>There are some benefits of using an approach like this:</p>
<ul>
<li><span style="line-height: 13px;">game.loadLevel() will kill all your entities when you switch levels. That way you don&#8217;t have to create any dealloc functions to clean up any mess.</span></li>
<li>It&#8217;s easy to see when editing the level which behaviour this level has. And it&#8217;s equally easy to change the level&#8217;s behaviour.</li>
<li>The code is separated from the main class and easily maintainable.</li>
</ul>
<p>So, how do you setup a system like this? Let me show you.</p>
<p>We need two base classes that all behaviour and entity classes extend from.</p>
<h2>BaseBehaviour</h2>
<pre><code data-language="javascript">ig.module(
    'game.base.base-behaviour'
)
.requires(
    'impact.entity'
)
.defines(function(){
    ig.EntityBaseBehaviour = ig.Entity.extend({
        _wmScalable: false,
        _wmDrawBox: true,
        _wmBoxColor: 'rgba(196, 255, 0, 0.7)',

        size: {x:64, y:64},

        game: null,
        game_data: null,

        _ready: function(args) {
            if (args !== undefined) {
                if (args.game) this.game = args.game;
            }
            if (this.game.director.data !== null) {
                this.game_data = ig.copy(this.game.director.data);
                this.game.director.data = null;
            }
            this.ready();
        }
    });
});</code></pre>
<h2>BaseEntity</h2>
<pre><code data-language="javascript">ig.module(
    'game.base.base-entity'
)
.requires(
    'impact.entity'
)
.defines(function(){
    ig.EntityBaseEntity = ig.Entity.extend({

        behaviour: null,
        game: null,

        _ready: function(args) {
            if (args !== undefined) {
                if (args.behaviour) this.behaviour = args.behaviour;
                if (args.game) this.game = args.game;
            }
            this.ready();
        }
    });
});</code></pre>
<h2>Main</h2>
<pre><code data-language="javascript">loadLevel: function( data ) {
    this.screen = {x: 0, y: 0};
    this.entities = [];
    this.namedEntities = {};
    for( var i = 0; i &lt; data.entities.length; i++ ) {
        var ent = data.entities[i],
        this.spawnEntity( ent.type, ent.x, ent.y, ent.settings );
    }
    this.sortEntities();

    // Call post-init ready function on all entities
    var behaviour = this.getEntitiesByType(ig.EntityBaseBehaviour)[0],
        entits = this.getEntitiesByType(ig.EntityBaseEntity);

    if (typeof behaviour !== 'undefined' &amp;&amp; behaviour !== null) {
        // Pass reference to game class to behaviour
        behaviour._ready({ game: this });
    }
    else {
        console.error('Your level is missing the main behaviour');
    }

    // Pass reference to behaviour class to all entities
    for( var i = 0; i &lt; entits.length; i++ ) {
        entits[i]._ready({
            behaviour: behaviour,
            game: this
        });
    }
}</code></pre>
<h2>Director</h2>
<pre><code data-language="javascript">goTo: function(nick, options) {
    if (typeof options !== 'undefined')
        this.data = options;
    this.jumpTo(nick);
}</code></pre>
<p>What happens here is the following:</p>
<p>Switching between levels is done using a Director class. With this class you can register levels with a keyword. That way you don&#8217;t have to load a level by making a direct reference to the level class. The Director plugin&#8217;s goTo function accepts two parameters: <strong>nick name</strong> for the level to load, and an optional <strong>options</strong> object for any data that you might want to pass from a level to another.</p>
<p>When you call director.goTo(), the Director will save any optional data in its own data property, and then trigger loadLevel (this is done in jumpTo(), where the Director checks to see if it has a level with the desired nick name).</p>
<p>LoadLevel will traverse all entities in the levels file and look for behaviours and entities. Once a behaviour has been found, all entities that extend from BaseEntity will get a reference to the behaviour so that they can access it via <strong>this.behaviour</strong>. Both the entities and the behaviour will get a reference to the main game class so that they don&#8217;t have to use ig.game (which doesn&#8217;t work well with Weltmeister).</p>
<p>Once the passing of references to the behaviour and the game class has been done, ready() is called on all entities. That&#8217;s where an entity can access the data object via <strong>this.behaviour.game_data</strong>.</p>
<h2>Caveats</h2>
<p>This implementation supports only one behaviour per level. I have some ideas for how to implement support for multiple behaviours per level. That would most definitely come in handy.</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/better-handling-of-behaviours-in-impactjs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Starting/restarting an ImpactJS game without reloading the page</title>
		<link>http://mandarin.no/startingrestarting-an-impactjs-game-without-reloading-the-page/</link>
		<comments>http://mandarin.no/startingrestarting-an-impactjs-game-without-reloading-the-page/#comments</comments>
		<pubDate>Mon, 04 Feb 2013 16:04:36 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[ImpactJS]]></category>
		<category><![CDATA[event handler]]></category>
		<category><![CDATA[game loop]]></category>
		<category><![CDATA[impactjs]]></category>
		<category><![CDATA[restart]]></category>
		<category><![CDATA[start]]></category>

		<guid isPermaLink="false">http://mandarin.no/?p=301</guid>
		<description><![CDATA[For the JIPPI project we needed to build the game so that it could be restarted without reloading the page. Killing event listeners and stopping timers would have to be done, in addition to cleaning up any modules that might be loaded on the next create() so that ImpactJS wouldn&#8217;t trigger the &#8220;Module has already [...]]]></description>
				<content:encoded><![CDATA[<p>For the <a title="JIPPI" href="http://mandarin.no/game/jippi/">JIPPI</a> project we needed to build the game so that it could be restarted without reloading the page. Killing event listeners and stopping timers would have to be done, in addition to cleaning up any modules that might be loaded on the next create() so that ImpactJS wouldn&#8217;t trigger the &#8220;Module has already been defined&#8221; error message.</p>
<h2>Create()</h2>
<p>Most of the create function has been explained in the blog post <a title="Dynamic loading of assets, entities and levels in ImpactJS" href="http://mandarin.no/dynamic-loading-of-assets-entities-and-levels-in-impactjs/">Dynamic loading of assets, entities and levels in ImpactJS</a>. Aside from what&#8217;s explained in that article, you could do other kinds of pre-initialization stuff here. Just make sure you end your create function with ig.main();</p>
<h2>Destroy()</h2>
<h3>Input handlers</h3>
<p>We made changes to impact/input.js so that the event handlers for input were not defined by anonymous functions. So instead of doing this:</p>
<pre><code data-language="javascript">ig.system.canvas.addEventListener('mousedown', this.keydown.bind(this), false );</code></pre>
<p>We did this:</p>
<pre><code data-language="javascript">ig.keydownBound = this.keydown.bind(this);
ig.system.canvas.addEventListener('mousedown', ig.keydownBound, false );</code></pre>
<p>That way we could later remove the event handlers by doing:</p>
<pre><code data-language="javascript">ig.system.canvas.removeEventListener('mousedown', ig.keydownBound, false );
window.removeEventListener('keydown', ig.keydownBound, false );</code></pre>
<h3>Game loop and other event handlers</h3>
<p>The main game loop can be stopped by calling:</p>
<pre><code data-language="javascript">ig.system.stopRunLoop();</code></pre>
<p>There are also two event handlers added for module loading that needs to be removed:</p>
<pre><code data-language="javascript">document.removeEventListener( 'DOMContentLoaded', ig._DOMReady, false );
window.removeEventListener( 'load', ig._DOMReady, false );</code></pre>
<p>In order to make the next create() execute as expected, reset ig._current by doing:</p>
<pre><code data-language="javascript">ig._current = null;</code></pre>
<h3>Removing modules and levels</h3>
<p>Next up, we removed all modules and levels that might be loaded the next time we run create(). We do this by traversing ig.modules, like this:</p>
<pre><code data-language="javascript">var deleteables = [];

for (var m in ig.modules) {

    var d = false;

    if (m.substr(0,11) === 'game.levels') {
        d = true;
    }

    if (m.substr(0,13) === 'game.entities') {
        var mod = m.split('.');
        if (mod.length &gt;= 4) d = true;
    }

    if (d) deleteables.push(m);
}

for (var i=0, l=deleteables.length; i&lt;l; i++) {
    delete ig.modules[deleteables[i]];
}</code></pre>
<p>As you can see here, I delete modules that has a name which begins with game.levels. But for entities, I make sure to only remove those who belong to a subfolder since I don&#8217;t want to remove the shared entities that are used in all levels, and resides in the root entities folder.</p>
<p>Next step is to clean up the ig.resources array.</p>
<pre><code data-language="javascript">deleteables = [];

if (ig.resources.length &gt; 0) {
    for (var res in ig.resources) {

        var r = ig.resources[res].path,
        d = false;

        if (typeof r !== 'undefined') {
            if (r.substr(0,13) === 'media/images/') {
                r = r.substr(13);
            }

            if (r.substr(0,6) === 'char1_' || 
                r.substr(0,6) === 'char2_' || ... ) {
                d = true;
            }

            if (d) deleteables.push(res);
        }
    }
}

for (var i=0, l=deleteables.length; i&lt;l; i++) {
    var key = deleteables[i],
    r = ig.resources[key];

    if (!r.hasOwnProperty(key))
        return;

    if (isNaN(parseInt(key)) || !(r instanceof Array))
        delete r[key];
    else
        r.splice(key, 1);
}</code></pre>
<p>This one is a bit more elaborate. I make sure to remove resources that only belongs to the game&#8217;s characters. That way I don&#8217;t delete the shared assets.</p>
<p>Finally I delete the levels by doing this for each level that might be loaded with the next create():</p>
<pre><code data-language="javascript">delete ig.LevelA;
ig.LevelA = null;</code></pre>
<p>It took me quite a few hours to figure out this one, but it turned out to be quite simple. I just had to read and understand almost every line of code in the Impact engine to get this working. I hope this will be useful for you. Feel free to ask if anything is unclear.</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/startingrestarting-an-impactjs-game-without-reloading-the-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic loading of assets, entities and levels in ImpactJS</title>
		<link>http://mandarin.no/dynamic-loading-of-assets-entities-and-levels-in-impactjs/</link>
		<comments>http://mandarin.no/dynamic-loading-of-assets-entities-and-levels-in-impactjs/#comments</comments>
		<pubDate>Mon, 04 Feb 2013 15:25:07 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[ImpactJS]]></category>
		<category><![CDATA[defines]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[impactjs]]></category>
		<category><![CDATA[loadqueue]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[preloading]]></category>
		<category><![CDATA[requires]]></category>
		<category><![CDATA[resources]]></category>

		<guid isPermaLink="false">http://mandarin.no/?p=303</guid>
		<description><![CDATA[As a part of the JIPPI project, we added a create/destroy function to ImpactJS. With the create function, you could pass a string to let the game know which jigsaw puzzle to load. We didn&#8217;t want the game to preload everything since the game consisted of 9 games and not all would be played during [...]]]></description>
				<content:encoded><![CDATA[<p>As a part of the <a title="JIPPI" href="http://mandarin.no/game/jippi/">JIPPI</a> project, we added a create/destroy function to ImpactJS. With the create function, you could pass a string to let the game know which jigsaw puzzle to load. We didn&#8217;t want the game to preload everything since the game consisted of 9 games and not all would be played during one session.</p>
<p>Due to the way ImpactJS is structured, it&#8217;s actually quite easy to add dynamic preloading. Have you noticed the three functions module(), requires() and defines() at the top of each class? Did you know that when your files have been downloaded, all of these functions are executed?</p>
<p>These functions are executed so that ImpactJS gets a full list of all modules and the preloader gets a list of all assets to download. If you want to dynamically add a module, simply load it with XHR so that the browser can interpret it once it&#8217;s downloaded. When the download has completed, call ig.main() to start the preloader and the game. Simple!</p>
<p>Let me show you how I did it.</p>
<p>In main.js I have a function called ig.create(params). One of the params is called &#8216;character&#8217;. I load a baked js-file with all levels and entities for that character by doing this:</p>
<pre><code data-language="javascript">var char_to_load = 'characters/'+character+'.js';

var script = ig.$new('script');
script.type = 'text/javascript';
script.src = char_to_load;

script.onload = function() {};

script.onerror = function() {
    throw('Failed to load character ' + path + ' ');
};

ig.$('head')[0].appendChild(script);</code></pre>
<p>This takes the character parameter, makes a full path to the baked file, creates a script tag and loads the file. You&#8217;ll se that I haven&#8217;t added any onload handler. Instead I use a timer to check for the length of ig._loadQueue.</p>
<p>When the file has been downloaded, the browser will interpret the file and execute any code that&#8217;s supposed to be executed. By default, ImpactJS will register the module, add any assets to ig.resources and by calling the requires() function, ImpactJS traverses all the classes you have in your baked file. So, to make sure ImpactJS has traversed all files before I call ig.main(), I set up a timer that checks the length of the loadQueue.</p>
<pre><code data-language="javascript">ig.loadReadyInterval = setInterval(ig.checkReady, 250);

ig.checkReady = function(){
    if (ig._loadQueue.length === 0) {
        clearInterval(ig.loadReadyInterval);
        ig.main( ... );
    }
}</code></pre>
<p>Once the loadQueue has a length of zero, I call ig.main().</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/dynamic-loading-of-assets-entities-and-levels-in-impactjs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automating entity generation with PHP and ImpactJS</title>
		<link>http://mandarin.no/automating-entity-generation-with-php-and-impactjs/</link>
		<comments>http://mandarin.no/automating-entity-generation-with-php-and-impactjs/#comments</comments>
		<pubDate>Mon, 04 Feb 2013 14:44:13 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[ImpactJS]]></category>
		<category><![CDATA[entities]]></category>
		<category><![CDATA[generating]]></category>
		<category><![CDATA[impactjs]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://mandarin.no/?p=298</guid>
		<description><![CDATA[While working on the JIPPI game we needed tools for easing the development. One of the tools was a PHP script for automating generation of entities. We would get the sprite sheets from Making Waves, and then it was our job to make the entities come alive. To make this process as flexible as possible, [...]]]></description>
				<content:encoded><![CDATA[<p>While working on the <a title="JIPPI" href="http://mandarin.no/game/jippi/">JIPPI</a> game we needed tools for easing the development. One of the tools was a PHP script for automating generation of entities.</p>
<p>We would get the sprite sheets from <a href="http://makingwaves.no">Making Waves</a>, and then it was our job to make the entities come alive. To make this process as flexible as possible, we needed a workflow that would allow the client to update the sprite sheets whenever needed. We could therefore not add any functionality to the generated entities. Otherwise, they would be overwritten during the next update. Instead, we turned the hierarchy upside-down. Generated entities would extended a parent entity that gave them a particular set of behaviours.</p>
<p>The PHP script got instructions for how to generate entities by reading the file names of the sprite sheets. Let&#8217;s consider the following file name:</p>
<pre>thomas_player_character_2_4_idle.$jump.$jump.$jump.$wait.$wait.sit.crouch.png</pre>
<p style="padding-left: 30px;"><strong>thomas</strong> &#8211; Tells the script to save the entity in game/entities/thomas. Create the folder if it doesn&#8217;t exist.</p>
<p style="padding-left: 30px;"><strong>player</strong> &#8211; Name the file player.js.</p>
<p style="padding-left: 30px;"><strong>character</strong> &#8211; Load the entity definition template called character.</p>
<p style="padding-left: 30px;"><strong>2</strong>_<strong>4</strong> &#8211; Split the sprite sheet in 2 columns and 4 rows.</p>
<p style="padding-left: 30px;"><strong>idle</strong>.<strong>$jump</strong>.<strong>$jump</strong>.<strong>$jump</strong>.<strong>$wait</strong>.<strong>$wait</strong>.<strong>sit</strong>.<strong>crouch</strong> &#8211; Define a set of animations, where the first animation is called &#8216;idle&#8217; and uses the first index of the sprite sheet. Next add an animation called &#8216;jump&#8217;, consisting of sprite index 1, 2 and 3. Wait animation uses index 4 and 5, and lastly add two animations with one frame each, called sit and crouch.</p>
<p>The script was split up into several files where the most important ones were the template files. They had each a parser with a set of rules specific for that template, and a function that would merge the data from the file with a template file. Some templates could generate multiple entities per file. The other files would do things like calculating the size and offset of each tile in a sprite sheet.</p>
<p>The PHP script followed the following routine:</p>
<ol>
<li><span style="line-height: 13px;">Scan media folder for valid image files.</span></li>
<li>Run the file name with the parser for each entity template to see if the file is supposed to be made into an entity. One can make the script ignore files by naming the file something that doesn&#8217;t match any of the patterns in the parsers.</li>
<li>When a template has been found, test it agains the class that splits the image into the desired number of rows and cols. If the image has the wrong size, abort the script.</li>
<li>Calculate each tile&#8217;s size and offset by looping over each transparent pixel from top -&gt; bottom, right -&gt; left, bottom -&gt; top and left -&gt; right until we either reach the other side of the image (all the pixels are transparent) or a pixel with a transparency level above a defined threshold.</li>
<li>If any animation has been specified in the file name, set up all the animations.</li>
<li>Merge all of this data with a template.</li>
<li>Write the file to the correct folder, overwriting any old entity.</li>
</ol>
<p>With this routine, we generated about 50 entities in only a couple of seconds. If we were to manually create and maintain these entities we would spend hours each update, and it would be prone to errors.</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/automating-entity-generation-with-php-and-impactjs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fast switching between your game and Weltmeister (ImpactJS)</title>
		<link>http://mandarin.no/fast-switching-between-your-game-and-weltmeister-impactjs/</link>
		<comments>http://mandarin.no/fast-switching-between-your-game-and-weltmeister-impactjs/#comments</comments>
		<pubDate>Mon, 04 Feb 2013 14:08:58 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[ImpactJS]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[entities]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[impactjs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[level]]></category>
		<category><![CDATA[loading]]></category>
		<category><![CDATA[subfolder]]></category>
		<category><![CDATA[switching]]></category>
		<category><![CDATA[weltmeister]]></category>

		<guid isPermaLink="false">http://mandarin.no/?p=306</guid>
		<description><![CDATA[For JIPPI I created a couple of tools to ease the development, one of them being a handy drop down menu which allowed me to open Weltmeister (from now on just W) with the config file set to a particular sub folder of the levels and entities folders. This is something I intend to make [...]]]></description>
				<content:encoded><![CDATA[<p>For <a title="JIPPI" href="http://mandarin.no/game/jippi/">JIPPI</a> I created a couple of tools to ease the development, one of them being a handy drop down menu which allowed me to open Weltmeister (from now on just W) with the config file set to a particular sub folder of the levels and entities folders. This is something I intend to make into a ImpactJS plugin, but the state of the code is not quite ready. So it&#8217;ll have to wait.</p>
<p>In W&#8217;s config file, you&#8217;ll find a couple of lines that define which folders W will look for entities and levels in. You can change these if you&#8217;d like to edit levels that are in a different folder than the default lib/game/levels. The config looks like this:</p>
<pre><code data-language="javascript">wm.config = {
    project: {
        'entityFiles': [
            'lib/game/entities/*.js',
            'lib/game/entities/subfolder/*.js'
        ],
        'levelPath': 'lib/game/levels/subfolder/',
        ...</code></pre>
<p>As you can see here, I&#8217;ve added two folders to the entityFolder settings. This makes W look for entities in both. In my case, this was exactly what I wanted, because at the root of the entities folder, I had all the common entities, and under each sub folder were all the level specific entities.</p>
<p>In order to make W open with the correct settings, I used a PHP script that edited the config file before routing the user to W. I&#8217;m no expert in regex, so I simply copied the default config file to a separate folder, added a couple of strings for where I wanted to insert the name of the subfolder, and then let PHP do a simple search and replace before overwriting W&#8217;s config file.</p>
<p>My template file looked like this:</p>
<pre><code data-language="javascript">ig.module(
    'weltmeister.config'
)
.defines(function(){ "use strict";
wm.config = {
    project: {
        'entityFiles': *[ENTITIES_DIR]*,
        'levelPath': *[LEVELS_DIR]*,</code></pre>
<p>Here you can see the strings I added as placeholders.</p>
<p>The drop down menu was created by a PHP script that simply listed all the subfolders of the levels folder. When I clicked on one of the options in the drop down menu, the name of the subfolder was posted to a PHP script that created the new config file, and used PHP&#8217;s header() function to route the user to W.</p>
<p>To get back to the game, I added a play button to W&#8217;s toolbar that would route me to the index file.</p>
<p>I have no idea how much or little time this has saved me from either typing the full address of W or switching between browser windows and manually editing the config file, but it sure feels like a lot of time has been saved.</p>
<h3>Caveats</h3>
<p>When open W from the drop down menu, W will still remember the last opened level and open that. But when you save the level, it will be saved to the subfolder you clicked on the drop down menu. Very confusing! For now, you&#8217;d have to remember to load the level you want to edit once you&#8217;ve opened W.</p>
<h3>Future features</h3>
<p>I&#8217;d like the drop down to be able to list levels in each subfolder so that I can jump directly to a level without having to manually load it from W. I would also like the play button in W to not only take me to the game but make the game load the level I&#8217;m editing. That way you can switch between the game and the editor with two clicks.</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/fast-switching-between-your-game-and-weltmeister-impactjs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Git for versioning with Unity</title>
		<link>http://mandarin.no/using-git-for-versioning-with-unity/</link>
		<comments>http://mandarin.no/using-git-for-versioning-with-unity/#comments</comments>
		<pubDate>Fri, 10 Aug 2012 13:37:54 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[tips]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[binary files]]></category>
		<category><![CDATA[conflict]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[unity]]></category>
		<category><![CDATA[versioning]]></category>

		<guid isPermaLink="false">http://mandarin.no/?p=176</guid>
		<description><![CDATA[In the document Using External Version Control Systems with Unity, Unity doesn&#8217;t mention Git as an alternative. I prefer using Git for versioning and just did a test using github.com. Setting up the respository was just as easy as described in the documentation. Update April 2nd 2013: Since committing to a git repo is a bit [...]]]></description>
				<content:encoded><![CDATA[<p>In the document <a href="http://docs.unity3d.com/Documentation/Manual/ExternalVersionControlSystemSupport.html">Using External Version Control Systems with Unity</a>, Unity doesn&#8217;t mention Git as an alternative. I prefer using Git for versioning and just did a test using github.com. Setting up the respository was just as easy as described in the documentation.</p>
<p>Update April 2nd 2013:</p>
<p>Since committing to a git repo is a bit different than committing to svn, I have listed the steps here:</p>
<ol>
<li>Create a code repo on github.com (or your own Git server).</li>
<li><span style="line-height: 13px;">Create a new project in Unity. Make sure to save it where you want to have your local copy of the code repo.</span></li>
<li>In Unity, go to Edit &gt; Project Settings &gt; Editor and enable Meta files for Version Control, and Force Text for Asset Serialization.</li>
<li>Quit Unity.</li>
<li>Delete the Library and Temp folder from the project folder.</li>
<li>And now, it&#8217;s time to make the first commit. Open terminal and follow the next 6 steps.</li>
<li>cd to/your/project/folder</li>
<li>git init</li>
<li>git add *</li>
<li>git commit -m &#8220;First commit&#8221;</li>
<li>git remote add origin git@github.com:username/project.git</li>
<li>git push -u origin master</li>
<li>Open your Unity project while holding down the Option or the left Alt key. This will force Unity to recreate the Library folder.</li>
<li>You can either contine to use git from the command line, or use a Git client like Tower or any other. In Tower, I would choose to Add Local Repository and point it to the folder where I created the Unity project. You don&#8217;t have to clone the repo because you already set up the repo when doing your first commit.</li>
<li>Make Git ignore the Library and Temp folder so that they won&#8217;t be pushed to the server. Add them to the .gitignore file and push the ignore to the server.</li>
</ol>
<p><del>I still have the problem of resolving conflicts in the scene files, as they are binary. I guess I could build my games so that the scenes reads settings files and builds up the levels programmatically, but that would in many cases defeat the purpose of the Unity Editor.</del> <strong>NOTE:</strong> There are others who have had the same thought of setting up the project with nothing in the scene files. Read the thread <a href="http://answers.unity3d.com/questions/8740/version-control-workflow.html">Version control workflow</a> at Unity Answers for a couple of hints on how to do it.</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/using-git-for-versioning-with-unity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blocking domains from Google search results</title>
		<link>http://mandarin.no/blocking-domains-from-google-search-results/</link>
		<comments>http://mandarin.no/blocking-domains-from-google-search-results/#comments</comments>
		<pubDate>Sun, 01 Jul 2012 22:56:00 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[tips]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[domains]]></category>
		<category><![CDATA[experts exchange]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[search results]]></category>

		<guid isPermaLink="false">http://mandarin.no/?p=146</guid>
		<description><![CDATA[Oh boy oh boy oh boy! I have just blocked all Google search results from experts-exchange.com! Make sure you are signed in to Google. Search for something, click on one of the websites in the results (I don&#8217;t know if you even have to wait for the page load), hit the back button and you [...]]]></description>
				<content:encoded><![CDATA[<p>Oh boy oh boy oh boy! I have just blocked all Google search results from experts-exchange.com! <img src='http://mandarin.no/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
<p>Make sure you are signed in to Google. Search for something, click on one of the websites in the results (I don&#8217;t know if you even have to wait for the page load), hit the back button and you will see a new line under the website link you just clicked. It will say something like &#8220;Block abcdef.com from &#8230;?&#8221;. Click it and you&#8217;ll never see hits from that domain again.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/blocking-domains-from-google-search-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Watch for changing properties in Flex</title>
		<link>http://mandarin.no/watch-for-changing-properties-in-flex/</link>
		<comments>http://mandarin.no/watch-for-changing-properties-in-flex/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 19:36:18 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[bindable]]></category>
		<category><![CDATA[changing variables]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://mandarin.no/?p=134</guid>
		<description><![CDATA[In AS3 there is a handy utility class called ChangeWatcher, which lives inside the mx.binding.utils package. It provides you with a handy way of watching other object’s properties. Here’s how it’s used: Object – the object which owns the property “property” – the property you want to watch handler – the function name of the [...]]]></description>
				<content:encoded><![CDATA[<p>In AS3 there is a handy utility class called ChangeWatcher, which lives inside the mx.binding.utils package. It provides you with a handy way of watching other object’s properties.</p>
<p>Here’s how it’s used:</p>
<pre class="brush: as3; title: ; notranslate">
ChangeWatcher.watch(object, &quot;property&quot;, handler);
</pre>
<p>Object – the object which owns the property<br />
“property” – the property you want to watch<br />
handler – the function name of the handler</p>
<p>Whenever the property of the object changes, the handler will respond. Quite handy, right?</p>
<p>Here’s an example for you:</p>
<p>Let’s say we have a class called WatchMe. Inside that class we have a public variable called ImBeingWatched. We’d like to trigger a function whenever this variable changes. To do this, we simply add one line of code:</p>
<pre class="brush: as3; title: ; notranslate">
package
{
    import mx.binding.utils.*;
    import flash.display.*;
    import flash.events.*;

    public class WatchMe extends MovieClip
    {
        [Bindable] public var ImBeingWatched:Boolean = true;

        public function WatchMe():void
        {
            ChangeWatcher.watch(this, &quot;ImBeingWatched&quot;, doSomething);
        }

        private function doSomething(e:Event):void
        {
            // do something ...
        }
    }
}
</pre>
<p>The property that ChangeWatcher is watching must be [Bindable] and Public for it to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/watch-for-changing-properties-in-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3: optimize an XMLSocket data handler</title>
		<link>http://mandarin.no/as3-optimize-an-xmlsocket-data-handler/</link>
		<comments>http://mandarin.no/as3-optimize-an-xmlsocket-data-handler/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 19:29:12 +0000</pubDate>
		<dc:creator>Thomas Viktil</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[optimizing code]]></category>
		<category><![CDATA[socket]]></category>
		<category><![CDATA[variable type]]></category>
		<category><![CDATA[xmlsocket]]></category>

		<guid isPermaLink="false">http://mandarin.no/?p=130</guid>
		<description><![CDATA[A while back ago I realized the importance of variable types and code optimization. I was working on an interactive installation using an Arduino and a Mac Mini. The Mac was communicating with the Arduino through an XMLSocket and was getting data probably about one hundred times per second. The first version of the datahandler [...]]]></description>
				<content:encoded><![CDATA[<p>A while back ago I realized the importance of variable types and code optimization. I was working on an interactive installation using an Arduino and a Mac Mini. The Mac was communicating with the Arduino through an XMLSocket and was getting data probably about one hundred times per second.</p>
<p>The first version of the datahandler used int&#8217;s as variable type for the values I recieved, and it would occasionally fail. After swithching to uint, things looked better.</p>
<p>I also had a set of 4 if-statements which I optimized by merging them into 2 if-statements.</p>
<p>To my surprise, this was the only thing I needed to do to make the datahandler parse the data fast enough.</p>
]]></content:encoded>
			<wfw:commentRss>http://mandarin.no/as3-optimize-an-xmlsocket-data-handler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
