<?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>Benoit Freslon&#039;s blog  - Game Design, Flash games, ActionScript tutorials ... &#187; orientation</title>
	<atom:link href="http://www.benoitfreslon.com/tag/orientation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.benoitfreslon.com</link>
	<description>Indie Game developer, learn Flash &#38; ActionScript with tutorials ...</description>
	<lastBuildDate>Mon, 16 Jan 2012 16:50:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>ActionScript: Orient an object to the mouse cursor</title>
		<link>http://www.benoitfreslon.com/orient-an-object-to-the-mouse-cursor</link>
		<comments>http://www.benoitfreslon.com/orient-an-object-to-the-mouse-cursor#comments</comments>
		<pubDate>Sat, 09 Jan 2010 18:17:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript3 as3]]></category>
		<category><![CDATA[Game Design]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[orientation]]></category>

		<guid isPermaLink="false">http://www.thisisgameplay.com/?p=725</guid>
		<description><![CDATA[How to orient an objet to an other ? Just put those lines and change the instance name myTank. 
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_Orienter_un_objet_par_rapport_%C3%A0_un_autre1_1797986110"
			class="flashmovie"
			width="300"
			height="300">
	<param name="movie" value="http://www.benoitfreslon.com/wp-content/uploads/2010/01/Orienter_un_objet_par_rapport_%C3%A0_un_autre1.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.benoitfreslon.com/wp-content/uploads/2010/01/Orienter_un_objet_par_rapport_%C3%A0_un_autre1.swf"
			name="fm_Orienter_un_objet_par_rapport_%C3%A0_un_autre1_1797986110"
			width="300"
			height="300">
	<!--<![endif]-->
		 
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object> 12345678910111213141516// This object will always look at the mouse cursor myTank.addEventListener&#40;Event.ENTER_FRAME, tankEnterFrame&#41;; // This function will be launched every frame (25 times by seconds); function tankEnterFrame&#40;pEvt&#41; &#123; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.benoitfreslon.com%2Forient-an-object-to-the-mouse-cursor&amp;title=ActionScript%3A%20Orient%20an%20object%20to%20the%20mouse%20cursor" id="wpa2a_2"><img src="http://www.benoitfreslon.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p><p>How to orient an objet to an other ? Just put those lines and change the instance name myTank. 
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_Orienter_un_objet_par_rapport_%C3%A0_un_autre1_1521335977"
			class="flashmovie"
			width="300"
			height="300">
	<param name="movie" value="http://www.benoitfreslon.com/wp-content/uploads/2010/01/Orienter_un_objet_par_rapport_%C3%A0_un_autre1.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.benoitfreslon.com/wp-content/uploads/2010/01/Orienter_un_objet_par_rapport_%C3%A0_un_autre1.swf"
			name="fm_Orienter_un_objet_par_rapport_%C3%A0_un_autre1_1521335977"
			width="300"
			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> 
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<div class="codecolorer-container actionscript3 default .codecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-style: italic;">// This object will always look at the mouse cursor</span><br />
myTank<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> tankEnterFrame<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #009900; font-style: italic;">// This function will be launched every frame (25 times by seconds);</span><br />
<span style="color: #339966; font-weight: bold;">function</span> tankEnterFrame<span style="color: #000000;">&#40;</span>pEvt<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// pEvt.currentTarget : myTank</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> mc = pEvt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">currentTarget</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Get the radian angle between the tank and the cursor</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// You can also replace mouseX and mouseY by another coordinates</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> angleRadian=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">atan2</span><span style="color: #000000;">&#40;</span>mouseY<span style="color: #000066; font-weight: bold;">-</span>mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>mouseX<span style="color: #000066; font-weight: bold;">-</span>mc<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><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Convert the radian angle in dedree</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> angleDegree = angleRadian <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">180</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Set the orientation</span><br />
&nbsp; &nbsp; mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span> = angleDegree<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Display angle of rotation in degree</span><br />
&nbsp; &nbsp; txtAngle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span>angleDegree<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;°&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Download the source code here : <a href="http://www.benoitfreslon.com/orient-an-object-to-the-mouse-cursor/www-thisisgameplay-com_orient_object_to_mouse_cursor/" rel="attachment wp-att-749">[www.thisisgameplay.com]_Orient_object_to_mouse_cursor.fla</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.benoitfreslon.com/orient-an-object-to-the-mouse-cursor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

