<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>pixelpracht.net</title>
	<atom:link href="http://pixelpracht.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://pixelpracht.wordpress.com</link>
	<description>a programmers log</description>
	<lastBuildDate>Mon, 09 Jan 2012 15:18:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='pixelpracht.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>pixelpracht.net</title>
		<link>http://pixelpracht.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://pixelpracht.wordpress.com/osd.xml" title="pixelpracht.net" />
	<atom:link rel='hub' href='http://pixelpracht.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Blog moved to a new location!</title>
		<link>http://pixelpracht.wordpress.com/2011/06/18/blog-moved-to-a-new-location/</link>
		<comments>http://pixelpracht.wordpress.com/2011/06/18/blog-moved-to-a-new-location/#comments</comments>
		<pubDate>Sat, 18 Jun 2011 21:14:26 +0000</pubDate>
		<dc:creator>lithander</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pixelpracht.wordpress.com/?p=302</guid>
		<description><![CDATA[This Blog has moved: http://blog.pixelpracht.net/ I have a domain, webspace&#8230; there is no good reason beyond lazyness to not host my own blog but forward to wordpress.com. Finally I found the time and bravery to make the move! I hope everything still works. In the days to come I&#8217;ll explore the new customization options that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=302&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>This Blog has moved: <a href="http://blog.pixelpracht.net/?p=256">http://blog.pixelpracht.net/</a></h2>
<p>I have a domain, webspace&#8230; there is no good reason beyond lazyness to not host my own blog but forward to wordpress.com. Finally I found the time and bravery to make the move! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I hope everything still works. In the days to come I&#8217;ll explore the new customization options that I now have.</p>
<p>Thanks to Barry from <a href="http://gameschart.go2cloud.org/aff_c?offer_id=3&amp;aff_id=1020">GameCharts.com</a> for the nudge! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pixelpracht.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pixelpracht.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pixelpracht.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pixelpracht.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pixelpracht.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pixelpracht.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pixelpracht.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pixelpracht.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pixelpracht.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pixelpracht.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pixelpracht.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pixelpracht.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pixelpracht.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pixelpracht.wordpress.com/302/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=302&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pixelpracht.wordpress.com/2011/06/18/blog-moved-to-a-new-location/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b440466bf29e504f3b29eca70f3c98ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lithander</media:title>
		</media:content>
	</item>
		<item>
		<title>An asset pipeline in Flash. How we do it!</title>
		<link>http://pixelpracht.wordpress.com/2011/05/31/an-asset-pipeline-in-flash-how-we-do-it/</link>
		<comments>http://pixelpracht.wordpress.com/2011/05/31/an-asset-pipeline-in-flash-how-we-do-it/#comments</comments>
		<pubDate>Tue, 31 May 2011 17:05:26 +0000</pubDate>
		<dc:creator>lithander</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[embedding]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[resource]]></category>

		<guid isPermaLink="false">http://pixelpracht.wordpress.com/?p=256</guid>
		<description><![CDATA[Here&#8217;s a real-world example of how we handle the assets in our current flash game project at my company. It&#8217;s a rather big browser game that uses several megabytes of resources (XML meta-data, PNG &#38; JPEG Images, Sounds and Movieclips) that we have to deploy to the serves and load into the client when needed. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=256&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a real-world example of how we handle the assets in our current flash game project at my company. It&#8217;s a rather big browser game that uses several megabytes of resources (XML meta-data, PNG &amp; JPEG Images, Sounds and Movieclips) that we have to deploy to the serves and load into the client when needed. In such a scenario managing the dependancies between the code and the assets can be quite challenging and timeconsuming.</p>
<p><em>This post is a little advanced and you should be allready familiar with <a title="Resource Handling in Flash – Part One" href="http://pixelpracht.wordpress.com/2010/06/02/resource-handling-in-flash-part-one/">embedding and dynamically loading resources</a> in Flash.</em></p>
<h2><strong>The Challenge</strong></h2>
<p>The content creators create assets file by file and save them to a folder structure. Thanks to the magics of version control systems (SVN in our case) these ever growing amount of assets is synced between all collaborators. But someone has to make sure everything is available at runtime when the application needs it.</p>
<p>To embedd all resources using the [Embed] tag in the game&#8217;s source code would cause several problems: The size of the SWF would be huge as all assets that are potentially needed would have to be included. Each embedded resource has to be added when you build your project so compile times would explode. And as we&#8217;re using <strong>FlashBuilder</strong> we would have to write some lines of code for each embedd asset. But who&#8217;s going to maintain that? Gamedesigners and artists change, add and delete files to the repository but they don&#8217;t have the means (and inclination) to edit source code, so who&#8217;s keeping it synced?<br />
A contrary approach is to put all resource files on server and load them at run time. But different types of resources require different code to load, if you require many resources at once you have to open one connection for each resource (adding a lot of overhead) and you have to keep track of multiple loaders. Lastly many resource files are compressed efficiently when embedded into a SWF and it&#8217;s sad to miss out on that kind of optimization.</p>
<h2><strong>Our Solution</strong></h2>
<p>So we&#8217;ve decided to setup an <em>asset pipeline</em> that converts our assets into a format that is more optimized to the needs of the runtime environment. Such a system is a common thing in &#8220;real&#8221; game development but unusual for flash game development &#8211; maybe because traditionally Flash applications are authored in an IDE that has build in functionality for asset management.</p>
<p>Flash Builder doesn&#8217;t have anything like that but luckily it&#8217;s based on Eclipse, a software development environment with an extensible plugin system. One plugin (part of the &#8220;Eclipse Java Development Tools&#8221;) adds support for &#8220;Apache Ant&#8221; build scripts to Flash Builder. Ant is a tool for automating software build processes. What to build with it? SWF&#8217;s that contain only assets as embedded resources, get uploaded to the server alongside our game SWF and when resource are needed the appropriate resource-packs are loaded at runtime to make the embedded assets available to Flash.</p>
<p>But our Ant script does a lot more then just invoke a compiler to build some AS3 files. It also generates these files on the fly. So the manual work required to embedd all our assets into some dozens of resource packs reduces to clicking a button.</p>
<p><a href="http://pixelpracht.files.wordpress.com/2011/05/ant.png"><img class="aligncenter size-full wp-image-271" title="Ant integrated into Flash Builder" src="http://pixelpracht.files.wordpress.com/2011/05/ant.png?w=497" alt=""   /></a></p>
<h2><strong>The Details</strong></h2>
<p>So, what happens when we click?</p>
<ol>
<li>The Script will go to the root directory where our assets are stored and browse the subdirectories recursively. Finally when a directory is reached that contains files a resource pack is created.</li>
<li>To do that we first generate create a temporary AS3 source file. We just concatenate templates that contain a mix of actual source code and temporary portions of text, marked with @-symbols, that are replaced by the Ant script when it builds the source file.First we include the header&#8230;<pre class="brush: plain;">package @PACKAGE@
{
  import flash.display.Sprite;
  public class @PACK_NAME@ extends Sprite
  {
</pre>
<p>&#8230;then we add souce code for each asset in the folder based on it&#8217;s file extension&#8230;</p>
<p><pre class="brush: plain;">  [Embed(source=&quot;@ASSET_PATH@/@ASSET_NAME@.@ASSET_EXTENSION@&quot;, mimeType=&quot;image/png&quot;, compression=&quot;true&quot;, quality=&quot;@IMAGE_COMPRESSION@&quot;)]
  public static var @ASSET_NAME@:Class;
</pre></p>
<p>&#8230;finally we add a footer to close the class and package declartion.</p>
<p><pre class="brush: plain;">
  }
}</pre></li>
<li>Now we kindly ask the mxmlc compiler to compile the generated class into a SWF. The Flex SDK contains Ant tasks for that purpose so it&#8217;s pretty easy to invoke the mxmlc compiler from an Ant script.<br />
<pre class="brush: plain;">

  false
</pre></li>
<li>We also copy a manifest XML that describes game objects and links them with certain embedded Resources in the ResourcePacks we generated.<br />
A gameobject&#8217;s definition might look like this:There&#8217;s one special manifest that tells our application what other manifests to load and where to look for the resource packs. When a player starts the game this main manifest is loaded. Now that we know what resourcepacks and manifests exists on the server we can ask the ResourceManager to load them when neaded.<pre class="brush: plain;">

</pre></li>
<li>The manifests and the compiled SWFs are uploaded to the server.</li>
</ol>
<h2><strong>I can has Resources, please?</strong></h2>
<p>To get the assets when you need them you have to add code to your main application that will load the resourcepacks and manifests and extract the required resources. Our ResourceManager turned out rather complex but at its core it&#8217;s pretty straight-forward. This is how you&#8217;d load a XML-based manifest file.</p>
<p><pre class="brush: plain;">private function loadManifest (url:String):void
{
  var xmlLoader:URLLoader = new URLLoader();
  xmlLoader.addEventListener(Event.COMPLETE, onManifestLoaded);
  xmlLoader.load(new URLRequest(url));
}
private function onManifestLoaded(e:Event):void
{
  var xml:XML = new XML(e.target.data);
  app.processManifest(xml);
}</pre></p>
<p>And provided you know the URL to the resource pack an asset can be retrieved like this:</p>
<p><pre class="brush: plain;">private function loadAssets(url:String):void
{
var loader:Loader = new Loader();
loaders[url] = loader;
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaded);
resourcesToLoad[url] = loader;
loader.load(new URLRequest(url));
}</pre></p>
<p>When the loader completes it contains the class that we generated and compiled with our Ant script. We can look for the embedded resources if we know their name. To access a specific image asset you&#8217;d do this:</p>
<p><pre class="brush: plain;">var resourcePack:Class = loader.contentLoaderInfo.applicationDomain.getDefinition(resourcePackClassName) as Class;
var resource:Class = resourcePack[imageName];
var bitmapData:BitmapData = (new resource() as Bitmap).bitmapData;</pre></p>
<h2><strong>Final Words</strong></h2>
<p>I do realize that (unlike ours) many Flash applications need to be deployable as a single SWF that contains all the code and assets. Also, in smaller projects the effort of setting up system like ours might be bigger then just embedding the assets manually. But for us Ant has made deployment much easier and it allows the coders and artists to work on the same project mostly independ from each other.</p>
<p>I&#8217;d be curios to learn how other developers manage the assets in their projects! Feel free to comment! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pixelpracht.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pixelpracht.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pixelpracht.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pixelpracht.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pixelpracht.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pixelpracht.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pixelpracht.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pixelpracht.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pixelpracht.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pixelpracht.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pixelpracht.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pixelpracht.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pixelpracht.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pixelpracht.wordpress.com/256/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=256&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pixelpracht.wordpress.com/2011/05/31/an-asset-pipeline-in-flash-how-we-do-it/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b440466bf29e504f3b29eca70f3c98ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lithander</media:title>
		</media:content>

		<media:content url="http://pixelpracht.files.wordpress.com/2011/05/ant.png" medium="image">
			<media:title type="html">Ant integrated into Flash Builder</media:title>
		</media:content>
	</item>
		<item>
		<title>Matrix Magic</title>
		<link>http://pixelpracht.wordpress.com/2011/03/18/matrix-magic/</link>
		<comments>http://pixelpracht.wordpress.com/2011/03/18/matrix-magic/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 21:24:54 +0000</pubDate>
		<dc:creator>lithander</dc:creator>
				<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://pixelpracht.wordpress.com/?p=228</guid>
		<description><![CDATA[For a flash game project at work I needed to setup a flash.geom.Matrix instance to transform points from cartesian space into an isometric perspective. To get it working I had to answer three questions: 1. How do the properties a, b, c, d, tx and ty map to the coefficients of the matrix? 2. How [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=228&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For a flash game project at work I needed to setup a <em>flash.geom.Matrix</em> instance to transform points from cartesian space into an isometric perspective.</p>
<p>To get it working I had to answer three questions:</p>
<h2><em>1. How do the properties a, b, c, d, tx and ty map to the coefficients of the matrix?</em></h2>
<h2><a href="http://pixelpracht.files.wordpress.com/2011/03/matrix_props2.jpg"><img class="aligncenter size-full wp-image-230" title="matrix_coeff_mapping" src="http://pixelpracht.files.wordpress.com/2011/03/matrix_props2.jpg?w=497" alt="Mapping of coefficeints in the Flash Matrix class"   /></a></p>
<p><em>2. How to use the matrix to transform a Point?</em></h2>
<p>The Matrix class provides two methods to transform a point.</p>
<ul>
<li><strong>deltaTransformPoint</strong> transforms a point without applying the translation.</li>
</ul>
<p><pre class="brush: plain;">
x' = a * x + c * y;
y' = b * x + d * y;
</pre></p>
<ul>
<li><strong>transformPoint</strong> transforms a point including the translation.</li>
</ul>
<p><pre class="brush: plain;">
x' = a * x + c * y + tx;
y' = b * x + d * y + ty;
</pre></p>
<p>If you know the mapping of coefficients and a bit of computer graphics that&#8217;s the expected behavior. To be able to multiply a 2D vector with a 3D matrix you introduce an extra 1 as 3rd component. Then perform a matrix multiplication. That way the transformation is added to x and y after the rotation/sheering is done.</p>
<h2><em>3. How to setup the matrix to get the desired transformation?</em></h2>
<p>If none of the provided methods fits your need (like in my case) you can set the correct values for the coefficients directly. That&#8217;s easier then it sounds. Look at the basis vectors of your source coordinate system and imagine (or calculate) how they look like after the transformation. Assign coefficients <strong>a</strong> the <em>x</em> and <strong>b</strong> the <em>y</em> value of the transformed x-axis. Assign the x and y value of the transformed y-axis to <strong>c</strong> and <strong>d</strong>.<br />
If you need it you can set <strong>tx</strong> and <strong>ty</strong> to move the transformed points relative to the new origin.</p>
<h2><em>And why do I blog about math, now?</em></h2>
<p>Adobe managed to have a <strong>incorrect</strong> illustration of the layout of the coefficients in the <a href="http://http://help.adobe.com/de_DE/AS3LCR/Flash_10.0/flash/geom/Matrix.html">german doc</a> (<a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/geom/Matrix.html">english docs</a> happen to be correct!) and the inscrutable description of the <strong>transformPoint</strong> and <strong>deltaTransformPoint</strong> methods lacked the specifics I needed. Let&#8217;s hope this post and the power of google will help those, that seek the same kind of knowledge!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pixelpracht.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pixelpracht.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pixelpracht.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pixelpracht.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pixelpracht.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pixelpracht.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pixelpracht.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pixelpracht.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pixelpracht.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pixelpracht.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pixelpracht.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pixelpracht.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pixelpracht.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pixelpracht.wordpress.com/228/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=228&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pixelpracht.wordpress.com/2011/03/18/matrix-magic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b440466bf29e504f3b29eca70f3c98ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lithander</media:title>
		</media:content>

		<media:content url="http://pixelpracht.files.wordpress.com/2011/03/matrix_props2.jpg" medium="image">
			<media:title type="html">matrix_coeff_mapping</media:title>
		</media:content>
	</item>
		<item>
		<title>Simulating Fluids in Flash</title>
		<link>http://pixelpracht.wordpress.com/2011/01/07/simulating-fluids-in-flash/</link>
		<comments>http://pixelpracht.wordpress.com/2011/01/07/simulating-fluids-in-flash/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 00:52:45 +0000</pubDate>
		<dc:creator>lithander</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[FGL]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[fluid]]></category>
		<category><![CDATA[particle]]></category>
		<category><![CDATA[pixelbender]]></category>
		<category><![CDATA[rendering]]></category>

		<guid isPermaLink="false">http://pixelpracht.wordpress.com/?p=200</guid>
		<description><![CDATA[A thread in the FGL forums got me interested in the simulation of fluids. Of course this topic has seen quite extensive coverage in academic papers but getting it to work in the limitted environment of Flash provides some intersting challenges. Interesting enough for me to give it a try over my christmas break. I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=200&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A <a title="Discussion on simulating fluids" href="http://www.flashgamelicense.com/view_thread.php?thread_id=23077">thread</a> in the FGL forums got me interested in the simulation of fluids. Of course this topic has seen quite extensive coverage in academic papers but getting it to work in the limitted environment of Flash provides some intersting challenges. Interesting enough for me to give it a try over my christmas break.</p>
<p>I loosely followed a paper <a title="Particle-based Viscoelastic Fluid Simulation" href="http://www.iro.umontreal.ca/labs/infographie/papers/Clavet-2005-PVFS/pvfs.pdf">Particle-based Viscoelastic Fluid Simulation</a> to implement a sandbox application that simulates and renders a small blob of fluid and allows you to tinker with various parameters. Click the image below and give it a try!</p>
<p><a href="http://web.pixelpracht.net/atlantis.php"><img src="http://pixelpracht.files.wordpress.com/2011/01/fluid_screenshot.png?w=497" alt="" title="Sample: Fluid Simulation in Flash"   class="aligncenter size-full wp-image-217" /></a></p>
<p>The fluid is represented as a set of ~400 particles that interact with their neighbours and such seem to form a coherent entity.</p>
<p>For rendering I use an oldschool approach: Each particle is represented as a <a title="Resources on Metaballs" href="http://steve.hollasch.net/cgindex/misc/metaballs.html">metaball</a>. For a given pixel the force function of every metaball is evaluated, summed up and the final sum is compared with a threshold value to decide whether the pixel is inside or outside of the fluid.</p>
<p>To be able to do that in realtime I precalculate the values that a forcefunction yields for pixels within a relevant range of the particles center as a Bitmap.<br />
<a href="http://pixelpracht.files.wordpress.com/2011/01/fluid_illu01.png"><img src="http://pixelpracht.files.wordpress.com/2011/01/fluid_illu01.png?w=497" alt="Fluid Rendering - Illustration #1" title="fluid_illu01"   class="aligncenter size-full wp-image-208" /></a><br />
These tiny images (about 40&#215;40 pixels) are rendered at the position of the particle with additive blendmode.<br />
<a href="http://pixelpracht.files.wordpress.com/2011/01/fluid_illu02.png"><img src="http://pixelpracht.files.wordpress.com/2011/01/fluid_illu02.png?w=497" alt="Fluid Rendering - Illustration #2" title="fluid_illu02"   class="aligncenter size-full wp-image-209" /></a><br />
Now I can decide with a single lookup in the resulting Bitmap if a pixel belongs to the surface or not. That evaluation step is done by a pixel bender shader and instead of just working with a boolean state (inside or outside) I sample a gradient based on the accumulated force value.<br />
<a href="http://pixelpracht.files.wordpress.com/2011/01/fluid_illu03.png"><img src="http://pixelpracht.files.wordpress.com/2011/01/fluid_illu03.png?w=497" alt="Fluid Rendering - Illustration #3" title="fluid_illu03"   class="aligncenter size-full wp-image-210" /></a><br />
This approach allows me to achieve a variety of styles in the visual appearance of the simulated fluid by just using different gradients.</p>
<p>This technique would unfold it&#8217;s real potential if you could use hardware acceleration to accumulate the field functions because that&#8217;s a bottle neck in the current implementation. </p>
<p>Not sure if that stuff has any practical relevance, anyway. But the SWF is only 32kb big so people that are into demos (32k, 64k) could maybe make something fancy out of it. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Here&#8217;s the <a href="http://files.pixelpracht.net/Atlantis.rar">source code</a> released under the MIT license.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pixelpracht.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pixelpracht.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pixelpracht.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pixelpracht.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pixelpracht.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pixelpracht.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pixelpracht.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pixelpracht.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pixelpracht.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pixelpracht.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pixelpracht.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pixelpracht.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pixelpracht.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pixelpracht.wordpress.com/200/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=200&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pixelpracht.wordpress.com/2011/01/07/simulating-fluids-in-flash/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b440466bf29e504f3b29eca70f3c98ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lithander</media:title>
		</media:content>

		<media:content url="http://pixelpracht.files.wordpress.com/2011/01/fluid_screenshot.png" medium="image">
			<media:title type="html">Sample: Fluid Simulation in Flash</media:title>
		</media:content>

		<media:content url="http://pixelpracht.files.wordpress.com/2011/01/fluid_illu01.png" medium="image">
			<media:title type="html">fluid_illu01</media:title>
		</media:content>

		<media:content url="http://pixelpracht.files.wordpress.com/2011/01/fluid_illu02.png" medium="image">
			<media:title type="html">fluid_illu02</media:title>
		</media:content>

		<media:content url="http://pixelpracht.files.wordpress.com/2011/01/fluid_illu03.png" medium="image">
			<media:title type="html">fluid_illu03</media:title>
		</media:content>
	</item>
		<item>
		<title>Developing and Selling Rune Hunt</title>
		<link>http://pixelpracht.wordpress.com/2010/09/30/devlog-rune-hunt/</link>
		<comments>http://pixelpracht.wordpress.com/2010/09/30/devlog-rune-hunt/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 22:18:12 +0000</pubDate>
		<dc:creator>lithander</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Rune Hunt]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[sponsoring]]></category>

		<guid isPermaLink="false">http://pixelpracht.wordpress.com/?p=173</guid>
		<description><![CDATA[I started experimenting with real time shadows in Flash in fall 2009. At the same time I took notice of the Flixel framework and all the cool retro games that people made with it. Why not make a game of my own that combines pixel graphics with dynamic light and shadows? At the 14th December [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=173&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I started experimenting with real time shadows in Flash in fall 2009. At the same time I took notice of the <a href="http://flixel.org">Flixel</a> framework and all the cool retro games that people made with it. Why not make a game of my own that combines pixel graphics with dynamic light and shadows?</p>
<p>At the 14th December 2009 I created a <a href="http://flixel.org/forums/index.php?topic=577.0">thread</a> in the Flixel forums with a mission statement:</p>
<blockquote><p>The setup is classic: a hero in a dungeon full of treasure, traps and NPC of questionable attitude. The twist is that I&#8217;m limiting the player&#8217;s view to what his avatar is seeing. Top-down-ego-perspective so to speak. I hope it&#8217;s making exploring the dungeon more interesting and the enemies more scary if you don&#8217;t see all the stuff long before it becomes relevant/dangerous.</p></blockquote>
<p><a href="http://pixelpracht.files.wordpress.com/2010/09/development.png"><img class="aligncenter size-full wp-image-186" title="development" src="http://pixelpracht.files.wordpress.com/2010/09/development.png?w=497" alt=""   /></a></p>
<p><span id="more-173"></span>I used that thread to post ideas and prototypes and it became a major  source of feedback and motivation spread over 6 pages. I love the  Flixel community! <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Meanwhile some Flixel games had been sponsored and the developers where kind enough to share figures with me and introduce me to the concept. So there actually was a market for flash games created by hobbyists? That intrigued me &#8211; I was curious to learn how that business worked and what my own game would be worth to sponsors.</p>
<p>There was a website dedicated to bring sponsors and developers together: <a href="http://www.flashgamelicense.com/">Flash Game License</a>. To help my game stick out I commissioned a portrait of the protagonist that I wanted to turn into an eye-catching thumbnail fit to communicate the essence of the game in one glimpse. Finding an <a href="http://www.kokorobot.ca/">artist</a>, directing the process and finally receiving an awesome result was great. It felt like the best investment I&#8217;ve made in a long time! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  In the FGL Icon Hotness ranking my thumbnail was soon among the top 30 of over 2000 icons.</p>
<p style="text-align:center;"><img class="aligncenter" title="rh_thumbnail" src="http://files.pixelpracht.net/rh_thumb100x100.png" alt="" width="100" height="100" /></p>
<p>Now I had multiple reasons to finish the project. Many people knew about it and expected results, I had invested a little money and a lot of time (worth 4-6 weeks of fulltime work) and if all went well I would be able to reap some substantial reward (in cash and exposure) by finishing it.</p>
<p>In August I was more or less done and quite happy with the game. I watched friends playing through the whole thing. There were a few minor issues and when I had them fixed I felt it was time to find a sponsor.</p>
<h2><strong>Finding a Sponsor</strong></h2>
<p><strong><a href="http://pixelpracht.files.wordpress.com/2010/09/fgl_logo1.png"> </a></strong>I <strong>uploaded </strong>to <a href="http://www.flashgamelicense.com/">FGL</a> at <strong><span style="text-decoration:underline;">14th August 2010</span></strong>. Developers could immediately play and review the game but it had to be approved by the site admins before sponsors would be able to see it. I made a couple of minor fixes while impatiently waiting to get approved. Luckily after a couple of days I realized that reuploading the game was repeatedly putting me at the end of the approval-queue.</p>
<p style="text-align:center;"><strong><a href="http://pixelpracht.files.wordpress.com/2010/09/fgl_logo1.png"><img class="aligncenter" title="fgl_logo" src="http://pixelpracht.files.wordpress.com/2010/09/fgl_logo1.png?w=496&#038;h=82" alt="" width="496" height="82" /></a></strong></p>
<p>The game got <strong>approved </strong>at the <strong><span style="text-decoration:underline;">19th August</span></strong> with a developer rating of 8 out of 10 points. Pretty cool. Now I was sitting there, pressing F5, waiting for bids.</p>
<p>I&#8217;ve heard that many developers didn&#8217;t rely on FGL alone but also emailed sponsors directly. I resolved to do that, too. Researched lists of sponsors. But in the end I wrote only 3 mails &#8211; to the portals that I personally used and liked. <a href="http://armorgames.com/">Armorgames</a>, <a href="http://www.kongregate.com/">Kongregate</a>, <a href="http://www.newgrounds.com/">Newgrounds</a>. Without having to lie I told them that I&#8217;d be proud to have Rune Hunt bear their logo. Armor Games replied to my mail and viewed the game but didn&#8217;t place a bid. Not yet.</p>
<p>Instead I received the <strong>first 5 bids</strong> from 4 different sponsors all on the <strong><span style="text-decoration:underline;">20th of August</span></strong>. The best bid offered was 2000$ for a primary license. A great start!</p>
<p>A day later I uploaded a new SWF including reviewed dialogue. (Thanks to Hectate and zyxstand from the Flixel forums!) It has also been the first version that included a <em>sitelock</em> and measures to make decompilation a little more difficult. I should have done that right from the beginning but the protection method offered by FGL didn&#8217;t work for me and at that point I didn&#8217;t realize how important proper protection is to sponsors: If the game leaks without their branding they are skrewed.</p>
<p>2 days later a new sponsor offered 3000$ for an exclusive license with no adds allowed. I marked the 2000$ primary as &#8220;Best Bid&#8221; and promptly received an increased bid. In the note I was told that his bid was now obviously better then any other. I didn&#8217;t get a reply on my questions regarding details of the offer, though. The reputation of the sponsor wasn&#8217;t good. I hoped for an alternative.</p>
<p>Meanwhile I had created and uploaded a trailer for the game. And so I wrote a PM to one of the other sponsors that had placed a bid, telling him about the trailer, the reviewed texts and all the other changes hoping for a new bid. I got a friendly reply the other day and it was the beginning of at least a dozen PMs we exchanged over the following weeks. The sponsor was worried about the 3 days without protection (this was when I realized my error) and he made an offer reflecting that: A primary license including a performance plan. So, now I had an alternative. And I really liked the sponsor. If the game did good I&#8217;d receive about 3000$ for a primary license. I had hoped for more money but then, what did I know?</p>
<p>At the <span style="text-decoration:underline;"><strong>13th of September</strong></span> I enabled<strong> Last Call</strong> which basically means<em> &#8220;I&#8217;m going to decide on a bid soon!&#8221;</em>. The 3 days went by with no new bids. I was a little disappointed and couldn&#8217;t really decide which bid to chose. And I totally didn&#8217;t expect what happened next. After Last Call had ended I got 2 new bids from sponsors that hadn&#8217;t yet taken part in the bidding. And a message from a 3rd one who asked me to wait so he could conferr with his partner before maybe placing a bid, too. The bids where clear improvements to what was offered previously. One of them was from Armor Games.</p>
<p>The sponsor offering the performance deal made a new bid: In addition to a 2000$ I would get up to 6000$ bonus based on the number of plays (all sources combined) within two months.  With 3 million plays that would be 8k + CPMstar + sitelocks.</p>
<p>Of course I had no idea how good my game would do and betting on the amount of plays I&#8217;d get really troubled me but the bid was best. I told Daniel from Armor Games as much. To my horror they made a new bid, with a performance plan! Complicated because only plays on the sponsor&#8217;s portal counted but the eCPM were rather huge. I had no means to compare the bids, I was confused and that&#8217;s exactly what I told both of them.</p>
<p>Both made offers stripped of any performance plan. I asked for simple deals and that&#8217;s what I got: exclusive license offers. This is where a little bid war started. I was amazed &#8211; when Last Call had run out I allready expected to get less then 4k$ total (adds &amp; sitelocks included) now I was offered more then twice that amount as upfront cash.</p>
<p>In the end the other sponsor who&#8217;d been worried of my game leaking told me that he could not increase his bid any higher. He gave two very valid reasons and for both of them I was responsible.</p>
<ol>
<li>he was concerned because he had found my game being unprotected for the first couple of days and that&#8217;s clearly a stupid mistake from my part.</li>
<li>he didn&#8217;t expect to be able to outbid Armorgames in the end anyway. Another stupid mistake from my part. I shouldn&#8217;t have told him who the other sponsor was but we had exchanged so many upfront &amp; friendly mails that I just forgot that some information are better not shared.</li>
</ol>
<p>Two serious errors on my part and there has been a 3rd: I didn&#8217;t give the 3rd sponsor who had placed a recent bid enough time to react. I was under the impression that I was supposed to decide fast because of the Last Call period being over. So I was telling them about my plans to accept a bid now and that theirs wasn&#8217;t quite on parr with the top bids. I waited 24 hours, saw that they had logged in but didn&#8217;t reply to my PM and accepted Armor Game&#8217;s bid. Later I learned that they were still debating to increase their previous bid by another 2000$ when I terminated the bidding process.</p>
<p>But despite these things I&#8217;m happy: I received more money then I had hoped for. Working with Daniel proved to be a pleasure. 5 days later we brought the game online. He required a couple of changes that I didn&#8217;t expect (like adding a walkthrough) but in the end I was very happy with how the branding integrated with the game. I received the payment only minutes after the game has gone online. And because he wanted to use paypal and they take a huge fee from the seller he added another 250$ to compensate.</p>
<p>If you plan on selling a flash game through FGL I hope you can learn from how things went for me. I tried to keep exact numbers and names private where possible.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pixelpracht.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pixelpracht.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pixelpracht.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pixelpracht.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pixelpracht.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pixelpracht.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pixelpracht.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pixelpracht.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pixelpracht.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pixelpracht.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pixelpracht.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pixelpracht.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pixelpracht.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pixelpracht.wordpress.com/173/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=173&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pixelpracht.wordpress.com/2010/09/30/devlog-rune-hunt/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b440466bf29e504f3b29eca70f3c98ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lithander</media:title>
		</media:content>

		<media:content url="http://pixelpracht.files.wordpress.com/2010/09/development.png" medium="image">
			<media:title type="html">development</media:title>
		</media:content>

		<media:content url="http://files.pixelpracht.net/rh_thumb100x100.png" medium="image">
			<media:title type="html">rh_thumbnail</media:title>
		</media:content>

		<media:content url="http://pixelpracht.files.wordpress.com/2010/09/fgl_logo1.png" medium="image">
			<media:title type="html">fgl_logo</media:title>
		</media:content>
	</item>
		<item>
		<title>Rune Hunt Released</title>
		<link>http://pixelpracht.wordpress.com/2010/09/24/rune-hunt-released/</link>
		<comments>http://pixelpracht.wordpress.com/2010/09/24/rune-hunt-released/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 22:37:04 +0000</pubDate>
		<dc:creator>lithander</dc:creator>
				<category><![CDATA[Rune Hunt]]></category>
		<category><![CDATA[FGL]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[sponsoring]]></category>

		<guid isPermaLink="false">http://pixelpracht.wordpress.com/?p=153</guid>
		<description><![CDATA[Hungry eyes watch from the shadows. The flickering light of a butterfly is all that keeps them at bay. Run for your live &#8211; and sanity! Finally, after almost a year of working on it, I have finished Rune Hunt! Well, technically it&#8217;s been finished a couple of weeks ago. But I tried to find [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=153&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://pixelpracht.wordpress.com/2010/09/24/rune-hunt-released/blog_post_header/" rel="attachment wp-att-161"><img src="http://pixelpracht.files.wordpress.com/2010/09/blog_post_header.png?w=497&#038;h=260" alt="" title="blog_post_header" width="497" height="260" class="aligncenter size-full wp-image-161" /></a></p>
<blockquote><p>Hungry eyes watch from the shadows. The flickering light of a butterfly is all that keeps them at bay. Run for your live &#8211; and sanity! </p></blockquote>
<p>Finally, after almost a year of working on it, I have finished <strong>Rune Hunt</strong>! </p>
<p>Well, technically it&#8217;s been finished a couple of weeks ago. But I tried to find a portal that would sponsor the game. The basic idea of sponsorship is that you include links and logos of a flash game portal in your game before you spread it. The branding means traffic for the sponsor and that traffic is what they essentially pay you for. The other great thing besides money is that the sponsoring portal has an interest in getting your game played and will help spreading it &#8211; for example by featuring it on the front page. So you get money, exposure and retain full creative control. Cool stuff!</p>
<p>So in the last weeks I&#8217;ve spend quite a while on <a href="flashgamelicense.com">flashgamelicense.com</a> and learned a great deal about how the market around free flash games works. The website is basically an agent that brings developers and sponsors together. Sponsors can bid on your games, after a while you pick the best offer and pay a comission to FGL. The process of trying to license my own game was nerve-wrecking but fun and in the end pretty successful. Huge thanks to <a href="http://armorgames.com">ArmorGames</a> for the generous sponsorship!</p>
<p>But enough of that for now. Go and <a href="http://armorgames.com/play/6963/rune-hunt">play the game</a> allready! <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pixelpracht.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pixelpracht.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pixelpracht.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pixelpracht.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pixelpracht.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pixelpracht.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pixelpracht.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pixelpracht.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pixelpracht.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pixelpracht.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pixelpracht.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pixelpracht.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pixelpracht.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pixelpracht.wordpress.com/153/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=153&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pixelpracht.wordpress.com/2010/09/24/rune-hunt-released/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b440466bf29e504f3b29eca70f3c98ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lithander</media:title>
		</media:content>

		<media:content url="http://pixelpracht.files.wordpress.com/2010/09/blog_post_header.png" medium="image">
			<media:title type="html">blog_post_header</media:title>
		</media:content>
	</item>
		<item>
		<title>Drawing API Memory-Leak in Flash 10.1</title>
		<link>http://pixelpracht.wordpress.com/2010/07/06/drawing-api-memory-leak-in-flash-10-1/</link>
		<comments>http://pixelpracht.wordpress.com/2010/07/06/drawing-api-memory-leak-in-flash-10-1/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 12:35:17 +0000</pubDate>
		<dc:creator>lithander</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://pixelpracht.wordpress.com/?p=122</guid>
		<description><![CDATA[When trying Rune Hunt in the new 10.1 version of the Flash Player I noticed a HUGE performance drop. In the old player it would take about 27ms on my system (debug build) to update the game&#8217;s state and render the next frame. In Flash Player 10.1 this changed: The time it took to calculate a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=122&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When trying <a href="http://pixelpracht.wordpress.com/2010/03/06/game-preview-rune-hunt/">Rune Hunt</a> in the new 10.1 version of the Flash Player I noticed a HUGE performance drop. In the old player it would take about 27ms on my system (debug build) to update the game&#8217;s state and render the next frame. <strong>In Flash Player 10.1 this changed: The time it took to calculate a frame started fluctuating and increased to 48ms on average.</strong></p>
<p>A member of the  Flash Player Engineering team the new player replied to my inquiry about known performance issues:</p>
<blockquote><p>General actionscript performance is not any slower in 10.1 than 10.0  from our testing, it must be something particular in your code which exhibits the problem. Do you have a reproducable test code or a url you can point us at?</p></blockquote>
<p>So I tried to isolate and reproduce my problems. It seems that my problems are caused by a <a href="https://bugs.adobe.com/jira/browse/FP-4812">Memory Leak in the Drawing API</a>. I wrote a simple test application to illustrate the issue and hopefully find a work-around.</p>
<p><pre class="brush: plain;">
//... there`s a buffer as rendertarget and a flare
private var _flare:BitmapData = null;
private var _buffer:BitmapData = null;

//each frame I render the flare 100 times into the buffer 
for(var i:int = 0; i &lt; 100; i++)
    _buffer.draw(_flare, null, null, BlendMode.ADD);
</pre></p>
<p>In the 10.0 player there is no memory fluctuation caused by this code. But in the 10.1 player each draw-call allocates new memory. The total memory is increasing linearily until the garbage collector kicks in. This of course effects the performance.</p>
<p><img src="http://pixelpracht.files.wordpress.com/2010/07/flash_performance_decrease.png?w=497" alt="" title="flash_performance_decrease"   class="aligncenter size-full wp-image-124" /></p>
<p>In all browsers and on all systems that I tested the memory leak was present in the new player &#8211; but the way the garbage collector handled it varied so the graph isn&#8217;t always as clear. You can <a href="http://files.pixelpracht.net/perftest">test it</a> for yourself. And here&#8217;s the <a href="http://files.pixelpracht.net/DrawPerformanceTest.zip">source</a> for the test application.</p>
<p>My guess at what happens: BitmapData.draw() method accepts IBitmapDrawable an interface that is implemented by all DisplayObjects and BitmapData objects. If you pass a BitmapData object however it seems like memory gets allocated based on the size of the render target. This memory is not reused or instantly freed but has to be collected by the garbage collector. </p>
<p><strong>Knowing this there&#8217;s a neat workaround: If you wrap the BitmapData in a Bitmap before you draw it you can avoid the bugged code and the memory keeps steady!</strong></p>
<p><pre class="brush: plain;">
//wrap _flare in a Bitmap (do this only once!)
_flareBmp = new Bitmap(_flare);

//now instead of _flare render _flareBmp
for(var i:int = 0; i &lt; 100; i++)
    _buffer.draw(_flareBmp, null, null, BlendMode.ADD);
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pixelpracht.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pixelpracht.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pixelpracht.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pixelpracht.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pixelpracht.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pixelpracht.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pixelpracht.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pixelpracht.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pixelpracht.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pixelpracht.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pixelpracht.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pixelpracht.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pixelpracht.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pixelpracht.wordpress.com/122/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=122&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pixelpracht.wordpress.com/2010/07/06/drawing-api-memory-leak-in-flash-10-1/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b440466bf29e504f3b29eca70f3c98ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lithander</media:title>
		</media:content>

		<media:content url="http://pixelpracht.files.wordpress.com/2010/07/flash_performance_decrease.png" medium="image">
			<media:title type="html">flash_performance_decrease</media:title>
		</media:content>
	</item>
		<item>
		<title>Resource Handling in Flash – Part Two</title>
		<link>http://pixelpracht.wordpress.com/2010/06/14/resource-handling-in-flash-part-two/</link>
		<comments>http://pixelpracht.wordpress.com/2010/06/14/resource-handling-in-flash-part-two/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 23:05:41 +0000</pubDate>
		<dc:creator>lithander</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[embedding]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[level-editor]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[wav]]></category>

		<guid isPermaLink="false">http://pixelpracht.wordpress.com/?p=87</guid>
		<description><![CDATA[In the last post I showed two approaches to access resources such as sound or image data in Flash. To make resources available to your application you can either load resources one-by-one on demand or embed them all into the main SWF file so they are available as soon as the application has loaded. Both [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=87&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://pixelpracht.wordpress.com/2010/06/02/resource-handling-in-flash-part-one/">last post</a> I showed two approaches to access resources such as sound or image data in Flash. To make resources available to your application you can either load resources one-by-one on demand or embed them all into the main SWF file so they are available as soon as the application has loaded. Both variants however have limitations. So in this post I&#8217;m going to show some alternatives.</p>
<p><span id="more-87"></span></p>
<h3>Drawbacks of loading on demand</h3>
<ul>
<li>different types of resources require different code to load.</li>
<li>there&#8217;s a gap between a resource beeing requested and the time it actually becomes available.</li>
<li>if you require multiple resources at once (loading the next level data) you have to open one connection for each resource which means a tremendous overhead.</li>
<li>if you&#8217;re loading multiple resources you have to keep track of multiple loaders to know your overall progress</li>
<li>when a resource fails to load you have to detect and handle it.</li>
</ul>
<h3>Drawbacks of embedding</h3>
<ul>
<li>Code and Data are not decoupled: When the assets change you have to change and recompile your code.</li>
<li>Workflow issues: How can content creators (artists, level designers) test their work ingame?</li>
<li>Transcoding a resource into a flash compatible format is taking time and so for large applications build times explode.</li>
<li>It&#8217;s likely that more data is pre-loaded than is actually required in a users session. The long initial load time might become a barrier for users and it certainly wastes bandwidth.</li>
</ul>
<h2>Alternatives</h2>
<p>The general approach to overcome these limitations is to decouple your data from your logic but preprocess  and package the data into a Flash compatible format so it becomes  trivial to join logic and data when needed.</p>
<h3>Option #1 &#8211; Statically linked SWCs</h3>
<p>If you don&#8217;t need loading on demand you can create a SWC file containing the resources and link it with your main application. The effect is the same as if you&#8217;d have embedded all the files directly but by splitting resources into multiple projects you keep your build times fast. Projectes are re-compiled seperately and only when needed.</p>
<p>It&#8217;s also nice that you can create the SWCs with more artist friendly tools like the Flash IDE. This provides additional benefits like build-in conversion of Sounds from WAV format to flash compatible MP3 encoding. I get back to that later.</p>
<p>To link a SWC in<strong> Flex/Flash Builder</strong> you select <strong>Project-&gt;Properties</strong> and click the &#8220;<strong>Add SWC</strong>&#8221; button in the <strong>ActionScript Build Path</strong> category to select and add the SWC containing the resources.</p>
<p><a href="http://pixelpracht.files.wordpress.com/2010/06/importswc.jpg"><img class="aligncenter size-full wp-image-102" title="Imprting an SWC in Flash Builder" src="http://pixelpracht.files.wordpress.com/2010/06/importswc.jpg?w=497" alt=""   /></a></p>
<p>Now the resources are available at compile time by their class-names just like if you embedded them using the <strong>Embed-Tag</strong>.</p>
<p>For example in the &#8220;sounds.swc&#8221; I have  a number of <em>embedded asset classes</em> for sound effects. They have names like &#8220;firefly_flee&#8221; or &#8220;music_title_screen&#8221; and extend the Sound class. To play &#8220;firefly_flee&#8221; I just have to instantiate it and call the play() method:</p>
<p><pre class="brush: plain;">
var sound:Sound = new firefly_flee();
sound.play();
</pre></p>
<h3>Option #2 &#8211; Dynamically load and link SWFs</h3>
<p>In Option #1 you still have to recompile your main appliciation whenever a  resource pack has changed and every linked resource will get pre-loaded  whether you&#8217;ll need it or not. Alternatively you can package the resources in a SWF instead of a SWC and load it on  demand. To load a SWF use a Loader class.</p>
<p><pre class="brush: plain;">
function load():void
{
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
    var urlReq:URLRequest = new URLRequest(&quot;sounds.swf&quot;);
    loader.load(urlReq);
}
</pre></p>
<p>When <strong>onLoaded </strong>is called the SWF has been loaded including all the embedded Resources. But how to access them? The SWF contains a specifically named class for each resource. You might know their names but since the classes weren&#8217;t present at compile time you couldn&#8217;t write any code using them. So before you can use the resource class to create an instance of the resource we have to retrieve that class by its name.</p>
<p><pre class="brush: plain;">
public function onLoaded(event:Event):void
{
    var info:LoaderInfo = event.currentTarget as LoaderInfo;
    var soundClass:Class = info.applicationDomain.getDefinition(&quot;firefly_flee&quot;) as Class;
    var sound:Sound = new sndClass;
    sound.play();
}
</pre></p>
<p>An <strong>ApplicationDomain </strong><strong>is a container for AS3 definitions</strong> and if not specified otherwise each loader will create it&#8217;s own applicationDomain where it adds all the definitions that are part of the loaded SWF. Of course you wouldn&#8217;t want to play a sound right in an event handler. Instead just load the SWF once and then store a pointer to the applicationDomain and call getDefinition on it whenever you need a class.</p>
<p>Now a smart question to ask would be: <em>Why do I have to load the classes into a new ApplicationDomain and keep a pointer to it? Can&#8217;t I just add all the definitions to where my other classes are stored?</em></p>
<p>Yes you can. Just provide a <strong>LoaderContext</strong> when requesting to load the SWF and in that LoaderContext you can specify in what AppDomain you want the definitions to end up.</p>
<p><pre class="brush: plain;">
loader.load(urlReq, new LoaderContext(false, ApplicationDomain.currentDomain));
</pre></p>
<p>Now whenever you want to reference a resource you can get the resource class  by calling getDefinition on the ApplicationDomain.currentDomain.</p>
<p>But a word of caution: You have to make sure that there are no naming collisions. Classes that allready exist in the currentDomain will not be replaced by a definition of the same name in the newly loaded SWF. And classes once added the main SWFs AppDomain can&#8217;t be removed. If you want to be able to <em>unload</em> dynamically loaded resources you have to keep them in different AppDomains.</p>
<p>If you want to learn more about Application Domains read <a href="http://blogs.adobe.com/rgonzalez/2006/06/applicationdomain.html">this excellent post</a>.</p>
<h3>Options #3 &#8211; Use Flex Modules</h3>
<p>Last option combines the benefits of both: Using Modules. The basic idea is that you know all the classes at compile time so you can code against them but then you don&#8217;t link them into your main SWF but into seperate SWFs that get loaded dynamically on demand or when you request it using the ModuleManager singleton. The drawback? This technology is part of the Flex framework and Flex applications are typically bigger then pure ActionScript applications. But if you are going with Flex anyone check it out!</p>
<h2>Creating Resource Projects</h2>
<p>While you can create resource projects in <strong>Flash Builder</strong> the <strong>Flash IDE</strong> is a better suited for that. Adding resources to the Library using drag &amp; drop and getting a preview is handy.<br />
<em><strong>Right click -&gt; Linkage</strong>..</em>. and you can mark that file to be exported for ActionScript.</p>
<p><a href="http://pixelpracht.files.wordpress.com/2010/06/linkage.jpg"><img class="aligncenter size-medium wp-image-94" title="Linkage Properties in Flash CS3" src="http://pixelpracht.files.wordpress.com/2010/06/linkage.jpg?w=300&#038;h=162" alt="" width="300" height="162" /></a></p>
<p>The class name can be edited to your liking. To generate a SWF just publish the file. If you want to generate a SWC for static linking with your main application check the <em><strong>Export SCW</strong></em> option in the <em><strong>Publish Settings Dialog</strong></em>.</p>
<p>The main reason for using the <strong>Flash IDE </strong>however is that it allows you to embedd files that would otherwise not be embeddable.</p>
<p>Most notably: <span style="text-decoration:underline;">Flash will encode WAV files as Mp3</span> for you. Details like encoding quality can be specified in the<em><strong> Publish Settings Dialog</strong></em>. But in any case Flash will create &#8220;loopable&#8221; Mp3&#8242;s that don&#8217;t suffer from the infamous gaps at the start and finish of the sound.</p>
<p>Another neat features: When you embedd images you can chose to JPEG-compress them and even specify the quality. Even PNGs with trancparency can have their RGB channels JPEG compressed which can reduce the memory-footprint considerably.</p>
<p>A completely different approach to genereating resource packs is to use some custom automated process. For example you could write a Level-Editor in a langauge like C# but export the levels as a ready-to-load SWF file by generating appropriate source files and feeding them to the Flex commandline compiler.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pixelpracht.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pixelpracht.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pixelpracht.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pixelpracht.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pixelpracht.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pixelpracht.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pixelpracht.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pixelpracht.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pixelpracht.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pixelpracht.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pixelpracht.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pixelpracht.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pixelpracht.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pixelpracht.wordpress.com/87/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=87&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pixelpracht.wordpress.com/2010/06/14/resource-handling-in-flash-part-two/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b440466bf29e504f3b29eca70f3c98ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lithander</media:title>
		</media:content>

		<media:content url="http://pixelpracht.files.wordpress.com/2010/06/importswc.jpg" medium="image">
			<media:title type="html">Imprting an SWC in Flash Builder</media:title>
		</media:content>

		<media:content url="http://pixelpracht.files.wordpress.com/2010/06/linkage.jpg?w=300" medium="image">
			<media:title type="html">Linkage Properties in Flash CS3</media:title>
		</media:content>
	</item>
		<item>
		<title>Resource Handling in Flash – Part One</title>
		<link>http://pixelpracht.wordpress.com/2010/06/02/resource-handling-in-flash-part-one/</link>
		<comments>http://pixelpracht.wordpress.com/2010/06/02/resource-handling-in-flash-part-one/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 01:37:16 +0000</pubDate>
		<dc:creator>lithander</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[embedding]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[resource]]></category>

		<guid isPermaLink="false">http://pixelpracht.wordpress.com/?p=77</guid>
		<description><![CDATA[It&#8217;s easy to pickup ActionScript3 with a programming background in C++,/C# or Java as the languages shares the same concepts and similar syntax. So, why learn about stages and timelines, keyframes and whatnot when you can write your games like you always did? Well&#8230; almost. There are concepts in Flash that require some getting used [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=77&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>It&#8217;s easy to pickup ActionScript3 with a programming background in <em>C++</em>,/<em>C#</em> or <em>Java</em> as the languages shares the same concepts and similar syntax. So, why learn about stages and timelines, keyframes and whatnot when you can write your games like you always did? Well&#8230; almost. <strong>There are concepts in Flash that require some getting used to</strong>. Resources is one of them.</p></blockquote>
<p>There are two fundamental different ways to get your resources loaded.</p>
<p>One is to <strong>embedd all the potentially needed data</strong> into your SWF file. This increases the initial loading time but once the application has fully loaded all resources are instantly available, too.</p>
<p>The second option is to send a lean application and <strong>load individual resources</strong> on demand. This is will reduce the initial load but making things less convenient for the coder and user.</p>
<p><span id="more-77"></span></p>
<h2>Loading Resources on Demand</h2>
<p>Loading individual resources when they are needed is similar to what you&#8217;d do in most local applications only that a request takes a lot longer to return the result because the data is on a server and not your local harddisk. Pausing the application while waiting for the result isn&#8217;t an option so instead you make the request and then register an event-listener to get notified when the resource has been loaded. Flash provides two classes for this task called Loader and URLLoader.</p>
<p><pre class="brush: plain;">
function load():void
{
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
    var urlReq:URLRequest = new URLRequest(myimage.jpg);
    loader.load(urlReq);
}
</pre></p>
<p><pre class="brush: plain;">
function onLoadComplete(event:Event):void
{
    var myimage:Bitmap = event.target.content as Bitmap;
}
</pre></p>
<p>The Loader can be used for images and SWF files only. To to load binary data like XML or TXT files you use the URLLoader class instead. You access the resource using the <tt>data</tt> property instead of one named <tt>content</tt> and you usually have to do use some other classes to interpret the raw binary data. For example to load an XML file you have to pass the data as a constructor parameter to a newly created XML instances.</p>
<p><pre class="brush: plain;">
function load():void
{
    var loader:URLLoader = new URLLoader();
    loader.addEventListener(Event.COMPLETE, onLoaded);
    var urlReq:URLRequest = new URLRequest(myxml.xml);
    loader.load(urlReq);
}

function onLoadComplete(event:Event):void
{
    var myxml:XML= new XML(event.target.data);
}
</pre></p>
<p>So we see that depending on the type of resource you have to use different loading mechanisms. There is no general approach &#8211; sometimes classes even provide integrated loading. For example to load an MP3 (the only sound format natively supported) you use the load function of the Sound class which is special in the way that it allows you to start playback before the resource has fully loaded. (Streaming)</p>
<p><pre class="brush: plain;">
function load():void
{
    var sound:Sound = new Sound();
    var urlReq:URLRequest = new URLRequest(mysound.mp3);
    sound.load(urlReq);
    sound.play();
}
</pre></p>
<p>The above examples show that while it is possible to load individual resources on demand there is not one generalized approach to do so. This can make it quite difficult to integrate for large applications.</p>
<h2>Embedding Resources</h2>
<p>Another option is to embedd all potentially required resources directly into your SWF file. To do so you must use the [Embed] metadata tag before a variable definition of type Class. As a parameter of the [Embed] tag you specify a resource location. When your sourcecode is compiled a new class is added that represents the embedded resource and the class-variable right below the embed tag will point to it. This variable can then be used to instantiate copies of the resource.</p>
<p><pre class="brush: plain;">
	[Embed(source=&quot;data/music.mp3&quot;)]
	private var music_sound:Class;

	function playMusic():void
	{
		var sound:Sound = new music_Sound();
		sound.play();
	}
</pre></p>
<p>If you don&#8217;t provide an absolute path to the resource (starting with a drive-letter) Flex matches the path to at least 3 directories: the projects root, the source directory and the directory of the file containing the embed tag. You can not use URLs to resources.</p>
<p>Once a resource is located it gets transcoded and added to the SWF as a full featured AS3 class. These generated classes are called <em>embedded asset classes</em> and inherit from the well known base classes classes.<br />
For example a JEPG will end up as a descendant of the Bitmap class. The only difference to the ordinary Bitmap class is that when you instantiate the embedded asset class (with the <tt>new</tt> keyword) you get a Bitmap that preinitialized with the embedded JPEG.</p>
<p>What kind of class is generated to represent a resource depends on file extensions.</p>
<ul>
<li>JPEGs, GIFs and PNGs -&gt; Bitmap</li>
<li>Mp3s -&gt; Sound</li>
<li>SVG -&gt; Sprite</li>
<li>SWF -&gt; MovieClip</li>
<li>TTF -&gt; Font</li>
</ul>
<p><em>Note: for Fonts you need to specify an additional parameter <tt>fontFamily</tt> to be able to use it by name like any other font.<br />
</em></p>
<p>Sometimes you&#8217;ll want to embedd resources that are haven a unsupported file extension. In this case you have to specify explicitly how to transcode the file. Usually an unsupported file extension means that the file format is one that isn&#8217;t in the list above so your best option is to encode it as binary data. To do so set the <tt>mime-type</tt> parameter to <em>&#8216;application/octet-stream&#8217;</em>.</p>
<p>The <em>embedded asset class</em> created for binary data descends from the ByteArray class. So you can embedd *any* file in flash but for some you get only a very lowlevel representation. But with a bit of luck there are higher level classes available to handle it with. Remeber the example about loading an XML dynamich using the URLLoader? The same works when embedding the XML:</p>
<p><pre class="brush: plain;">
	[Embed(source = &quot;some_xml.xml&quot;, mimeType=&quot;application/octet-stream&quot;)]
	private static var xml_binary:Class;

	function doSomething():void
	{
		var xml:XML = new XML(new xml_binary());
		//do stuff
	}
</pre></p>
<p>A quite similar process is used to embed Pixelbender shaders. And if you want to embed text files you can access the content by converting the binary data to a String:</p>
<p><pre class="brush: plain;">
	[Embed(source = &quot;ramblings.txt&quot;, mimeType=&quot;application/octet-stream&quot;)]
	private static var txt_binary:Class;

	function doSomething():void
	{
		var bytes:ByteArray = new txt_binary;
		var text:String = bytes.toString();
		//do stuff
	}
</pre></p>
<p>This is an extensive post allready but so far I&#8217;ve only touched the basics. In the <a href="http://pixelpracht.wordpress.com/2010/06/14/resource-handling-in-flash-part-two/">second part</a> I list some drawbacks of these simple methods. I explain an alternative approach in which multiple resources get packed in SWFs or SWCs and linked with the main project either dynamicly or staticly. I&#8217;m also showing how to use the Flash IDE to create such resource packs because this provides better worklfow and treats like automated encoding of WAV files with support for support gap-less looping.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pixelpracht.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pixelpracht.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pixelpracht.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pixelpracht.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pixelpracht.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pixelpracht.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pixelpracht.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pixelpracht.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pixelpracht.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pixelpracht.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pixelpracht.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pixelpracht.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pixelpracht.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pixelpracht.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=77&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pixelpracht.wordpress.com/2010/06/02/resource-handling-in-flash-part-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b440466bf29e504f3b29eca70f3c98ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lithander</media:title>
		</media:content>
	</item>
		<item>
		<title>Flash TMX Parser</title>
		<link>http://pixelpracht.wordpress.com/2010/03/31/flash-tmx-parser/</link>
		<comments>http://pixelpracht.wordpress.com/2010/03/31/flash-tmx-parser/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 22:25:46 +0000</pubDate>
		<dc:creator>lithander</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[level-editor]]></category>
		<category><![CDATA[Tiled]]></category>
		<category><![CDATA[tmx]]></category>

		<guid isPermaLink="false">http://pixelpracht.wordpress.com/?p=59</guid>
		<description><![CDATA[I&#8217;ve created all the key gameplay elements for Rune Hunt and the next step is to build levels to see if they can be used to create fun gameplay. I didn&#8217;t want to write my own tools so I searched for a map editor flexible and feature complete enough to meet my requirements. The editor [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=59&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created all the key gameplay elements for <a href="http://pixelpracht.wordpress.com/2010/03/06/game-preview-rune-hunt/">Rune Hunt</a> and the next step is to build levels to see if they can be used to create fun gameplay. I didn&#8217;t want to write my own tools so I searched for a map editor flexible and feature complete enough to meet my requirements. The editor that impressed me the most was the <a href="http://mapeditor.org/">Tiled Map Editor</a> that has comfy features (including Undo!) and exports an xml based level format.</p>
<p>For people interested in using <strong>Tiled</strong> for their flash game but unsure how to handle the level format I&#8217;ve put together a little example. It contains code that parses a tmx file and recreates the data on the flash side in form of custom classes designed to make all the data easily accessible. The code is generic enough to be used in about any AS3 based project. I support XML, CSV, base64 and zlib-compressed base64 encoding. </p>
<p>In my sample I modified a <a href="http://flixel.org">Flixel Framework v2.23</a> based demo (the original version called <strong>FlxCollision</strong> is available <a href="http://github.com/AdamAtomic/FlxCollisions">on githup</a>) to reload the current game state out of a TMX file on keypress. If you run the editor and the swf simultanously you can make changes in the editor, save, switch to the swf, press the <em>Enter</em> key and see the changes taking effect.</p>
<div id="attachment_61" class="wp-caption aligncenter" style="width: 310px"><a href="http://pixelpracht.files.wordpress.com/2010/03/screenshot.png"><img class="size-medium wp-image-61" title="Tiled Editor and Demo App" src="http://pixelpracht.files.wordpress.com/2010/03/screenshot.png?w=300&#038;h=225" alt="" width="300" height="225" /></a><p class="wp-caption-text">Tiled Editor and Demo App</p></div>
<p>If you&#8217;re interested it&#8217;s easy to give it a try. No source compiling is required. Just <a href="http://files.pixelpracht.net/flxTiled.rar">get the files</a> and unzip them somewhere. Then execute the <strong>FlxCollisions.swf</strong> file found in <strong>bin-debug</strong> by double clicking it and load the level <strong>map01.tmx</strong> found in <strong>bin-debug/data</strong> in the map editor. No restarting of the flash app should be required. Just trigger the reload ingame whenever you changed something!</p>
<p>If you want to use the same approach for your own project all relevant code is included. The interesting parts are found in the <strong>PlayStateTmx</strong> class where the TMX file is loaded and parsed and then used to populate the FlxState with level content matching the tiles and objects described in the level file. Have fun! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pixelpracht.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pixelpracht.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pixelpracht.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pixelpracht.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pixelpracht.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pixelpracht.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pixelpracht.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pixelpracht.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pixelpracht.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pixelpracht.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pixelpracht.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pixelpracht.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pixelpracht.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pixelpracht.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pixelpracht.wordpress.com&amp;blog=10285574&amp;post=59&amp;subd=pixelpracht&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pixelpracht.wordpress.com/2010/03/31/flash-tmx-parser/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b440466bf29e504f3b29eca70f3c98ea?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">lithander</media:title>
		</media:content>

		<media:content url="http://pixelpracht.files.wordpress.com/2010/03/screenshot.png?w=300" medium="image">
			<media:title type="html">Tiled Editor and Demo App</media:title>
		</media:content>
	</item>
	</channel>
</rss>
