<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Cold Constructs</title>
	
	<link>http://coldconstructs.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 26 Oct 2009 21:22:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/ColdConstructsNews" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Beware the rounding error (or “Avoiding Out of Range errors”)</title>
		<link>http://coldconstructs.com/2009/10/beware-the-rounding-error/</link>
		<comments>http://coldconstructs.com/2009/10/beware-the-rounding-error/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 20:00:35 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ActionScript 3]]></category>

		<guid isPermaLink="false">http://coldconstructs.com/?p=223</guid>
		<description><![CDATA[When iterating through an array that was generated by some built-in function (such as getVector()), check to make sure you&#8217;re rounding the input first. If you get an &#8220;out of range&#8221; error but your code is fucking perfect, then it&#8217;s probably because the rectangle used as input by getVector is skipping a row of pixels [...]]]></description>
			<content:encoded><![CDATA[<p>When iterating through an array that was generated by some built-in function (such as <code>getVector()</code>), check to make sure you&#8217;re rounding the input first. If you get an &#8220;out of range&#8221; error but your code is fucking perfect, then it&#8217;s probably because the rectangle used as input by <code>getVector</code> is skipping a row of pixels because the x,y of said rectangle is being rounded UP. For example, <code>12.51</code> becomes <code>13</code> but since the rectangle is limited by certain dimensions it simply (stupidly, moronically, fucking ridiculously) truncates the dimensions by one row or column. So when it turns the pixel data into a 1D array it&#8217;s missing a whole chunk of data which causes your pre-computed (with the correct dimensions) array length to be <em>too high</em>&#8230; hence the iterator will hit a number outside the array&#8217;s range.</p>
<p>Judging by the number of results Google returns, this is a pretty fringe case (that or I&#8217;m exceptionally stupid&#8230; hush). Regardless, it&#8217;s a problem that has been plaguing me for the past few months. If it weren&#8217;t for my genius programmery brother I would have never found it either. But thanks to him I&#8217;m now savvy to what&#8217;s termed as &#8220;rounding errors&#8221;. They even <em>sound</em> evil.</p>
<p>Here&#8217;s an example with code&#8230;<br />
<span id="more-223"></span><br />
Below we define our dimensions grabbed from pixels (raw <code>bitmapData</code> from some loaded file elsewhere). We just want to analyze a quarter of the image, hence we&#8217;re dividing both dimensions by 2. We also instantiate the array (a fixed-length <code>Vector</code>) we&#8217;ll be iterating through:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p223code4'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2234"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p223code4"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> w<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = pixels<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> h<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = pixels<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> _l<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = w <span style="color: #000066; font-weight: bold;">*</span> h<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> _rc<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=rectangle%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:rectangle.html"><span style="color: #004993;">Rectangle</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=rectangle%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:rectangle.html"><span style="color: #004993;">Rectangle</span></a><span style="color: #000000;">&#40;</span>0<span style="color: #000066; font-weight: bold;">,</span> 0<span style="color: #000066; font-weight: bold;">,</span> w<span style="color: #000066; font-weight: bold;">,</span> h<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
array = <span style="color: #0033ff; font-weight: bold;">new</span> Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>uint<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#40;</span>_l<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>Awesome. Now somewhere else in the code (say, an update method) we want to assign a chunk of pixel data to the array so we can pick through them one by one:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p223code5'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2235"><td class="line_numbers"><pre>6
7
8
9
10
11
12
</pre></td><td class="code" id="p223code5"><pre class="actionscript3" style="font-family:monospace;">_rc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = pixels<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span>
_rc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = pixels<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span>
array = pixels<span style="color: #000066; font-weight: bold;">.</span>getVector<span style="color: #000000;">&#40;</span>_rc<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> _l<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	_pixel = array<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">alpha</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span style="color: #004993;">uint</span></a> = _pixel <span style="color: #000066; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight:bold;">24</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Alright, looks mighty fine. We&#8217;re just checkin&#8217; out the alpha value in those pixels, you know whatever. BUT WAIT. While we&#8217;re running this code, the values for <code> pixels.x</code> and <code> pixels.y</code> are changing because our source image is moving around the stage. And guess what? Without pixel snapping on, we&#8217;re getting floating point values for those coordinates <strong>even though they&#8217;re typed as <code>int</code>s</strong>. This wouldn&#8217;t normally be a problem but since we&#8217;re extracting other pixel data using those values, they need to be floored or else we&#8217;ll get the rounding error I discussed above.</p>
<p>So to fix this bitch we simply change lines 6 and 7 to:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p223code6'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2236"><td class="line_numbers"><pre>6
7
</pre></td><td class="code" id="p223code6"><pre class="actionscript3" style="font-family:monospace;">_rc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000000;">&#40;</span>pixels<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
_rc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000000;">&#40;</span>pixels<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>&#8230;and viola, no more error. (I used <code>int()</code> instead of <code>Math.floor()</code> because it&#8217;s hella faster). So I hope that helped someone out there because I sure as hell needed it <img src='http://coldconstructs.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  Good luck and have fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://coldconstructs.com/2009/10/beware-the-rounding-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 to Pixel Bender guide</title>
		<link>http://coldconstructs.com/2009/10/pixel-bender-gap-guide/</link>
		<comments>http://coldconstructs.com/2009/10/pixel-bender-gap-guide/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 22:00:23 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Discussions]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Pixel Bender]]></category>

		<guid isPermaLink="false">http://coldconstructs.com/?p=134</guid>
		<description><![CDATA[

Best resources for beginners
Syntax overview
More performance tips
Realtime use of Pixel Bender

Asynchronous mode
Synchronous mode


Conclusion


When I set out to write a very simple Pixel Bender (PB) kernel/script thingy, I expected it to be relatively straight-forward, mostly because Adobe has been so good writing quality documentation for its products and/or there is a wealth of info on their [...]]]></description>
			<content:encoded><![CDATA[<div class="toc">
<ol>
<li><a href="http://coldconstructs.com/2009/10/pixel-bender-gap-guide/#toc-best-resources-for-beginners">Best resources for beginners</a></li>
<li><a href="http://coldconstructs.com/2009/10/pixel-bender-gap-guide/#toc-syntax-overview">Syntax overview</a></li>
<li><a href="http://coldconstructs.com/2009/10/pixel-bender-gap-guide/#toc-more-performance-tips">More performance tips</a></li>
<li><a href="http://coldconstructs.com/2009/10/pixel-bender-gap-guide/#toc-realtime-use-of-pixel-bender">Realtime use of Pixel Bender</a>
<ol>
<li><a href="http://coldconstructs.com/2009/10/pixel-bender-gap-guide/#toc-asynchronous-mode">Asynchronous mode</a></li>
<li><a href="http://coldconstructs.com/2009/10/pixel-bender-gap-guide/#toc-synchronous-mode">Synchronous mode</a></li>
</ol>
</li>
<li><a href="http://coldconstructs.com/2009/10/pixel-bender-gap-guide/#toc-conclusion">Conclusion</a></li>
</ol>
</div>
<p>When I set out to write a very simple Pixel Bender (<em>PB</em>) kernel/script thingy, I expected it to be relatively straight-forward, mostly because Adobe has been so good writing quality documentation for its products and/or there is a wealth of info on their products produced by their users. Unfortunately I didn&#8217;t find the dev guide in the Help menu and I missed some key AS3 bits from the links I&#8217;ll post below, but even so I still had a lot of trouble finding some info that really should already have been out on the interwebs. So this post is to fill in the gaps when going from AS3 to Pixel Bender.<br />
Hope it helps <img src="http://coldconstructs.com/random/pint.gif"></p>
<h4 id="toc-best-resources-for-beginners">Best resources for beginners</h4>
<p>Here&#8217;s the best tutorials and explanations I&#8217;ve found so far:</p>
<ul>
<li><a href="http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS3E659D01-10C0-479d-8175-B40950BBC223.html">The official guide</a> and <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/index.html">reference</a>. Slap that F1 key! Also, don&#8217;t forget the Help menu in the toolkit like I did (there&#8217;s the PB-specific language spec and dev guide there).</li>
<li><a href="http://www.flashmagazine.com/tutorials/detail/using_pixel_bender_to_calculate_information/">Using PB as a calculator</a>. Completes the official tutorial.</li>
<li><a href="http://www.kaourantin.net/2008/05/adobe-pixel-bender-in-flash-player-10.html">Great in-depth article</a> with general+performance tips.</li>
<li>Very <a href="http://blog.gamingyourway.com/default.aspx">straight-forward examples</a> + comedy. Can&#8217;t go wrong there.</li>
<li><a href="http://www.derschmale.com/2009/07/23/some-flash-pixel-bender-performance-tips-benchmarks/">Nice user article</a> on optimizations and some speed tests (turns out, for input <code>bitmapData</code> beats <code>ByteArray </code>beats <code>Vector.<T></code>)</li>
</ul>
<h4 id="toc-syntax-overview">Syntax overview</h4>
<p>As a casual programmer of high-level languages and no mid- to low-level ones, I was thrown off by PB&#8217;s awkward syntax. It&#8217;s strongly typed, which is fine, except I&#8217;m not familiar with low-level languages like C or any previous shader language (PB is based on GLSL from what I hear). Here&#8217;s a basic difference:</p>
<blockquote><p>AS3: <code>var i:Number = 12;</code><br />
&#8230;in PB is: <code>float i = 12.0;</code><br />
The decimal in <code>12.0</code> tells PB it&#8217;s a floating point number. If it was just <code>12</code> PB would think it&#8217;s an <code>int</code>.</p></blockquote>
<p>When dealing with &#8220;vectors&#8221; (which are arrays, as in Flash 10&#8217;s odd use of the word &#8220;vector&#8221;) it&#8217;s <code>float2 i = float2(12.0, 2.0)</code>. Notice there&#8217;s no brackets or anything suggesting any type of array present. It&#8217;s simply the type + how big the array is, eg <code>float3</code>. It goes up to 4, for the 4 channels in images: Red, Green, Blue, Alpha). Then, as you can see, intializing the array is a simple matter of putting in the numbers you said would be there. So <code>float4(1.0, 24.2, 0.1, 3.4)</code> is valid whereas <code>float2(1.0, 24.2, 2)</code> is not, because there&#8217;s an extra number in there and it&#8217;s an <code>int</code> (adding insult to injury).</p>
<p><span id="more-134"></span></p>
<p>An important thing to keep in mind is that Pixel Bender sees channels in the order described above (RGBA). This little detail cost me a bit of time because I&#8217;m used to AS3&#8217;s order of ARGB&#8211;the alpha channel is first in AS3 while it&#8217;s <em>last</em> in PB.</p>
<p>To use any of the built-in functions you simply call them as they appear in the reference doc: <code>all(x); atan(x,y);</code> etc., no <code>Math</code> calls like we have to do in Flash (this through me for a loop, lemme tell ya).</p>
<p>For those of you who use the shortcut operations like <code>var i:int = foo < bar ? foo : bar;</code>, then you'll be pleased to hear they're supported in PB too. Just about the only thing "Hydra" (formally the codename for Pixel Bender, now--I guess--the name of the PB Flash implementation) does not support is loops of any kind<strong> and their related break/continue statements</strong>. That last bit is bad because there are times when I want to stop the filter if a certain condition is met. You just have to design your logic to take this into account from the start.</p>
<p>That's the basics but take special note that <code>shader.data</code> is actually an array, so you can do some naughty stuff like iterate through some kinky data and set the input as <code>shader.data['whatever'+i].input = kinky[i]</code>. Also note that in order to set the input for a shader in AS3 you <strong>must</strong> set it to <code>shader.data.vdipb.INPUT = inputImage</code> where <code>vdipb</code> is the variable name you declared in the PB shader itself.</p>
<h4 id="toc-more-performance-tips">More performance tips</h4>
<p>Turns out that after I converted my kernel from using boolean methods (like <code>boolean4()</code> etc.) to <code>if</code> statements, it consistently executed faster. I also got some fractional FPS increases by using the age-old optimization of putting real values (eg 1.2) in the evaluation statement instead of references (eg pixel.r). See the last blog I linked above for some other obvious and not-so-obvious performance tips.</p>
<p>PB math is much faster than straight AS3 math but it's slightly brighter (I wouldn't say it <em>shines</em> per se...) when it runs in asynchronous mode, which is enabled by using <code>ShaderJob</code>. You use <code>addEventListener(Event:ShaderEvent...)</code> and then run <code>start(false</code>) to put it in asynchronous mode (the param is <code>waitForCompletion</code> and it's already <code>false</code> by default). See <a href="http://www.boostworthy.com/blog/?p=243">Ryan's post</a> for a great example of how the <code>ShaderJob</code> has to be setup (<a href="http://blog.gamingyourway.com/default.aspx">Squize's post</a>, linked above, is an even clearer example).</p>
<h4 id="toc-realtime-use-of-pixel-bender">Realtime use of Pixel Bender</h4>
<h5 id="toc-asynchronous-mode">Asynchronous mode</h5>
<p>Reading the above linked performance tips for PB you, like me, might be thinking "OH MAN I can rule the universe with ShaderJob doing bitchwork like heavy collision solving" and you'd be <em>totally wrong</em>. You only have to set the input for a shader once, but you <em>do</em> have to create <strong>a new ShaderJob per computation of the filter every frame/tick</strong>. This is the depressing because <strong>ShaderJob takes a LONG time to start up</strong> and it, unlike the job itself, <em>does</em> use CPU from Flash's main thread--you do not get the asynchronous hotness until the actual job is started. And it is <em>sloooooowwwww</em>. Unless you're doing some serious number crunching or temporary special effect, you will not see a huge benefit from using PB in your game.</p>
<p>To be clear, ShaderJob works well enough for realtime usage but my experiments have shown that it's not fast enough to be executed every frame (unless you're SWF is running at 20 FPS or so). I tried to get it to fulfill my game's collision detection system by processing the entire map, but PB just couldn't handle the job. Still, I do recommend you try it (using Squize's recursive implementation) and see if it works for you. Just keep your hopes down <img src='http://coldconstructs.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h5 id="toc-synchronous-mode">Synchronous mode</h5>
<p>You can set <code>ShaderJob.start(true)</code> but if you're going the synchronous route, I suggest applying your Pixel Bender kernel by using the filter method. It starts up much faster than ShaderJob and doesn't have to be restarted every time you want to update the input. You do have to wait for it to finish processing before it will move to the next line in your code though, but as I mentioned above, PB math is a lot faster than AS3's Math library. So if you're doing something intense(r) like severe image distortion then PB is definitely worth a shot, but if it's just conditionals then you're probably better off in pure AS3 land.</p>
<h4 id="toc-conclusion">Conclusion</h4>
<p>Besides doing complex calculations, another place where PB would really help though is processing large (like 600 or 10000 pixels wide or bigger) images. It loops through each pixel faster than AS3 does. But remember that in AS3 you can do loops, so easily skipping pixels (using the <code>continue</code> statement) can result in some significant performance gains if you're not processing all the pixels in the input data (eg skipping transparent pixels). There's a lot of pro/cons so experimenting is, as always, the way to go (if you can afford it).</p>
<p>So there it is, all the info I wish was out there when I started learning PB (<em>I can't stop thinking of Peanut Butter!</em>). Hope some of it was helpful and of course I could be wrong about something (except about declaring input once, I've heard otherwise but in practice it worked fine) so please don't hesitate to correct me if so. Good luck and have fun <img src="http://coldconstructs.com/random/pint.gif"></p>
]]></content:encoded>
			<wfw:commentRss>http://coldconstructs.com/2009/10/pixel-bender-gap-guide/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Status update: games, the MTX dilemma, housekeeping</title>
		<link>http://coldconstructs.com/2009/10/status-update-2/</link>
		<comments>http://coldconstructs.com/2009/10/status-update-2/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 23:16:11 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Discussions]]></category>
		<category><![CDATA[Housekeeping]]></category>
		<category><![CDATA[Cold Constructs]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[status update]]></category>

		<guid isPermaLink="false">http://coldconstructs.com/?p=187</guid>
		<description><![CDATA[Makin&#8217; games
I&#8217;ve been working on a couple game concepts and want to prototype a few more before committing to one to build out. I&#8217;ve been hacking the hell out of Flixel, which I&#8217;ve decided to use for a most of the games. There&#8217;s a screenshot of game3 on the right there. Weird, eh? Also fugly, [...]]]></description>
			<content:encoded><![CDATA[<h4 id="toc-makin-games">Makin&#8217; games</h4>
<p><img src="http://coldconstructs.com/siteFiles/blogImages/game3_screen01.png" class="alignright bordered" />I&#8217;ve been working on a couple game concepts and want to prototype a few more before committing to one to build out. I&#8217;ve been hacking the hell out of <a href="http://flixel.org">Flixel</a>, which I&#8217;ve decided to use for a most of the games. There&#8217;s a screenshot of game3 on the right there. Weird, eh? Also fugly, but it&#8217;s placeholder art so there. I have a new collision detection system for it that I&#8217;ll be posting about eventually (at least, I&#8217;ve never heard of it before).</p>
<h4 id="toc-the-microtransaction-mtx-dilemma">The microtransaction (MTX) dilemma</h4>
<p>I&#8217;m really excited about all the new services that have been released to allow Flash developers to monetize their games through microtransactions. I fucking hate ads, plus the ROI of them in Flash games is usually shit. Many many years ago I knew microtransactions (MTX) were the future of digital content and I&#8217;m pleased to see the idea coming to the mainstream (in America at least, Asia was quicker on it as usual).</p>
<p><strong>The problem</strong> I&#8217;m seeing with MTX is that Flash developers need to try a lot harder by making <strong>much</strong> bigger games in order to really reap the rewards. Before, you could make a pretty simple, fun and addictive game and monetize it easily with ads. But with MTX, you can&#8217;t do that as easily since you need to build more content for players to buy into. For example, to me, putting premium content in a Tower Defense game isn&#8217;t viable&#8211;the game concept is so small that I doubt anyone is going to pay anything for more turrets or maps (for example). There just isn&#8217;t enough <em>game </em>there.</p>
<p><span id="more-187"></span></p>
<p>So in order to realistically bring MTX into our games I think we&#8217;re going to have to build much bigger games, and that kind of sucks because that makes it much harder for indie devs to make good on their work. Hell, this might actually decrease the quality of Flash games due to the higher gate devs will need to jump to get in. Well, let&#8217;s just see how it goes but I for one am having to take a lot more time building a game worthy of MTX-enabled content <img src='http://coldconstructs.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>By the by, below is my current list of MTX-enabling services currently available. If you know of any others, please leave a comment <img src="http://coldconstructs.com/random/pint.gif"></p>
<ul>
<li><a href="https://www.gamersafe.com/index.php">GamerSafe</a> &#8211; Seems to be the best choice so far. Adds achievements, microtransactions, save games, leaderboards, etc in a unified, web-wide accessible account.</li>
<li><a href="http://www.nonoba.com/developers">Nonoba</a> &#8211; Like GamerSafe, but also has a multiplayer network&#8230; but you must have a nonoba account to keep multiplayer stats/items etc (but guests can still play, just not save). Anyone used their multiplayer API yet?</li>
<li><a href="http://www.mochimedia.com/developers/coins.html">MochiCoins</a> &#8211; MTX only. Can&#8217;t use with other systems so I&#8217;m completely ignoring this one.</li>
<li><a href="http://www.heyzap.com/developers">HeyZap</a> &#8211; Also MTX only.</li>
</ul>
<p>It&#8217;s best to include as many options for your players as possible, so given this list, you would allow premium content to be purchased with GamerSafe, Nonoba and HeyZap.</p>
<h4 id="toc-new-additions-to-c3">New additions to C<sup>3</sup></h4>
<p>I&#8217;ve made a significant number of changes to the site itself. Besides the better layout (<a href="http://960.gs">960gs</a> ftw) I added <a href="http://wordpress.org/extend/plugins/wp-codebox/">this awesome</a> Wordpress plugin that does an excellent job highlighting AS3 code (see previous posts with code)&#8230; except it&#8217;s fat and makes the site load slower, but whatever. I can fix that with another plugin (I <3 WP). </p>
<p>Also you can socialize my posts now, using <a href="http://blogplay.com/">Sociable</a>; you&#8217;ll also see new blog posts updating my Twitter status (I mainly wrote this post to test that actually). I still have a bit to do for the site aesthetically though&#8230; but I kinda like tweaking themes, and now that IE is growing up (sort of) web design has been a little easier. I still can&#8217;t wait for Google&#8217;s <a href="http://code.google.com/chrome/chromeframe/">bitch-slap</a> to MS though. That&#8217;s so baller.</p>
]]></content:encoded>
			<wfw:commentRss>http://coldconstructs.com/2009/10/status-update-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MP Bar system</title>
		<link>http://coldconstructs.com/2009/05/mp-bar-system/</link>
		<comments>http://coldconstructs.com/2009/05/mp-bar-system/#comments</comments>
		<pubDate>Mon, 18 May 2009 08:02:55 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Introductions]]></category>
		<category><![CDATA[Metaplace]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[virtual intoxication]]></category>

		<guid isPermaLink="false">http://coldconstructs.com/?p=104</guid>
		<description><![CDATA[This is my most polished module and one that I&#8217;m most proud of. It&#8217;s a stupid fun module that, when you attach the behavior to an object, will allow users to browse a bar menu full of various drinks whenever they click on the object. It adds an icon of the drink the user selected [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://coldconstructs.com/p/metaplace/screenshots/barsystem.jpg" class="alignleft bordered">This is my most polished module and one that I&#8217;m most proud of. It&#8217;s a stupid fun module that, when you attach the behavior to an object, will allow users to browse a bar menu full of various drinks whenever they click on the object. It adds an icon of the drink the user selected to their nametag. The icon &#8220;drains&#8221; over time and eventually goes empty, at which point you should grab another.</p>
<p>Each drink adds a certain amount of &#8220;drunkeness points&#8221; for every sip (you can tell how many sips you have by the icon on your nametag) to your avatar and over time your avatar will show signs of intoxication, such as bubbles above their heads and the propensity to fall down randomly. You avatar has a drink tolerance that&#8217;s determined by your MP level and how many drinks you&#8217;ve had in a session.</p>
<p>As of this writing there&#8217;s only 4 types of beers to choose from. In the future I&#8217;ll be adding a lot more, and not just beer but wines and spirits too. Good stuff.</p>
<p>If you have any other ideas for what drunk effects I should add, let me know. (Note that I can&#8217;t touch the avatar graphics so I can&#8217;t add new animations. I also can&#8217;t currently blur the screen because that would kill performance and it can get annoying.)</p>
<p><a href="http://beta.metaplace.com/module/BarSystem_2">Module page</a>. Search the marketplace for &#8220;bar system&#8221; or my username, &#8220;vonwolfehaus&#8221;.<br />
Price: 1700 coins.<br />
Configurable options: x and y position that the bar menu appears at when opened</p>
]]></content:encoded>
			<wfw:commentRss>http://coldconstructs.com/2009/05/mp-bar-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MP Timeout chair</title>
		<link>http://coldconstructs.com/2009/05/mp-timeout-chair/</link>
		<comments>http://coldconstructs.com/2009/05/mp-timeout-chair/#comments</comments>
		<pubDate>Sun, 17 May 2009 07:52:50 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Introductions]]></category>
		<category><![CDATA[Metaplace]]></category>
		<category><![CDATA[module]]></category>

		<guid isPermaLink="false">http://coldconstructs.com/?p=106</guid>
		<description><![CDATA[With the opening of Metaplace to the masses, I can finally show off a couple of the projects I&#8217;ve built for the platform.
I&#8217;m not sure why I made this module but I did. If user sit in a piece of furniture with this behavior attached to it, they&#8217;ll be giving a dunce cap with the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://coldconstructs.com/p/metaplace/screenshots/timeoutchair.jpg" class="alignleft bordered">With the opening of <a href="http://www.metaplace.com/">Metaplace</a> to the masses, I can finally show off a couple of the projects I&#8217;ve built for the platform.</p>
<p>I&#8217;m not sure why I made this module but I did. If user sit in a piece of furniture with this behavior attached to it, they&#8217;ll be giving a dunce cap with the word &#8220;FAIL&#8221; on it. They&#8217;ll also be scorned by a message from the world owner. If the user tries to leave the chair before their time is up (time is also configurable) they will be kicked from the world.</p>
<p><a href="http://beta.metaplace.com/module/TimeoutChair">Module page</a>.<br />
Price: 30 coins.<br />
Configurable variables: timeout length, timeout message (title too), x and y position of the hat.</p>
]]></content:encoded>
			<wfw:commentRss>http://coldconstructs.com/2009/05/mp-timeout-chair/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pixel transition</title>
		<link>http://coldconstructs.com/2009/04/pixel-transition/</link>
		<comments>http://coldconstructs.com/2009/04/pixel-transition/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 20:35:18 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://coldconstructs.com/?p=79</guid>
		<description><![CDATA[What I wanted was a fast, seamless way to transition from clickable thumbnail on a zui canvas while dynamically loading the content of whatever the thumbnail represented. I just loved the idea of loading content while zooming into a thumbnail without loading a higher-res image to take its place, then having the pixelated thumbnail disintegrate [...]]]></description>
			<content:encoded><![CDATA[<p>What I wanted was a fast, seamless way to transition from clickable thumbnail on a zui canvas while dynamically loading the content of whatever the thumbnail represented. I just loved the idea of loading content while zooming into a thumbnail without loading a higher-res image to take its place, then having the pixelated thumbnail disintegrate to reveal the actual content that got loaded during the transition. Anyway, it was the best idea that I could come up with for my application, so here we are.</p>
<p><a title="Pixel Transition demo" rel="shadowbox;height=400;width=550" href="http://labs.coldconstructs.com/e/pixelTransition.swf"><img class="centered" src="http://labs.coldconstructs.com/i/pixeltransition.png" alt="Click to view" /></a></p>
<p><span id="more-79"></span></p>
<p>I started by converting the thumbnail to a Vector array of Bitmaps. I planned on using TweenLite to shuffle each bitmapped pixel off the screen, and hoped I could do some fancy stuff with the Bitmaps like scale them for interesting effects. I did this by dumping the uint values of the bitmap into a ByteArray using getPixels(), then creating a new Bitmap for each value in the ByteArray using readUnsighnedInt() in a while loop. Each new Bitmap (representing a pixel of the original image) was added to that Vector array I mentioned:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p79code8'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p798"><td class="code" id="p79code8"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> pixels<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a> = srcBMD<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getPixels</span><span style="color: #000000;">&#40;</span>srcBMD<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rect</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
pixels<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// make sure we start reading from the beginning</span>
<span style="color: #6699cc; font-weight: bold;">var</span> newx<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = src<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> newy<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = src<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>pixels<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesAvailable</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> splodeParticle<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bitmap%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmap.html"><span style="color: #004993;">Bitmap</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=bitmap%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmap.html"><span style="color: #004993;">Bitmap</span></a><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a><span style="color: #000000;">&#40;</span>1<span style="color: #000066; font-weight: bold;">,</span> 1<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> pixels<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readUnsignedInt</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=pixelsnapping%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:pixelsnapping.html"><span style="color: #004993;">PixelSnapping</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ALWAYS</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	splodeParticle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = newx<span style="color: #000066; font-weight: bold;">;</span>
	splodeParticle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = newy<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000066; font-weight: bold;">++</span>newx<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>newx <span style="color: #000066; font-weight: bold;">&gt;</span> src<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span> src<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">++</span>newy<span style="color: #000066; font-weight: bold;">;</span>
		newx = src<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
	container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>splodeParticle<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	pixArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>splodeParticle<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>I&#8217;d then loop through each item in the Vector to tween them off stage, revealing the loaded content below them.</p>
<p>Turns out this was a pretty dumb idea. The performance was extraordinarily sluggish during the while and for loops (naturally) and I wasn&#8217;t able to get a smooth tween because of this. Also, the ByteArray did not recreate the original image correctly &#8212; it came out rather distorted:</p>
<p><img class="centered" src="http://labs.coldconstructs.com/i/pt-err.png" alt="oops" /></p>
<p>I&#8217;m still not sure why, as this is my first time dealing with the ByteArray class, but I figured I&#8217;d cut my losses and try a different approach.</p>
<p>Since I was getting great results with blitting in other experiments, I figured I should try holding a Vector array of Points that represented the pixels I wanted to move around. The actual &#8220;moving&#8221; simply ran setPixel() on a Bitmap for each Point in the array after I ran some translation calculations to get shit moving all nice-like. Points have a lot of extra baggage that I didn&#8217;t want though, so I just used a custom class that simply stored some dimensional variables and called it good.</p>
<p>I based my classes off of Andre Michelle&#8217;s <a href="http://lab.andre-michelle.com/bitmap-particles-2">Bitmap Particle</a> experiment &#8212; he knows more math than I ever will and came up with a fucking brilliant effect there that I can only dream of achieving, so mad props to that bloke.</p>
<p>Anyway, as you can see this worked out pretty damn well. I could spend a whole week on this experiment, playing with the variables (especially the ignite var) to get different transitional effects, as well as adding more filters&#8230; but I&#8217;ll just leave this basic example for you to play with. Just be sure to show me anything particularly cool you come up with!</p>
<p><a title="download source" href="http://labs.coldconstructs.com/src/pixelTransition.rar"><img class="centered" src="http://coldconstructs.com/siteFiles/download_button.png" alt="download source" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://coldconstructs.com/2009/04/pixel-transition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BitmapText class</title>
		<link>http://coldconstructs.com/2009/03/bitmaptext-class/</link>
		<comments>http://coldconstructs.com/2009/03/bitmaptext-class/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 21:32:44 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Introductions]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://coldconstructs.com/?p=65</guid>
		<description><![CDATA[A new section is up on the projects page where I put classes I&#8217;ve written that I think might be useful to others. People seemed to like my post on bitmap text so I released the class I use to do the boring work for me.
Usage:

?View Code ACTIONSCRIPT3// Optional format
var format:TextFormat = new TextFormat&#40;&#41;;
format.font = [...]]]></description>
			<content:encoded><![CDATA[<p>A new section is up on the projects page where I put classes I&#8217;ve written that I think might be useful to others. People seemed to like my post <a href="http://coldconstructs.com/2008/06/scaling-dynamic-text-in-as3/">on bitmap text</a> so I released the class I use to do the boring work for me.</p>
<p>Usage:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p65code10'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p6510"><td class="code" id="p65code10"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// Optional format</span>
<span style="color: #6699cc; font-weight: bold;">var</span> format<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=textformat%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textformat.html"><span style="color: #004993;">TextFormat</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=textformat%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textformat.html"><span style="color: #004993;">TextFormat</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
format<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">font</span> = <span style="color: #990000;">&quot;Verdana&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
format<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">size</span> = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> bmt<span style="color: #000066; font-weight: bold;">:</span>BitmapText = <span style="color: #0033ff; font-weight: bold;">new</span> BitmapText<span style="color: #000000;">&#40;</span>300<span style="color: #000066; font-weight: bold;">,</span> 500<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> format<span style="color: #000066; font-weight: bold;">,</span> 12<span style="color: #000066; font-weight: bold;">,</span> 100<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// only width and height are required</span>
bmt<span style="color: #000066; font-weight: bold;">.</span>addText<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;This is html text, which can't be mixed with regular text.&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// set last param to false for regular text</span>
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>bmt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">render</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>More instructions/explanations are in the class itself.</p>
]]></content:encoded>
			<wfw:commentRss>http://coldconstructs.com/2009/03/bitmaptext-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pixel particle trails</title>
		<link>http://coldconstructs.com/2009/03/pixel-particle-trails/</link>
		<comments>http://coldconstructs.com/2009/03/pixel-particle-trails/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 04:13:46 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://coldconstructs.com/?p=31</guid>
		<description><![CDATA[I&#8217;ve been messing around with particles, particularly the blitted, traily kind I guess. Click on the image below to pop and watch it. Grab the source at the bottom and let me know if you do something cool with it.


The particle trails you see are actually all on one bitmap that I draw to after [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been messing around with particles, particularly the blitted, traily kind I guess. Click on the image below to pop and watch it. Grab the source at the bottom and let me know if you do something cool with it.</p>
<p><a href="http://labs.coldconstructs.com/e/pixelparticletrails.swf" rel="shadowbox;height=500;width=700" title="Pixel Particle Trails demo" /><img src="http://labs.coldconstructs.com/i/pixelparticletrails.png" alt="Click to view" class="centered"/></a></p>
<p><span id="more-31"></span></p>
<p>The particle trails you see are actually all on one bitmap that I draw to after updating each particle in sequence, per frame tick. The particles themselves are a simple class that keeps track of a few variables such as velocity and position. The class doesn&#8217;t extend anything, instead the Main class of the swf draws a line from where the particle was in the previous frame to where it is in the current frame.</p>
<p>To make them fade over time I simply did a colorTransform on the whole bitmap at the begining of the tick method. I didn&#8217;t alter any hues obviously, I just subtracted the alpha value of the bitmap a little. So the longer the pixel has been in the bitmap, the lower it&#8217;s opacity. I wish I can claim that cleverness but I actually got the idea from somewhere else&#8230; probably <a href="http://www.8bitrocket.com/"/>8bitRocket</a>.</p>
<p>This method of graphics manipulation, called blitting, is the way to get a metric fuck-ton more performance out of Flash than is possible with mere Sprites. You can see there&#8217;s 600 &#8220;particles&#8221; in the demo &#8212; had I simply extended the Sprite class and used that to render the scene, I probably would have only been allowed a few hundred sprites while keeping the framerate at around 30.</p>
<p>If you want to see some great examples of blitting, check out 8bitRocket&#8217;s posts on the subject. You can even find a blitting engine called <a href="http://code.google.com/p/pixelblitz/"/>PixelBlitz</a> &#8212; check out <a href="http://www.photonstorm.com/archives/264/pixelblitz-first-2009-update-lots-of-new-toys-and-shmup-test-1"/>this badass schmup demo</a> of his!</p>
<p><a href="http://labs.coldconstructs.com/src/pixelparticletrails.rar" title="download source" /><img src="http://coldconstructs.com/siteFiles/download_button.png" alt="download source" class="centered"/></a></p>
]]></content:encoded>
			<wfw:commentRss>http://coldconstructs.com/2009/03/pixel-particle-trails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Status update</title>
		<link>http://coldconstructs.com/2008/09/status-update/</link>
		<comments>http://coldconstructs.com/2008/09/status-update/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 19:27:12 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Housekeeping]]></category>
		<category><![CDATA[Cold Constructs]]></category>
		<category><![CDATA[status update]]></category>

		<guid isPermaLink="false">http://coldconstructs.com/?p=30</guid>
		<description><![CDATA[It&#8217;s been a while since my last update unfortunately. I&#8217;m planning on updating the site at least once a month with new projects and experiments but sometimes that&#8217;s just not possible.
This time it&#8217;s because I&#8217;m an alpha tester for Metaplace, and I&#8217;ve been putting most of my free time into that. Check out the site, [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since my last update unfortunately. I&#8217;m planning on updating the site at least once a month with new projects and experiments but sometimes that&#8217;s just not possible.</p>
<p>This time it&#8217;s because I&#8217;m an alpha tester for <a href="http://metaplace.com/">Metaplace</a>, and I&#8217;ve been putting most of my free time into that. Check out the site, post in the forums (maybe you&#8217;ll get selected for the upcoming beta) &#8212; it&#8217;s an excellent project with a ton of potential.</p>
<p>But I&#8217;ve also been working on a new AS3 experiment that implements a blitting engine for sprite rendering. This allows me to display over 1000 sprites on-screen at once, as opposed to the 300-400 that&#8217;s possible with no special code. I&#8217;ll be implementing this in my upcoming Flash game. Maybe.</p>
]]></content:encoded>
			<wfw:commentRss>http://coldconstructs.com/2008/09/status-update/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Scaling dynamic text in AS3</title>
		<link>http://coldconstructs.com/2008/06/scaling-dynamic-text-in-as3/</link>
		<comments>http://coldconstructs.com/2008/06/scaling-dynamic-text-in-as3/#comments</comments>
		<pubDate>Tue, 24 Jun 2008 22:27:56 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Experiments]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://coldconstructs.com/?p=29</guid>
		<description><![CDATA[Recently I&#8217;ve had the need to scale a dynamic text field which was fed by XML. Readability after scaling was not important, but it did have to look good (it&#8217;s for a full Flash site). However, scaling the MovieClip that the text field was in would cause some pretty chaotic behavior with the text &#8212; [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve had the need to scale a dynamic text field which was fed by XML. Readability after scaling was not important, but it did have to look good (it&#8217;s for a full Flash site). However, scaling the MovieClip that the text field was in would cause some pretty chaotic behavior with the text &#8212; the text would try to scale with its parent but in doing so would shift around spastically until the parent MC settled into a new scale. This was unacceptable.</p>
<p><a href="http://labs.coldconstructs.com/e/bitmapText.swf" rel="shadowbox;height=400;width=550" title="Scaling dynamic text" /><img src="http://labs.coldconstructs.com/i/bitmapText.png" alt="Click to view" class="centered" /></a></p>
<p>A quick google didn&#8217;t yield anything relevant, so I was left to my own devices. I remembered being able to draw pixels to a BitmapData object while writing my game in order to improve performance, so I figured I&#8217;d see if I could just copy the pixels from the text field and &#8220;bake&#8221; it into a bitmap.</p>
<p>Turns out you can. In fact, Adobe had already done this in the help files and it&#8217;s actually extremely easy. Check it out:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p29code12'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2912"><td class="code" id="p29code12"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> tf<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=textfield%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfield.html"><span style="color: #004993;">TextField</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=textfield%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfield.html"><span style="color: #004993;">TextField</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;bitmap text&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> myBitmapData<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a><span style="color: #000000;">&#40;</span>80<span style="color: #000066; font-weight: bold;">,</span> 20<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
myBitmapData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span>tf<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> bmp<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bitmap%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmap.html"><span style="color: #004993;">Bitmap</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=bitmap%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmap.html"><span style="color: #004993;">Bitmap</span></a><span style="color: #000000;">&#40;</span>myBitmapData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>bmp<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>No sweat right? Anyway, since I didn&#8217;t find any help on this anywhere else (granted, I didn&#8217;t look very hard), I thought I&#8217;d share this little adventure of mine. Hope it&#8217;s helpful.</p>
<p><a href="http://labs.coldconstructs.com/src/bitmapText.fla" title="download source" /><img src="http://coldconstructs.com/siteFiles/download_button.png" alt="download source" class="centered"/></a></p>
]]></content:encoded>
			<wfw:commentRss>http://coldconstructs.com/2008/06/scaling-dynamic-text-in-as3/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
