<?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: Bombs with Box2D &amp; Cocos2D</title>
	<atom:link href="http://www.vellios.com/2010/06/12/bombs-with-box2d-cocos2d/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vellios.com/2010/06/12/bombs-with-box2d-cocos2d/</link>
	<description>iPhone Development and my life as a single father</description>
	<lastBuildDate>Wed, 01 Feb 2012 09:43:42 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: random</title>
		<link>http://www.vellios.com/2010/06/12/bombs-with-box2d-cocos2d/comment-page-1/#comment-2858</link>
		<dc:creator>random</dc:creator>
		<pubDate>Sat, 23 Apr 2011 00:01:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.vellios.com/?p=316#comment-2858</guid>
		<description>Very cool.  Thanks for posting this.  After playing around a bit I decided to use ApplyLinearImpulse instead of ApplyForce.  Then you can turn it off after one tick and get essentially the same result.</description>
		<content:encoded><![CDATA[<p>Very cool.  Thanks for posting this.  After playing around a bit I decided to use ApplyLinearImpulse instead of ApplyForce.  Then you can turn it off after one tick and get essentially the same result.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Makyfa</title>
		<link>http://www.vellios.com/2010/06/12/bombs-with-box2d-cocos2d/comment-page-1/#comment-1159</link>
		<dc:creator>Makyfa</dc:creator>
		<pubDate>Fri, 29 Oct 2010 03:02:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.vellios.com/?p=316#comment-1159</guid>
		<description>Thanks Dan!  This is great!

I&#039;m having some trouble iterating on this though.  I&#039;d love to be able to delete the bomb&#039;s b2Body and let the user create an additional bomb.

Every time that I remove the body though, I lose the ability to add additional bombs.  Do I need to add the bombs to some sort of list before I remove their b2Body?  How would I go about that?

Thanks so much!</description>
		<content:encoded><![CDATA[<p>Thanks Dan!  This is great!</p>
<p>I&#8217;m having some trouble iterating on this though.  I&#8217;d love to be able to delete the bomb&#8217;s b2Body and let the user create an additional bomb.</p>
<p>Every time that I remove the body though, I lose the ability to add additional bombs.  Do I need to add the bombs to some sort of list before I remove their b2Body?  How would I go about that?</p>
<p>Thanks so much!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: koss</title>
		<link>http://www.vellios.com/2010/06/12/bombs-with-box2d-cocos2d/comment-page-1/#comment-1045</link>
		<dc:creator>koss</dc:creator>
		<pubDate>Sat, 09 Oct 2010 16:29:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.vellios.com/?p=316#comment-1045</guid>
		<description>Thank you for this tutorial!   I also add the new bomblife too and it works great! I have a question... How would you change your code to NOT explode but IMPLODE?  I kind of newbie :)</description>
		<content:encoded><![CDATA[<p>Thank you for this tutorial!   I also add the new bomblife too and it works great! I have a question&#8230; How would you change your code to NOT explode but IMPLODE?  I kind of newbie <img src='http://www.vellios.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cocos2d Collection at Under The Bridge</title>
		<link>http://www.vellios.com/2010/06/12/bombs-with-box2d-cocos2d/comment-page-1/#comment-965</link>
		<dc:creator>cocos2d Collection at Under The Bridge</dc:creator>
		<pubDate>Fri, 24 Sep 2010 06:55:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.vellios.com/?p=316#comment-965</guid>
		<description>[...] Nick Vellios wrote a series on adding radial gravity to Box2D. (h/t: [...]</description>
		<content:encoded><![CDATA[<p>[...] Nick Vellios wrote a series on adding radial gravity to Box2D. (h/t: [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Vellios</title>
		<link>http://www.vellios.com/2010/06/12/bombs-with-box2d-cocos2d/comment-page-1/#comment-47</link>
		<dc:creator>Nick Vellios</dc:creator>
		<pubDate>Tue, 22 Jun 2010 04:21:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.vellios.com/?p=316#comment-47</guid>
		<description>Funny you posted this.  I was just thinking yesterday how I wanted to implement a timer to turn off the force.  Thank you!  I will be updating this in the next week or so to implement something like this.</description>
		<content:encoded><![CDATA[<p>Funny you posted this.  I was just thinking yesterday how I wanted to implement a timer to turn off the force.  Thank you!  I will be updating this in the next week or so to implement something like this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: afour</title>
		<link>http://www.vellios.com/2010/06/12/bombs-with-box2d-cocos2d/comment-page-1/#comment-45</link>
		<dc:creator>afour</dc:creator>
		<pubDate>Tue, 22 Jun 2010 03:54:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.vellios.com/?p=316#comment-45</guid>
		<description>Thanks for this... I modified it a little to make a more realistic explosion. I added a &#039;bomblife&#039; variable that turns off the bomb gravity after a set period of ticks. This makes the falling blocks fall without being pushed away from the circles.

Like this:
&lt;pre lang=&quot;objc&quot;&gt;
-(void) tick: (ccTime) dt
{
	//It is recommended that a fixed time step is used with Box2D for stability
	//of the simulation, however, we are using a variable time step here.
	//You need to make an informed choice, the following URL is useful
	//http://gafferongames.com/game-physics/fix-your-timestep/
	
	int32 velocityIterations = 8;
	int32 positionIterations = 1;
	
	// Instruct the world to perform a single step of simulation. It is
	// generally best to keep the time step and iterations fixed.
	world-&gt;Step(dt, velocityIterations, positionIterations);

	
	//Iterate over the bodies in the physics world
	for (b2Body* b = world-&gt;GetBodyList(); b; b = b-&gt;GetNext())
	{
		if(bomb)
		{
			if (bomblife &gt; 0)
			{
				b2Body* ground = planet-&gt;GetBody();
				b2CircleShape* circle = (b2CircleShape*)planet-&gt;GetShape();
				// Get position of our &quot;Planet&quot; - Nick
				b2Vec2 center = ground-&gt;GetWorldPoint(circle-&gt;m_p);
				// Get position of our current body in the iteration - Nick
				b2Vec2 position = b-&gt;GetPosition();
				// Get the distance between the two objects. - Nick
				b2Vec2 d = center - position;
				// The further away the objects are, the weaker the gravitational force is - Nick
				float force = kRADIAL_GRAVITY_FORCE / d.LengthSquared(); // 150 can be changed to adjust the amount of force - Nick
				d.Normalize();
				b2Vec2 F = force * d;
				// Finally apply a force on the body in the direction of the &quot;Planet&quot; - Nick
				b-&gt;ApplyForce(F, position);
				bomblife--;
			}
			else {
				bomb = NO;
			}

		}
		
		if (b-&gt;GetUserData() != NULL) {
			//Synchronize the AtlasSprites position and rotation with the corresponding body
			CCSprite *myActor = (CCSprite*)b-&gt;GetUserData();
			myActor.position = CGPointMake( b-&gt;GetPosition().x * PTM_RATIO, b-&gt;GetPosition().y * PTM_RATIO);
			myActor.rotation = -1 * CC_RADIANS_TO_DEGREES(b-&gt;GetAngle());
		}	
	}
}

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
	//Add a new body/atlas sprite at the touched location
	for( UITouch *touch in touches ) {
		CGPoint location = [touch locationInView: [touch view]];
		
		location = [[CCDirector sharedDirector] convertToGL: location];
		
		if(!bomb) {
			// Create our static &quot;Planet&quot; - Nick
			b2CircleShape shape;
			shape.m_radius = 0.5f;
			shape.m_p.Set(location.x / PTM_RATIO,location.y / PTM_RATIO);
			b2FixtureDef fd;
			fd.shape = &amp;shape;
			planet = groundBody-&gt;CreateFixture(&amp;fd);
			// End Create Planet - Nick
			bomb = YES;
			bomblife = 120;
		}
	}
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Thanks for this&#8230; I modified it a little to make a more realistic explosion. I added a &#8216;bomblife&#8217; variable that turns off the bomb gravity after a set period of ticks. This makes the falling blocks fall without being pushed away from the circles.</p>
<p>Like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> tick<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>ccTime<span style="color: #002200;">&#41;</span> dt
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">//It is recommended that a fixed time step is used with Box2D for stability</span>
	<span style="color: #11740a; font-style: italic;">//of the simulation, however, we are using a variable time step here.</span>
	<span style="color: #11740a; font-style: italic;">//You need to make an informed choice, the following URL is useful</span>
	<span style="color: #11740a; font-style: italic;">//http://gafferongames.com/game-physics/fix-your-timestep/</span>
&nbsp;
	int32 velocityIterations <span style="color: #002200;">=</span> <span style="color: #2400d9;">8</span>;
	int32 positionIterations <span style="color: #002200;">=</span> <span style="color: #2400d9;">1</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Instruct the world to perform a single step of simulation. It is</span>
	<span style="color: #11740a; font-style: italic;">// generally best to keep the time step and iterations fixed.</span>
	world<span style="color: #002200;">-</span>&gt;Step<span style="color: #002200;">&#40;</span>dt, velocityIterations, positionIterations<span style="color: #002200;">&#41;</span>;
&nbsp;
&nbsp;
	<span style="color: #11740a; font-style: italic;">//Iterate over the bodies in the physics world</span>
	<span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>b2Body<span style="color: #002200;">*</span> b <span style="color: #002200;">=</span> world<span style="color: #002200;">-</span>&gt;GetBodyList<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>; b; b <span style="color: #002200;">=</span> b<span style="color: #002200;">-</span>&gt;GetNext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>bomb<span style="color: #002200;">&#41;</span>
		<span style="color: #002200;">&#123;</span>
			<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>bomblife &gt; <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>
			<span style="color: #002200;">&#123;</span>
				b2Body<span style="color: #002200;">*</span> ground <span style="color: #002200;">=</span> planet<span style="color: #002200;">-</span>&gt;GetBody<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
				b2CircleShape<span style="color: #002200;">*</span> circle <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>b2CircleShape<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>planet<span style="color: #002200;">-</span>&gt;GetShape<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
				<span style="color: #11740a; font-style: italic;">// Get position of our &quot;Planet&quot; - Nick</span>
				b2Vec2 center <span style="color: #002200;">=</span> ground<span style="color: #002200;">-</span>&gt;GetWorldPoint<span style="color: #002200;">&#40;</span>circle<span style="color: #002200;">-</span>&gt;m_p<span style="color: #002200;">&#41;</span>;
				<span style="color: #11740a; font-style: italic;">// Get position of our current body in the iteration - Nick</span>
				b2Vec2 position <span style="color: #002200;">=</span> b<span style="color: #002200;">-</span>&gt;GetPosition<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
				<span style="color: #11740a; font-style: italic;">// Get the distance between the two objects. - Nick</span>
				b2Vec2 d <span style="color: #002200;">=</span> center <span style="color: #002200;">-</span> position;
				<span style="color: #11740a; font-style: italic;">// The further away the objects are, the weaker the gravitational force is - Nick</span>
				<span style="color: #a61390;">float</span> force <span style="color: #002200;">=</span> kRADIAL_GRAVITY_FORCE <span style="color: #002200;">/</span> d.LengthSquared<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">// 150 can be changed to adjust the amount of force - Nick</span>
				d.Normalize<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
				b2Vec2 F <span style="color: #002200;">=</span> force <span style="color: #002200;">*</span> d;
				<span style="color: #11740a; font-style: italic;">// Finally apply a force on the body in the direction of the &quot;Planet&quot; - Nick</span>
				b<span style="color: #002200;">-</span>&gt;ApplyForce<span style="color: #002200;">&#40;</span>F, position<span style="color: #002200;">&#41;</span>;
				bomblife<span style="color: #002200;">--</span>;
			<span style="color: #002200;">&#125;</span>
			<span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
				bomb <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
			<span style="color: #002200;">&#125;</span>
&nbsp;
		<span style="color: #002200;">&#125;</span>
&nbsp;
		<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>b<span style="color: #002200;">-</span>&gt;GetUserData<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">!=</span> <span style="color: #a61390;">NULL</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
			<span style="color: #11740a; font-style: italic;">//Synchronize the AtlasSprites position and rotation with the corresponding body</span>
			CCSprite <span style="color: #002200;">*</span>myActor <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>CCSprite<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>b<span style="color: #002200;">-</span>&gt;GetUserData<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
			myActor.position <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span> b<span style="color: #002200;">-</span>&gt;GetPosition<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>.x <span style="color: #002200;">*</span> PTM_RATIO, b<span style="color: #002200;">-</span>&gt;GetPosition<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>.y <span style="color: #002200;">*</span> PTM_RATIO<span style="color: #002200;">&#41;</span>;
			myActor.rotation <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">1</span> <span style="color: #002200;">*</span> CC_RADIANS_TO_DEGREES<span style="color: #002200;">&#40;</span>b<span style="color: #002200;">-</span>&gt;GetAngle<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#125;</span>	
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>ccTouchesEnded<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSSet</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>touches withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">//Add a new body/atlas sprite at the touched location</span>
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span> UITouch <span style="color: #002200;">*</span>touch <span style="color: #a61390;">in</span> touches <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		CGPoint location <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>touch locationInView<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>touch view<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
		location <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCDirector sharedDirector<span style="color: #002200;">&#93;</span> convertToGL<span style="color: #002200;">:</span> location<span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>bomb<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
			<span style="color: #11740a; font-style: italic;">// Create our static &quot;Planet&quot; - Nick</span>
			b2CircleShape shape;
			shape.m_radius <span style="color: #002200;">=</span> 0.5f;
			shape.m_p.Set<span style="color: #002200;">&#40;</span>location.x <span style="color: #002200;">/</span> PTM_RATIO,location.y <span style="color: #002200;">/</span> PTM_RATIO<span style="color: #002200;">&#41;</span>;
			b2FixtureDef fd;
			fd.shape <span style="color: #002200;">=</span> <span style="color: #002200;">&amp;</span>shape;
			planet <span style="color: #002200;">=</span> groundBody<span style="color: #002200;">-</span>&gt;CreateFixture<span style="color: #002200;">&#40;</span><span style="color: #002200;">&amp;</span>fd<span style="color: #002200;">&#41;</span>;
			<span style="color: #11740a; font-style: italic;">// End Create Planet - Nick</span>
			bomb <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
			bomblife <span style="color: #002200;">=</span> <span style="color: #2400d9;">120</span>;
		<span style="color: #002200;">&#125;</span>
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
</channel>
</rss>

