<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Relative performance for collision detection techniques in ActionScript 3</title>
	<atom:link href="http://www.mikechambers.com/blog/2009/06/26/relative-performance-for-collision-detection-techniques-in-actionscript-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikechambers.com/blog/2009/06/26/relative-performance-for-collision-detection-techniques-in-actionscript-3/</link>
	<description>code = joy</description>
	<lastBuildDate>Fri, 02 Dec 2011 01:36:37 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>By: Sarah</title>
		<link>http://www.mikechambers.com/blog/2009/06/26/relative-performance-for-collision-detection-techniques-in-actionscript-3/comment-page-1/#comment-26897</link>
		<dc:creator>Sarah</dc:creator>
		<pubDate>Thu, 14 Jul 2011 22:08:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=1758#comment-26897</guid>
		<description>Your Rectangle.intersects() test isn&#039;t fair.  It&#039;s definitely getBounds() that&#039;s slowing down the test.  In all my tests, even with early bail out, Rectangle.intersects() blows away manual comparisons of the same rectangles (possibly due to the property nature of things like .left, .top, .right, etc.).</description>
		<content:encoded><![CDATA[<p>Your Rectangle.intersects() test isn&#8217;t fair.  It&#8217;s definitely getBounds() that&#8217;s slowing down the test.  In all my tests, even with early bail out, Rectangle.intersects() blows away manual comparisons of the same rectangles (possibly due to the property nature of things like .left, .top, .right, etc.).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Corey von Birnbaum</title>
		<link>http://www.mikechambers.com/blog/2009/06/26/relative-performance-for-collision-detection-techniques-in-actionscript-3/comment-page-1/#comment-24821</link>
		<dc:creator>Corey von Birnbaum</dc:creator>
		<pubDate>Tue, 14 Dec 2010 03:03:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=1758#comment-24821</guid>
		<description>I know this post is super-old, but it&#039;s still relevant-ish (Flash Player keeps changing things). So I just wanted to mention an optimization that will turn all those numbers around:

var irect:Rectangle = rect.intersection(rect2);
Then use irect for the clipRect property of draw(), after some coordinate compensation (and after irect is found to be larger than 1x1). This will make Flash draw ONLY the portion of the clips we&#039;re concerned with, drastically reducing draw time, in most cases (especially when testing big clips against small clips).

Besides calling &quot;new&quot;, draw() has the biggest impact on performance (sometimes more-so, depending on the size of the clip to draw), which is why the gain is so large.</description>
		<content:encoded><![CDATA[<p>I know this post is super-old, but it&#8217;s still relevant-ish (Flash Player keeps changing things). So I just wanted to mention an optimization that will turn all those numbers around:</p>
<p>var irect:Rectangle = rect.intersection(rect2);<br />
Then use irect for the clipRect property of draw(), after some coordinate compensation (and after irect is found to be larger than 1&#215;1). This will make Flash draw ONLY the portion of the clips we&#8217;re concerned with, drastically reducing draw time, in most cases (especially when testing big clips against small clips).</p>
<p>Besides calling &#8220;new&#8221;, draw() has the biggest impact on performance (sometimes more-so, depending on the size of the clip to draw), which is why the gain is so large.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mike chambers</title>
		<link>http://www.mikechambers.com/blog/2009/06/26/relative-performance-for-collision-detection-techniques-in-actionscript-3/comment-page-1/#comment-17507</link>
		<dc:creator>mike chambers</dc:creator>
		<pubDate>Sat, 07 Nov 2009 05:56:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=1758#comment-17507</guid>
		<description>fyi, I have been playing around with this and if you optimize the circle test, you can get performance approaching the built in hitTest:
&lt;pre&gt;
private function i_hitTestCircle2(clip1:Sprite, clip2:Sprite):Boolean
{			
	var dx:Number = clip2.x - clip1.x;
	var dy:Number = clip2.y  - clip1.y ;

	var radii:Number = ((clip1.width * .5) + (clip2.width * .5));
	return ((dx * dx) + (dy * dy) &lt; radii * radii);
}
&lt;/pre &gt;

&lt;p&gt;&#160;&lt;/p&gt;
Here are the results:

&lt;pre&gt;
hitTest (50000 iterations)                                              
Player version: MAC 10,1,51,28 (regular)
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
hitTest                                                      54     0.00
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
hitTestCircle (50000 iterations)                                        
Player version: MAC 10,1,51,28 (regular)
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
hitTestCircle                                               133     0.00
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
hitTestCircle2 (50000 iterations)                                       
Player version: MAC 10,1,51,28 (regular)
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
hitTestCircle2                                               56     0.00
–––––––––––––––––––––––––––––––––––––––––––––––
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>fyi, I have been playing around with this and if you optimize the circle test, you can get performance approaching the built in hitTest:</p>
<pre>
private function i_hitTestCircle2(clip1:Sprite, clip2:Sprite):Boolean
{
	var dx:Number = clip2.x - clip1.x;
	var dy:Number = clip2.y  - clip1.y ;

	var radii:Number = ((clip1.width * .5) + (clip2.width * .5));
	return ((dx * dx) + (dy * dy) < radii * radii);
}
</pre >

&nbsp;

Here are the results:
</pre>
<pre>
hitTest (50000 iterations)
Player version: MAC 10,1,51,28 (regular)
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
hitTest                                                      54     0.00
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
hitTestCircle (50000 iterations)
Player version: MAC 10,1,51,28 (regular)
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
hitTestCircle                                               133     0.00
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
hitTestCircle2 (50000 iterations)
Player version: MAC 10,1,51,28 (regular)
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
hitTestCircle2                                               56     0.00
–––––––––––––––––––––––––––––––––––––––––––––––
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Garney</title>
		<link>http://www.mikechambers.com/blog/2009/06/26/relative-performance-for-collision-detection-techniques-in-actionscript-3/comment-page-1/#comment-16496</link>
		<dc:creator>Ben Garney</dc:creator>
		<pubDate>Mon, 06 Jul 2009 16:59:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=1758#comment-16496</guid>
		<description>@Matt Bolt:

Sure, Box2D actually does the right thing w.r.t collision (and PushButton is integrated with it out of box). Even if you don&#039;t care about the physical response part, the algorithms that Box2D uses to _detect_ collisions are smart and would get you the performance improvement I described.

Before we go 1.0 we are going to do a major code style update to match Flex style (http://code.google.com/p/pushbuttonengine/issues/detail?id=56) as well as reorganize the codebase to make it easier to work with... Our bad. :)</description>
		<content:encoded><![CDATA[<p>@Matt Bolt:</p>
<p>Sure, Box2D actually does the right thing w.r.t collision (and PushButton is integrated with it out of box). Even if you don&#8217;t care about the physical response part, the algorithms that Box2D uses to _detect_ collisions are smart and would get you the performance improvement I described.</p>
<p>Before we go 1.0 we are going to do a major code style update to match Flex style (<a href="http://code.google.com/p/pushbuttonengine/issues/detail?id=56" rel="nofollow">http://code.google.com/p/pushbuttonengine/issues/detail?id=56</a>) as well as reorganize the codebase to make it easier to work with&#8230; Our bad. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mikechambers</title>
		<link>http://www.mikechambers.com/blog/2009/06/26/relative-performance-for-collision-detection-techniques-in-actionscript-3/comment-page-1/#comment-16495</link>
		<dc:creator>mikechambers</dc:creator>
		<pubDate>Mon, 06 Jul 2009 15:54:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=1758#comment-16495</guid>
		<description>@tonypa

That is a good point. Here is the result with clips that are about 3 times larger:

&lt;pre&gt;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
checkBitmapDataHitInternal (10000 iterations)
Uses BitmapData.hitTest to check for collision. BitmapData not cached.  
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
[function]                                                 8087     0.81
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
checkBitmapDataHitDynamic (10000 iterations)
Uses BitmapData.hitTest to check for collision. BitmapData not cached. M
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
[function]                                                 1848     0.18
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––&lt;/pre&gt;

Note, that is with cacheAsBitmap set to true.

mike chambers

mesh@adobe.com</description>
		<content:encoded><![CDATA[<p>@tonypa</p>
<p>That is a good point. Here is the result with clips that are about 3 times larger:</p>
<pre>––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
checkBitmapDataHitInternal (10000 iterations)
Uses BitmapData.hitTest to check for collision. BitmapData not cached.
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
[function]                                                 8087     0.81
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
checkBitmapDataHitDynamic (10000 iterations)
Uses BitmapData.hitTest to check for collision. BitmapData not cached. M
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
[function]                                                 1848     0.18
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––</pre>
<p>Note, that is with cacheAsBitmap set to true.</p>
<p>mike chambers</p>
<p><a href="mailto:mesh@adobe.com">mesh@adobe.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mikechambers</title>
		<link>http://www.mikechambers.com/blog/2009/06/26/relative-performance-for-collision-detection-techniques-in-actionscript-3/comment-page-1/#comment-16494</link>
		<dc:creator>mikechambers</dc:creator>
		<pubDate>Mon, 06 Jul 2009 15:43:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=1758#comment-16494</guid>
		<description>@Renaun

You are exactly correct. Setting cacheAsBitmap = true on the author time clips brings the performance to the same level as the dynamic clips.

Here is the relevant section:

&lt;pre&gt;––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
checkBitmapDataHitDynamic (10000 iterations)
Uses BitmapData.hitTest to check for collision. BitmapData not cached. M
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
[function]                                                 1844     0.18
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
checkBitmapDataHitInternal - cacheAsBitmap (10000 iterations)
Uses BitmapData.hitTest to check for collision. BitmapData not cached.  
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
[function]                                                 1805     0.18
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––&lt;/pre&gt;

Ill update the post to reflect this. Good catch.

mike chambers

mesh@adobe.com</description>
		<content:encoded><![CDATA[<p>@Renaun</p>
<p>You are exactly correct. Setting cacheAsBitmap = true on the author time clips brings the performance to the same level as the dynamic clips.</p>
<p>Here is the relevant section:</p>
<pre>––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
checkBitmapDataHitDynamic (10000 iterations)
Uses BitmapData.hitTest to check for collision. BitmapData not cached. M
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
[function]                                                 1844     0.18
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
checkBitmapDataHitInternal - cacheAsBitmap (10000 iterations)
Uses BitmapData.hitTest to check for collision. BitmapData not cached.
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
[function]                                                 1805     0.18
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––</pre>
<p>Ill update the post to reflect this. Good catch.</p>
<p>mike chambers</p>
<p><a href="mailto:mesh@adobe.com">mesh@adobe.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Renaun Erickson</title>
		<link>http://www.mikechambers.com/blog/2009/06/26/relative-performance-for-collision-detection-techniques-in-actionscript-3/comment-page-1/#comment-16485</link>
		<dc:creator>Renaun Erickson</dc:creator>
		<pubDate>Thu, 02 Jul 2009 14:20:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=1758#comment-16485</guid>
		<description>About your conclusion #4 (MovieClip at author time vs runtime).  I think the issue is the use of cacheAsBitmap = true on the runtime objects.  If you set the same property in author time (Properties -&gt; Display -&gt; check &quot;Cache as bitmap&quot;) then it has the similar performance.</description>
		<content:encoded><![CDATA[<p>About your conclusion #4 (MovieClip at author time vs runtime).  I think the issue is the use of cacheAsBitmap = true on the runtime objects.  If you set the same property in author time (Properties -&gt; Display -&gt; check &#8220;Cache as bitmap&#8221;) then it has the similar performance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tonypa</title>
		<link>http://www.mikechambers.com/blog/2009/06/26/relative-performance-for-collision-detection-techniques-in-actionscript-3/comment-page-1/#comment-16470</link>
		<dc:creator>tonypa</dc:creator>
		<pubDate>Mon, 29 Jun 2009 07:26:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=1758#comment-16470</guid>
		<description>I also tested checkGetColorBoundsRect method, it does not perform too well compared to BitmapData.hitTest (2x slower on 20px objects, ~20-25 times slower on 100 px objects).</description>
		<content:encoded><![CDATA[<p>I also tested checkGetColorBoundsRect method, it does not perform too well compared to BitmapData.hitTest (2x slower on 20px objects, ~20-25 times slower on 100 px objects).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tonypa</title>
		<link>http://www.mikechambers.com/blog/2009/06/26/relative-performance-for-collision-detection-techniques-in-actionscript-3/comment-page-1/#comment-16469</link>
		<dc:creator>tonypa</dc:creator>
		<pubDate>Mon, 29 Jun 2009 06:55:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=1758#comment-16469</guid>
		<description>Quote: &quot;If you can cache the BitmapData being compared, then BitmapData.hitTest performance is on par with the other techniques / APIs tested.&quot;

Thats not completely true because speed of BitmapData.hitTest is largely depending on the size of objects. For objects with size of only couple of pixels, its lightning-fast. But try objects of hundreds or thousands of pixels and it gets so slow that it cant even finish this test.

Other collision techniques, like math-based or checking bounds, are not affected by the size.

So you cant just compare these results directly.</description>
		<content:encoded><![CDATA[<p>Quote: &#8220;If you can cache the BitmapData being compared, then BitmapData.hitTest performance is on par with the other techniques / APIs tested.&#8221;</p>
<p>Thats not completely true because speed of BitmapData.hitTest is largely depending on the size of objects. For objects with size of only couple of pixels, its lightning-fast. But try objects of hundreds or thousands of pixels and it gets so slow that it cant even finish this test.</p>
<p>Other collision techniques, like math-based or checking bounds, are not affected by the size.</p>
<p>So you cant just compare these results directly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mikechambers</title>
		<link>http://www.mikechambers.com/blog/2009/06/26/relative-performance-for-collision-detection-techniques-in-actionscript-3/comment-page-1/#comment-16462</link>
		<dc:creator>mikechambers</dc:creator>
		<pubDate>Sat, 27 Jun 2009 23:17:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=1758#comment-16462</guid>
		<description>@SP

Feel free to rewrite the circle collision and Ill add it to the test.

Thanks...

mike chambers

mesh@adobe.com</description>
		<content:encoded><![CDATA[<p>@SP</p>
<p>Feel free to rewrite the circle collision and Ill add it to the test.</p>
<p>Thanks&#8230;</p>
<p>mike chambers</p>
<p><a href="mailto:mesh@adobe.com">mesh@adobe.com</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

