<?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: Throw a ball with a sling physics Flash tutorial: Part 2 by Kevin Ward</title>
	<atom:link href="http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Sat, 11 Feb 2012 05:27:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: edgar</title>
		<link>http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-848763</link>
		<dc:creator>edgar</dc:creator>
		<pubDate>Wed, 08 Jun 2011 17:52:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-848763</guid>
		<description>Good work Kevin, Thanks for sharing</description>
		<content:encoded><![CDATA[<p>Good work Kevin, Thanks for sharing</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William</title>
		<link>http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-590557</link>
		<dc:creator>William</dc:creator>
		<pubDate>Tue, 15 Jun 2010 20:37:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-590557</guid>
		<description>I made an exetremely similar tutorial, only... This my one allows you to move the points on the elastic. Actually they happen to be strikingly similar, I just came across this now.

http://willasss.deviantart.com/art/Tutorial-Ball-Band-Collision-166528666</description>
		<content:encoded><![CDATA[<p>I made an exetremely similar tutorial, only&#8230; This my one allows you to move the points on the elastic. Actually they happen to be strikingly similar, I just came across this now.</p>
<p><a href="http://willasss.deviantart.com/art/Tutorial-Ball-Band-Collision-166528666" rel="nofollow">http://willasss.deviantart.com/art/Tutorial-Ball-Band-Collision-166528666</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ahzrael</title>
		<link>http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-430537</link>
		<dc:creator>Ahzrael</dc:creator>
		<pubDate>Mon, 13 Apr 2009 00:15:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-430537</guid>
		<description>This was a nice read, thanks :)</description>
		<content:encoded><![CDATA[<p>This was a nice read, thanks :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brandon</title>
		<link>http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-395209</link>
		<dc:creator>brandon</dc:creator>
		<pubDate>Mon, 23 Feb 2009 05:54:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-395209</guid>
		<description>question i would like to make something similar i would like to make a trowable ball without the sling part and with boundries so that you can trow it with your mouse but i dont want gravity i think you know what i mean try to find a way to do this thanks</description>
		<content:encoded><![CDATA[<p>question i would like to make something similar i would like to make a trowable ball without the sling part and with boundries so that you can trow it with your mouse but i dont want gravity i think you know what i mean try to find a way to do this thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-39430</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Fri, 05 Oct 2007 14:44:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-39430</guid>
		<description>toworth matthew
its funny how u can write actionscript so well and not know math :) but anyway
i&#039;ve been putting ur codes in a flash movie, and besides the faults u said there is also this one

at least at my flashstage (pro 8) 
all the lines like this one give errors, because the asterix * gets changed to a &quot;x&quot;
line1.lineStyle(2,0*000000);

oh and i just noticed, (i was changing the coordinates to get the things in screen) and u have the node2 2 times in the top lines, u create it 2 times? i don&#039;t realy see use for it i deleted it and it still works :) just that u know its double ;)

i placed ur game here
http://users.telenet.be/architectural_inspiration_peter_stals/matthew.swf</description>
		<content:encoded><![CDATA[<p>toworth matthew<br />
its funny how u can write actionscript so well and not know math :) but anyway<br />
i&#8217;ve been putting ur codes in a flash movie, and besides the faults u said there is also this one</p>
<p>at least at my flashstage (pro 8)<br />
all the lines like this one give errors, because the asterix * gets changed to a &#8220;x&#8221;<br />
line1.lineStyle(2,0*000000);</p>
<p>oh and i just noticed, (i was changing the coordinates to get the things in screen) and u have the node2 2 times in the top lines, u create it 2 times? i don&#8217;t realy see use for it i deleted it and it still works :) just that u know its double ;)</p>
<p>i placed ur game here<br />
<a href="http://users.telenet.be/architectural_inspiration_peter_stals/matthew.swf" rel="nofollow">http://users.telenet.be/architectural_inspiration_peter_stals/matthew.swf</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: herman</title>
		<link>http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-35920</link>
		<dc:creator>herman</dc:creator>
		<pubDate>Mon, 17 Sep 2007 15:55:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-35920</guid>
		<description>hey could somebody help me? I don&#039;t understand these lines -&gt;

var xOffset:Number=
Math.cos(angle1+Math.PI/2)*radius;

var yOffset:Number = Math.sin(angle1+Math.PI/2)*radius;

How can you know ,you should add &quot;Math.PI/2&quot;
to get to the right position?

Please tell me the idea !</description>
		<content:encoded><![CDATA[<p>hey could somebody help me? I don&#8217;t understand these lines -&gt;</p>
<p>var xOffset:Number=<br />
Math.cos(angle1+Math.PI/2)*radius;</p>
<p>var yOffset:Number = Math.sin(angle1+Math.PI/2)*radius;</p>
<p>How can you know ,you should add &#8220;Math.PI/2&#8243;<br />
to get to the right position?</p>
<p>Please tell me the idea !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Izy</title>
		<link>http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-30290</link>
		<dc:creator>Izy</dc:creator>
		<pubDate>Fri, 17 Aug 2007 20:20:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-30290</guid>
		<description>You&#039;re very correct.  I&#039;ve made some consideration on that, but I didn&#039;t want to take too large a step from Emanuele&#039;s original tutorial.

A good tweak would also be to allow the two points to be at different elevations.</description>
		<content:encoded><![CDATA[<p>You&#8217;re very correct.  I&#8217;ve made some consideration on that, but I didn&#8217;t want to take too large a step from Emanuele&#8217;s original tutorial.</p>
<p>A good tweak would also be to allow the two points to be at different elevations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew</title>
		<link>http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-30287</link>
		<dc:creator>Matthew</dc:creator>
		<pubDate>Fri, 17 Aug 2007 19:47:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-30287</guid>
		<description>o and also change this:
if (xpos2&gt;xpos1) {
xspeed = 0.3;
}

to

if (xpos2&gt;xpos1) {
xspeed (plus symbol)= 0.3;
}</description>
		<content:encoded><![CDATA[<p>o and also change this:<br />
if (xpos2&gt;xpos1) {<br />
xspeed = 0.3;<br />
}</p>
<p>to</p>
<p>if (xpos2&gt;xpos1) {<br />
xspeed (plus symbol)= 0.3;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew</title>
		<link>http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-30286</link>
		<dc:creator>Matthew</dc:creator>
		<pubDate>Fri, 17 Aug 2007 19:43:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-30286</guid>
		<description>oops I just relised it doesnt add the plus symbol for some reason so
in your code change

yspeed = gravity;
ball._y = yspeed;
xspeed *= friction;
ball._x = xspeed;

to

yspeed (plus symbol)= gravity;
ball._y (plus symbol)= yspeed;
xspeed *= friction;
ball._x (plus symbol)= xspeed;

obviously replaing the (plus symbol) with the actual symbol


also you will need to change any quotation marks to normal ones
just delete them and then put them in again as normal ones


o and gd luck to everyone entering the Jayisgames comp :)</description>
		<content:encoded><![CDATA[<p>oops I just relised it doesnt add the plus symbol for some reason so<br />
in your code change</p>
<p>yspeed = gravity;<br />
ball._y = yspeed;<br />
xspeed *= friction;<br />
ball._x = xspeed;</p>
<p>to</p>
<p>yspeed (plus symbol)= gravity;<br />
ball._y (plus symbol)= yspeed;<br />
xspeed *= friction;<br />
ball._x (plus symbol)= xspeed;</p>
<p>obviously replaing the (plus symbol) with the actual symbol</p>
<p>also you will need to change any quotation marks to normal ones<br />
just delete them and then put them in again as normal ones</p>
<p>o and gd luck to everyone entering the Jayisgames comp :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew</title>
		<link>http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-30281</link>
		<dc:creator>Matthew</dc:creator>
		<pubDate>Fri, 17 Aug 2007 18:24:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2007/08/16/throw-a-ball-with-a-sling-physics-flash-tutorial-part-2-by-kevin-ward/#comment-30281</guid>
		<description>Forgive me if im wrong but because Im only 12 i don&#039;t realy understand the maths that well. So I made a much easier way to do this which although it doesnt look exactly the same you hardly notice it.
Below is the code (if you want to use it just copy it to the main timeline, youll need three balls in your library linkaged as ball,node1 and node2. Also center the registration points of the two nodes and for the ball choose the middles bottom one)

//Attach some movieclips to the stage
var node1:MovieClip = _root.attachMovie(&quot;node1&quot;, &quot;node11&quot;, 3, {_x:50, _y:350});
var node2:MovieClip = _root.attachMovie(&quot;node2&quot;, &quot;node22&quot;, 4, {_x:650, _y:350});
var ball:MovieClip = _root.attachMovie(&quot;ball&quot;, &quot;balll&quot;, 5, {_x:350, _y:200});
var node2:MovieClip = _root.attachMovie(&quot;node2&quot;, &quot;node22&quot;, 4, {_x:650, _y:350});
//The movieclips we will use as lines
var line1:MovieClip = _root.createEmptyMovieClip(&quot;lines1&quot;, 1);
var line2:MovieClip = _root.createEmptyMovieClip(&quot;lines2&quot;, 2);
line1.lineStyle(2,0x000000);
line2.lineStyle(2,0x000000);
line1.moveTo(node1.x,node1.y);
line1.lineTo(node2.x,node2.y);
//Define some variables we can use later on
var friction:Number = 0.99;
var xspeed:Number = 0;
var yspeed:Number = 0;
var gravity:Number = 0.5;
var spring:Number = 1;
var dragging:Boolean = false;
//These are for dragging the ball

ball.onPress = function() {
	this.startDrag();
	yspeed = 0;
	xspeed = 0;
	gravity = 0;
	spring = 0;
	dragging = true;
};

ball.onRelease = function() {
	this.stopDrag();
	yspeed = 0;
	gravity = 0.5;
	spring = 1;
	dragging = false;
};



//When you click on one of the nodes the ball is placed back in its original position
node1.onRelease = function() {
	_root.ball._x = 350;
	_root.ball._y = 200;
	xspeed = 0;
	yspeed = 0;
};
node2.onRelease = function() {
	_root.ball._x = 350;
	_root.ball._y = 200;
	xspeed = 0;
	yspeed = 0;
};

//The main function
this.onEnterFrame = function() {
	//Moves the ball
	yspeed  = gravity;
	ball._y  = yspeed;
	xspeed *= friction;
	ball._x  = xspeed;
	line1.clear();
	line2.clear();
	//If its lower than the node
	if (ball._y&gt;node1._y) {
		//Check how far to the right and left the nodes are
		var xpos1:Number = node1._x-ball._x;
		var xpos2:Number = node2._x-ball._x;
		xpos1 = -xpos1;
		//If your not dragging the ball
		if (dragging == false) {
			//If it is further to the right than the left
			if (xpos1&gt;xpos2) {
				//Move it to the left
				xspeed -= 0.3;
			}
			//Other way round           
			if (xpos2&gt;xpos1) {
				xspeed  = 0.3;
			}
		}
		//Otherwise it would keep going down           
		yspeed -= spring;
		//Draw the lines again so they are connected to the ball
		line1.lineStyle(2,0x000000);
		line2.lineStyle(2,0x000000);
		line1.moveTo(node1._x,node1._y);
		line1.lineTo(ball._x,ball._y);
		line2.moveTo(node2._x,node2._y);
		line2.lineTo(ball._x,ball._y);

	} else {
		//If it isnt below the two points draw the line so it connects the two nodes
		line1.lineStyle(2,0x000000);
		line1.moveTo(node1._x,node1._y);
		line1.lineTo(node2._x,node2._y);
	}
};</description>
		<content:encoded><![CDATA[<p>Forgive me if im wrong but because Im only 12 i don&#8217;t realy understand the maths that well. So I made a much easier way to do this which although it doesnt look exactly the same you hardly notice it.<br />
Below is the code (if you want to use it just copy it to the main timeline, youll need three balls in your library linkaged as ball,node1 and node2. Also center the registration points of the two nodes and for the ball choose the middles bottom one)</p>
<p>//Attach some movieclips to the stage<br />
var node1:MovieClip = _root.attachMovie(&#8220;node1&#8243;, &#8220;node11&#8243;, 3, {_x:50, _y:350});<br />
var node2:MovieClip = _root.attachMovie(&#8220;node2&#8243;, &#8220;node22&#8243;, 4, {_x:650, _y:350});<br />
var ball:MovieClip = _root.attachMovie(&#8220;ball&#8221;, &#8220;balll&#8221;, 5, {_x:350, _y:200});<br />
var node2:MovieClip = _root.attachMovie(&#8220;node2&#8243;, &#8220;node22&#8243;, 4, {_x:650, _y:350});<br />
//The movieclips we will use as lines<br />
var line1:MovieClip = _root.createEmptyMovieClip(&#8220;lines1&#8243;, 1);<br />
var line2:MovieClip = _root.createEmptyMovieClip(&#8220;lines2&#8243;, 2);<br />
line1.lineStyle(2,0&#215;000000);<br />
line2.lineStyle(2,0&#215;000000);<br />
line1.moveTo(node1.x,node1.y);<br />
line1.lineTo(node2.x,node2.y);<br />
//Define some variables we can use later on<br />
var friction:Number = 0.99;<br />
var xspeed:Number = 0;<br />
var yspeed:Number = 0;<br />
var gravity:Number = 0.5;<br />
var spring:Number = 1;<br />
var dragging:Boolean = false;<br />
//These are for dragging the ball</p>
<p>ball.onPress = function() {<br />
	this.startDrag();<br />
	yspeed = 0;<br />
	xspeed = 0;<br />
	gravity = 0;<br />
	spring = 0;<br />
	dragging = true;<br />
};</p>
<p>ball.onRelease = function() {<br />
	this.stopDrag();<br />
	yspeed = 0;<br />
	gravity = 0.5;<br />
	spring = 1;<br />
	dragging = false;<br />
};</p>
<p>//When you click on one of the nodes the ball is placed back in its original position<br />
node1.onRelease = function() {<br />
	_root.ball._x = 350;<br />
	_root.ball._y = 200;<br />
	xspeed = 0;<br />
	yspeed = 0;<br />
};<br />
node2.onRelease = function() {<br />
	_root.ball._x = 350;<br />
	_root.ball._y = 200;<br />
	xspeed = 0;<br />
	yspeed = 0;<br />
};</p>
<p>//The main function<br />
this.onEnterFrame = function() {<br />
	//Moves the ball<br />
	yspeed  = gravity;<br />
	ball._y  = yspeed;<br />
	xspeed *= friction;<br />
	ball._x  = xspeed;<br />
	line1.clear();<br />
	line2.clear();<br />
	//If its lower than the node<br />
	if (ball._y&gt;node1._y) {<br />
		//Check how far to the right and left the nodes are<br />
		var xpos1:Number = node1._x-ball._x;<br />
		var xpos2:Number = node2._x-ball._x;<br />
		xpos1 = -xpos1;<br />
		//If your not dragging the ball<br />
		if (dragging == false) {<br />
			//If it is further to the right than the left<br />
			if (xpos1&gt;xpos2) {<br />
				//Move it to the left<br />
				xspeed -= 0.3;<br />
			}<br />
			//Other way round<br />
			if (xpos2&gt;xpos1) {<br />
				xspeed  = 0.3;<br />
			}<br />
		}<br />
		//Otherwise it would keep going down<br />
		yspeed -= spring;<br />
		//Draw the lines again so they are connected to the ball<br />
		line1.lineStyle(2,0&#215;000000);<br />
		line2.lineStyle(2,0&#215;000000);<br />
		line1.moveTo(node1._x,node1._y);<br />
		line1.lineTo(ball._x,ball._y);<br />
		line2.moveTo(node2._x,node2._y);<br />
		line2.lineTo(ball._x,ball._y);</p>
<p>	} else {<br />
		//If it isnt below the two points draw the line so it connects the two nodes<br />
		line1.lineStyle(2,0&#215;000000);<br />
		line1.moveTo(node1._x,node1._y);<br />
		line1.lineTo(node2._x,node2._y);<br />
	}<br />
};</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 6/11 queries in 0.059 seconds using disk: basic

Served from: www.emanueleferonato.com @ 2012-02-11 14:16:32 -->
