<?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>Everyday 3D &#187; 2D Animation</title>
	<atom:link href="http://www.everyday3d.com/blog/index.php/category/animation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.everyday3d.com/blog</link>
	<description>3D user experience on the web. Design, technology news. A blog by Bartek Drozdz.</description>
	<lastBuildDate>Thu, 02 Sep 2010 19:36:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Rotating a Sprite around any point</title>
		<link>http://www.everyday3d.com/blog/index.php/2008/05/28/rotating-a-sprite-around-any-point/</link>
		<comments>http://www.everyday3d.com/blog/index.php/2008/05/28/rotating-a-sprite-around-any-point/#comments</comments>
		<pubDate>Wed, 28 May 2008 20:47:30 +0000</pubDate>
		<dc:creator>bartek drozdz</dc:creator>
				<category><![CDATA[2D Animation]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.everydayflash.com/blog/?p=27</guid>
		<description><![CDATA[Click once to activate, then click anywhere to move the registration point. Use SPACE to change the object or any other key to change the direction of the rotation. This time I want to share a simple solution to a relatively simple, but annoying problem. The problem: the Sprite.rotation property rotates the object always around [...]]]></description>
			<content:encoded><![CDATA[<p><iframe marginwidth="0" marginheight="0" src="http://www.everydayflash.com/flash/rotator" frameborder="0" width="520" height="200"></iframe></p>
<p><span style="font-size:10px;line-height:12px">Click once to activate, then click anywhere to move the registration point. Use SPACE to change the object or any other key to change the direction of the rotation.</span></p>
<p>This time I want to share a simple solution to a relatively simple, but annoying problem.</p>
<p><u><em>The problem:</em></u> the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html#rotation" target="_blank">Sprite.rotation</a> property rotates the object always around the <strong>registration point</strong> of the Sprite. If you need to rotate it around some other point, it's not automatic. </p>
<p>One way to achieve this is to move the content inside the Sprite in order to change its position in relation to the registration point. It works, but it's not elegant and not very handy if the Sprite has many children - you would need to move all of them.</p>
<p>Another way is to wrap your Sprite into another Sprite and rotate the parent. This solution is a bit better, but still has lots of shortcomings. And what about if you need to change the registration point of the object during rotation?</p>
<p><u><em>Solution:</em></u> the <strong>Rotator</strong> class can be used as a replacement for the default <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html#rotation" target="_blank">Sprite.rotation</a> property. This class uses a combination of trigonometric functions to rotate an object around a point along with the rotation property itself to create a correct circular movement. It allows you to have a proper rotation no matter if the point is placed inside the rotated object or outside of it. And, what's most fun, you can change the registration point at any moment. Play with the demo above to see it in action.</p>
<p><strong>Source.</strong> Check out the <a href="http://code.google.com/p/barteksplayground/source/browse/trunk/src/com/everydayflash/util/Rotator.as" target="_blank">source of the class here</a>, or just grab a ZIP with the <a href="http://www.everydayflash.com/flash/rotator/Rotator.zip">complete demo here</a>. </p>
<p><strong>Example.</strong> It can be used either directly, in an 'ENTER_FRAME' animation, or in combination with <a href="http://code.google.com/p/tweener/" target="_blank">Tweener</a> or other similar libraries. It works not only with a Sprite, but also with any class that extends the DisplayObject. </p>
<p>Use it like this:</p>
<p>
<div class="igBar"><span id="lactionscript-3"><a href="#" onclick="javascript:showPlainTxt('actionscript-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-3">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> s:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> r:Rotator = <span style="color: #000000; font-weight: bold;">new</span> Rotator<span style="color: #66cc66;">&#40;</span>s, <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">10</span>,<span style="color: #cc66cc;color:#800000;">10</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">r.<span style="color: #006600;">rotation</span> = <span style="color: #cc66cc;color:#800000;">45</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>or like this:</p>
<p>
<div class="igBar"><span id="lactionscript-4"><a href="#" onclick="javascript:showPlainTxt('actionscript-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-4">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">import</span> caurina.<span style="color: #006600;">transitions</span>.<span style="color: #006600;">Tweener</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> s:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> r:Rotator = <span style="color: #000000; font-weight: bold;">new</span> Rotator<span style="color: #66cc66;">&#40;</span>s, <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">10</span>,<span style="color: #cc66cc;color:#800000;">10</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Tweener.<span style="color: #006600;">addTween</span><span style="color: #66cc66;">&#40;</span>r, <span style="color: #66cc66;">&#123;</span> rotation:<span style="color: #cc66cc;color:#800000;">45</span>, <span style="color: #0066CC;">time</span>:<span style="color: #cc66cc;color:#800000;">1</span>, transition:<span style="color: #ff0000;">"linear"</span><span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.everyday3d.com/blog/index.php/2008/05/28/rotating-a-sprite-around-any-point/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
