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

<channel>
	<title>Phil Peron &#187; actionscript</title>
	<atom:link href="http://philperon.com/tag/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://philperon.com</link>
	<description>Flash Platform Developer and Game Development Hobbyist</description>
	<lastBuildDate>Wed, 23 Jun 2010 15:30:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Polygon Collision and the Separating Axis Theorem in ActionScript</title>
		<link>http://philperon.com/2010/06/23/polygon-collision/</link>
		<comments>http://philperon.com/2010/06/23/polygon-collision/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 15:30:53 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[gamedev]]></category>

		<guid isPermaLink="false">http://philperon.com/?p=667</guid>
		<description><![CDATA[I&#8217;ve been spending quite a bit of time on my latest game project which, like many other games, requires collision detection. Knowing that using brute force for broad-phase detection wasn&#8217;t an option, I implemented a spatial hash to partition the world&#8217;s game objects into manageable groups. At this point, I was ready to tackle the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been spending quite a bit of time on my latest game project which, like many other games, requires collision detection. Knowing that using brute force for broad-phase detection wasn&#8217;t an option, I implemented a spatial hash to partition the world&#8217;s game objects into manageable groups. At this point, I was ready to tackle the narrow-phase portion and immediately sought to use a form of pixel-perfect collision I&#8217;ve grown to understand and use fairly well. Unfortunately, this type of detection is inappropriate for a lot of things and an avatar moving along a tile-based set is one of them. It can be fairly costly and is better suited for boolean-based tests. After trying to force this algorithm to do something it shouldn&#8217;t, I finally settled down and visited a form of collision I had known about for a while but had not the need to implement&#8230;until now.<br />
<span id="more-667"></span><br />
I&#8217;m not going to explain how the <a href="http://en.wikipedia.org/wiki/Separating_axis_theorem">Separating Axis Theorem (SAT)</a> works. There are <a href="http://www.google.com/search?sourceid=chrome&#038;ie=UTF-8&#038;q=Separating+Axis+Theorem">plenty of resources available</a> for that. Instead, I&#8217;m simply going to share with you the code that drives it and how you can use it in your own game.</p>
<p>Before we dive in, there&#8217;s something you should be aware of:</p>
<p><em>This code exists because it&#8217;s easier for me to prototype new things in ActionScript. That being said, there are certainly opportunities to improve performance and structure but I&#8217;m not interested in doing that here. I&#8217;ll address those issues and share the result when I port it over to my target platform in C#.</em></p>
<p>I&#8217;ve taken time to try and make things as easy as possible to use. I&#8217;m assuming you&#8217;re reading this because you need to leverage this functionality and want things to &#8220;just work&#8221;.</p>
<p>Here it is:</p>
<pre class="brush: jscript;">
// create a vector of points that express the first polygon.
var points1:Vector.&lt;Point&gt; = new Vector.&lt;Point&gt;();
points1.push(new Point(0, 0));
points1.push(new Point(50, 0));
points1.push(new Point(50, 50));
points1.push(new Point(0, 50));

// create the first polygon, adjust it's registration point and move it.
var polygon1:Polygon = new Polygon(points);
polygon1.offset = new Vector2D(polygon1.center.x, polygon1.center.y);
polygon1.translate(new Vector2D(50, 50));

// create a vector of points that express the second polygon.
var points2:Vector.&lt;Point&gt; = new Vector.&lt;Point&gt;();
points2.push(new Point(0, 0));
points2.push(new Point(100, 0));
points2.push(new Point(100, 100));
points2.push(new Point(0, 100));

// create the second polygon, adjust it's registration point and move it.
var polygon2:Polygon = new Polygon(points);
polygon2.offset = new Vector2D(polygon2.center.x, polygon2.center.y);
polygon2.translate(new Vector2D(200, 200));
</pre>
<p>At this point, there are two polygons ready to shake, rattle or roll. When you&#8217;d like to see whether or not they&#8217;re colliding, use the following:</p>
<pre class="brush: jscript;">
// define a container to hold a translation vector that can be altered by the collision.
var collisionResponseTranslation:Vector2D = new Vector2D();

// finally, discover whether or not a collision has occurred.
if(polygon1.isCollidingWith(polygon2, collisionResponseTranslation))
    polygon1.translate(collisionResponseTranslation);
</pre>
<p>That&#8217;s it! Here&#8217;s a demo that illustrates things a little better:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_PolygonCollisionDemo_1842692320"
			class="flashmovie"
			width="400"
			height="300">
	<param name="movie" value="/flash/PolygonCollisionDemo.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/flash/PolygonCollisionDemo.swf"
			name="fm_PolygonCollisionDemo_1842692320"
			width="400"
			height="300">
	<!--<![endif]-->
		<a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Please keep in mind that <strong>this will only work for convex polygons</strong>. My game doesn&#8217;t merit getting as complex as the folks at <a href="http://www.metanetsoftware.com/technique/tutorialA.html">Metanet</a> did with <a href="http://www.thewayoftheninja.org/n.html">N</a> so until it that time, it&#8217;s pretty much complete.</p>
<p>You&#8217;ll find the demo and library source, <a href="http://philperon.com/files/PolygonCollisionDemo.zip">here</a>.</p>
<p>Good luck and happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://philperon.com/2010/06/23/polygon-collision/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Vim Omnicompletion for ActionScript 3</title>
		<link>http://philperon.com/2008/12/10/vim-omnicompletion-for-actionscript-3/</link>
		<comments>http://philperon.com/2008/12/10/vim-omnicompletion-for-actionscript-3/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 15:46:06 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[actionscript]]></category>

		<guid isPermaLink="false">http://philperon.com/?p=20</guid>
		<description><![CDATA[Shortly before we received Flex IDE licenses at work, I was in the process of writing an ActionScript 3 omnicompletion plug-in for vim. The &#8216;flash&#8217; package is covered for the most part while &#8216;mx&#8217;, &#8216;flashx&#8217; and &#8216;air&#8217; are still lacking.
Anyway, it&#8217;s not serving the community sitting around my hard drive so I went ahead and [...]]]></description>
			<content:encoded><![CDATA[<p>Shortly before we received Flex IDE licenses at work, I was in the process of writing an ActionScript 3 omnicompletion plug-in for vim. The &#8216;flash&#8217; package is covered for the most part while &#8216;mx&#8217;, &#8216;flashx&#8217; and &#8216;air&#8217; are still lacking.</p>
<p>Anyway, it&#8217;s not serving the community sitting around my hard drive so I went ahead and pushed it up to the vim script repository.</p>
<p><a href="http://www.vim.org/scripts/script.php?script_id=2478">http://www.vim.org/scripts/script.php?script_id=2478 </a></p>
<p>Hopefully, it will make someone happy.</p>
]]></content:encoded>
			<wfw:commentRss>http://philperon.com/2008/12/10/vim-omnicompletion-for-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>State Machines in ActionScript</title>
		<link>http://philperon.com/2008/12/03/state-machines-in-actionscript/</link>
		<comments>http://philperon.com/2008/12/03/state-machines-in-actionscript/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 12:53:18 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[gamedev]]></category>

		<guid isPermaLink="false">http://philperon.com/?p=18</guid>
		<description><![CDATA[I love simple solutions to complex things. Squize&#8217;s post over at Gaming Your Way on State Machines in ActionScript explains an issue game developers often face that is elegantly handled with function pointers.
It&#8217;s been months since my last post (and coincidentally changing jobs) but I&#8217;d recently dusted off a grid-less rendering engine for 2d games [...]]]></description>
			<content:encoded><![CDATA[<p>I love simple solutions to complex things. Squize&#8217;s post over at <a href="http://blog.gamingyourway.com" title="Gaming Your Way">Gaming Your Way</a> on <a href="http://blog.gamingyourway.com/PermaLink,guid,8c079942-1647-4393-a7fc-fab8d014e24b.aspx" title="State Machines in ActionScript">State Machines in ActionScript</a> explains an issue game developers often face that is elegantly handled with function pointers.</p>
<p>It&#8217;s been months since my last post (and coincidentally changing jobs) but I&#8217;d recently dusted off a grid-less rendering engine for 2d games and was slightly disgusted with it core. It&#8217;s really not <em>that</em> bad. It works but the main loop gets a wee-bit lengthy and burns up cycles evaluating items that could possible be out of context at any given moment.</p>
<p>Using function pointers to create a state machine wraps this up nicely. Cheers, Squize!</p>
]]></content:encoded>
			<wfw:commentRss>http://philperon.com/2008/12/03/state-machines-in-actionscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Components: MXML vs. ActionScript</title>
		<link>http://philperon.com/2008/06/16/flex-components-mxml-vs-actionscript/</link>
		<comments>http://philperon.com/2008/06/16/flex-components-mxml-vs-actionscript/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 21:38:48 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://philperon.com/?p=16</guid>
		<description><![CDATA[One question that has constantly nagged me during my conversion from Flash to Flex development is, &#8220;Do I write this thingamajig in MXML or ActionScript?&#8221; The question is usually answered by the type of component that&#8217;s being written. If it&#8217;s a visual component, I&#8217;ll write MXML otherwise, I&#8217;ll write the whole thing in ActionScript.
 This [...]]]></description>
			<content:encoded><![CDATA[<p>One question that has constantly nagged me during my conversion from Flash to Flex development is, &#8220;Do I write this thingamajig in MXML or ActionScript?&#8221; The question is usually answered by the type of component that&#8217;s being written. If it&#8217;s a visual component, I&#8217;ll write MXML otherwise, I&#8217;ll write the whole thing in ActionScript.</p>
<p><span id="more-16"></span> This kind of reasoning was satisfying in the beginning but as I gain more experience with component development in Flex, I&#8217;m finding that it may not be as clear cut as I once thought. In fact, it wasn&#8217;t until I glanced at <a href="http://www.adobe.com/devnet/flex/quickstart/building_components_using_code_behind/" title="Building components by using code behind">this article </a>on Adobe&#8217;s <a href="http://www.adobe.com/devnet/" title="Adobe Developer Connection">Developer Connection site</a> that I&#8217;ve since refined my decision-making process.</p>
<p>Here are the two points mentioned in the article:</p>
<ul>
<li>When you create composite controls declaratively, MXML makes it easier to create and lay out child controls.</li>
<li>When you modify the behavior of components, that is, override their methods, you typically use ActionScript.</li>
</ul>
<p>As simple and obvious as they may sound, they&#8217;re quite powerful when trying to decide in which direction to take your development. As stated in the article, most of the time you&#8217;ll be using a combination of the two. One way to do that is by using a technique called &#8220;code behind&#8221; which is something I&#8217;m working on right now&#8230;</p>
<p>UPDATE: After playing with the code behind technique mentioned in the article it seems obvious to me that it&#8217;s the way to go in most cases. It&#8217;s also very satisfying to separate form from function in a sensible manner.  Unless, you&#8217;re developing a very simple component you should probably get in the habit of writing core logic (as a class) in ActionScript and extending it via the root tag in MXML.</p>
]]></content:encoded>
			<wfw:commentRss>http://philperon.com/2008/06/16/flex-components-mxml-vs-actionscript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>C/C++ to ActionScript Cross-Compiler</title>
		<link>http://philperon.com/2008/02/26/cc-to-actionscript-cross-compiler/</link>
		<comments>http://philperon.com/2008/02/26/cc-to-actionscript-cross-compiler/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 01:17:55 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[air]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[actionscript]]></category>

		<guid isPermaLink="false">http://philperon.com/?p=14</guid>
		<description><![CDATA[Last year, at MAX 2007 Scott Peterson showed everyone a demo of various C apps running in the Flash Player. It was pretty radical stuff. I recall seeing the demo and feeling absolutely speechless.
Well, I totally forgot about this (too good to be true?) until today, when Ted Patrick announced that indeed, development is still [...]]]></description>
			<content:encoded><![CDATA[<p>Last year, at <a href="http://www.adobemax2007.com/">MAX 2007</a> Scott Peterson <a href="http://youtube.com/watch?v=0hX-Uh3oTcE&#038;feature=related">showed everyone a demo</a> of various C apps running in the Flash Player. It was pretty radical stuff. I recall seeing the demo and feeling absolutely speechless.</p>
<p>Well, I totally forgot about this (too good to be true?) until today, when <a href="http://www.onflex.org/">Ted Patrick</a> <a href="http://www.onflex.org/ted/2008/02/extending-adobe-flash-player-and-adobe.php">announced</a> that indeed, development is still moving forward in this area.</p>
<p>I&#8217;ve been chewing on the thought of creating P2P clients in AIR but couldn&#8217;t figure out an <em>elegant</em> approach to packaging a client module (written in ActionScript) and a server module (written in C/C++, Java or Python) in a single AIR installer&#8230; </p>
<p>Could this be it?</p>
]]></content:encoded>
			<wfw:commentRss>http://philperon.com/2008/02/26/cc-to-actionscript-cross-compiler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActionScript 3 SGS Client Template</title>
		<link>http://philperon.com/2008/02/15/actionscript-3-sgs-client-template/</link>
		<comments>http://philperon.com/2008/02/15/actionscript-3-sgs-client-template/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 20:20:02 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[gamedev]]></category>

		<guid isPermaLink="false">http://philperon.com/?p=12</guid>
		<description><![CDATA[I&#8217;ve been playing with SGS lately and must admit, I freaking love it.
It&#8217;s free, GPL&#8217;d, has excellent documentation and just plain works. On top of all that, there&#8217;s even a full-fledged ActionScript 3 Client API available!
While working through the tutorials I found myself writing more than one flash client and decided I&#8217;d be better off [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing with <a href="http://www.projectdarkstar.com/">SGS</a> lately and must admit, I freaking love it.</p>
<p>It&#8217;s free, GPL&#8217;d, has excellent documentation and just plain works. On top of all that, there&#8217;s even a full-fledged <a href="https://darkstar-as-client.dev.java.net/">ActionScript 3 Client API</a> available!</p>
<p>While working through the tutorials I found myself writing more than one flash client and decided I&#8217;d be better off distilling them down to a single template. I think it&#8217;s a decent starting point for those &#8220;Hello World&#8221; demos and could potentially become the base for a full-blown, multi-user client application.</p>
<p>You can download the files, <a href="/files/as3_sgs_client_template.zip">here</a>.</p>
<p><em>Please let me know if you&#8217;re working on a Flash client for an SGS application. I&#8217;d love to hear about it!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://philperon.com/2008/02/15/actionscript-3-sgs-client-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bitmap Collison Detection with ActionScript 3</title>
		<link>http://philperon.com/2007/09/07/bitmap-collison-detection-with-actionscript-3/</link>
		<comments>http://philperon.com/2007/09/07/bitmap-collison-detection-with-actionscript-3/#comments</comments>
		<pubDate>Fri, 07 Sep 2007 22:53:01 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[gamedev]]></category>

		<guid isPermaLink="false">http://philperon.com/?p=7</guid>
		<description><![CDATA[I finally got around to converting Grant Skinner&#8217;s collision detection algorithm to ActionScript 3. This version primarily takes advantage of the latest library class/method additions.
For anyone familiar with Grant&#8217;s implementation, you&#8217;ll notice the method signature is similar.
To determine whether or not the bitmap data values of two display objects are &#8220;colliding&#8221;, you simply call:
var x:Rectangle [...]]]></description>
			<content:encoded><![CDATA[<p>I finally got around to converting <a href="http://www.gskinner.com/blog/archives/2005/08/flash_8_shape_b.html">Grant Skinner&#8217;s collision detection algorithm</a> to ActionScript 3. This version primarily takes advantage of the latest library class/method additions.</p>
<p>For anyone familiar with Grant&#8217;s implementation, you&#8217;ll notice the method signature is similar.</p>
<p>To determine whether or not the bitmap data values of two display objects are &#8220;colliding&#8221;, you simply call:</p>
<p><code>var x:Rectangle = Collision.collisionTest(myObj, yourObj);</code></p>
<p>Alternatively, you may also pass a third argument representing the alpha tolerance which in turn gets passed to the alphaTolerance argument of the ColorTransform constructor.</p>
<p><code>var x:Rectangle = Collision.collisionTest(myObj, yourObj, alphaTol);</code></p>
<p>You can see an example, <a href="http://www.philperon.com/files/bitmapCollision/BitmapCollisionDetection.swf">here</a> or download the Class definition, <a href="http://www.philperon.com/files/bitmapCollision/Collision.as">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://philperon.com/2007/09/07/bitmap-collison-detection-with-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
