<?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; mouse</title>
	<atom:link href="http://www.benoitfreslon.com/tag/mouse/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: Throw bullets to mouse direction</title>
		<link>http://www.benoitfreslon.com/actionscript-throw-bullets-to-mouse-direction</link>
		<comments>http://www.benoitfreslon.com/actionscript-throw-bullets-to-mouse-direction#comments</comments>
		<pubDate>Mon, 27 Dec 2010 12:50:13 +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[angle]]></category>
		<category><![CDATA[bullet]]></category>
		<category><![CDATA[direction]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[radian]]></category>
		<category><![CDATA[shoot em up]]></category>

		<guid isPermaLink="false">http://www.benoitfreslon.com/?p=1225</guid>
		<description><![CDATA[After calculating the angle of 2 graphic objects, you can also use this angle to throw a bullet to the object direction with the trigonometry. How ? Calculating the angle (in radian) between 2 graphics objects with the Math.atan2 method (cf. Orient object to the mouse cursor). On click, display a bullet to the &#8220;tank&#8221; [...]]]></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%2Factionscript-throw-bullets-to-mouse-direction&amp;title=ActionScript%3A%20Throw%20bullets%20to%20mouse%20direction" 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>After calculating the angle of 2 graphic objects, you can also use this angle to throw a bullet to the object direction with the trigonometry.</p>
<p><strong>How ?</strong></p>
<ol>
<li>Calculating the angle (in radian) between 2 graphics objects with the <strong><a href="http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary451.html" target="_blank">Math.atan2</a></strong> method (cf. <a href="./orient-an-object-to-the-mouse-cursor" target="_blank">Orient object to the mouse cursor</a>).</li>
<li>On click, display a bullet to the &#8220;tank&#8221; position and add an &#8220;enter frame&#8221; event on this bullet.</li>
<li>And save the angle between the tank and the mouse cursor on the new  bullet.</li>
<li>Use this angle on the &#8220;enter frame&#8221; event to calculate the x and y speed with the cosinus and the sinus.</li>
</ol>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_www.benoitfreslon.com_Throw_bullets_to_mouse_direction_2119543674"
			class="flashmovie"
			width="640"
			height="400">
	<param name="movie" value="http://www.benoitfreslon.com/wp-content/uploads/2010/12/www.benoitfreslon.com_Throw_bullets_to_mouse_direction.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.benoitfreslon.com/wp-content/uploads/2010/12/www.benoitfreslon.com_Throw_bullets_to_mouse_direction.swf"
			name="fm_www.benoitfreslon.com_Throw_bullets_to_mouse_direction_2119543674"
			width="640"
			height="400">
	<!--<![endif]-->
		<br />
<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>
<div class="codecolorer-container actionscript3 default .codecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:300px;height:400px;"><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 />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<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: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Point</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// Code by Benoit Freslon.</span><br />
<span style="color: #009900; font-style: italic;">// Tutorials, Flash games:</span><br />
<span style="color: #009900; font-style: italic;">// http://www.benoitfreslon.com</span><br />
<br />
<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> &nbsp;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><span style="color: #004993;">mouseY</span> <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><span style="color: #004993;">mouseX</span> <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 angle</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><br />
<br />
<span style="color: #009900; font-style: italic;">// Add a mouse down event on stage</span><br />
<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">mouseDown</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">mouseDown</span><span style="color: #000000;">&#40;</span>pEvent<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Create a new bullet</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">b</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Bullet<span style="color: #000000;">&#40;</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;">// Set his position to the tank position</span><br />
&nbsp; &nbsp; <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = myTank<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = myTank<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Save the randian angle between the mouse and the tank</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// This angle will set the direction of the bullet</span><br />
&nbsp; &nbsp; <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</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><span style="color: #004993;">mouseY</span> <span style="color: #000066; font-weight: bold;">-</span> myTank<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: #004993;">mouseX</span> <span style="color: #000066; font-weight: bold;">-</span>myTank<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;">// Add an enter frame event on each bullet</span><br />
&nbsp; &nbsp; <span style="color: #004993;">b</span><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> bulletEnterFrame<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Add this display object on the display list</span><br />
&nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// Velocity of each bullet</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> speed = <span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> bulletEnterFrame<span style="color: #000000;">&#40;</span>pEvent<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Get the current object (Bullet)</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">b</span> = pEvent<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;">// Move this bullet on each frames</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// On X axis use the cosinus angle</span><br />
&nbsp; &nbsp; <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= &nbsp;<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span>angleRadian<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> speed<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// On Y axis use the sinus angle</span><br />
&nbsp; &nbsp; <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= &nbsp;<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span>angleRadian<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> speed<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Orient the bullet to the direction</span><br />
&nbsp; &nbsp; <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span> = <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span>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;">// You have to remove each created bullet</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// So after every moves you must check bullet position</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// If the bullet is out of the screen</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">400</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">400</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Remove it from the display list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// /!\ AND REOMOVE HIS EVENT LISTER</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</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> bulletEnterFrame<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Download source: <a href="http://www.benoitfreslon.com/wp-content/uploads/2010/12/www.benoitfreslon.com_Throw_bullets_to_mouse_direction.zip" target="_self">www.benoitfreslon.com_Throw_bullets_to_mouse_direction.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.benoitfreslon.com/actionscript-throw-bullets-to-mouse-direction/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<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_1866282458"
			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_1866282458"
			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_4"><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_1542845637"
			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_1542845637"
			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>

