<?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>iPhone Dev</title>
	<atom:link href="http://iphonedev.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://iphonedev.net</link>
	<description>iPhone Development, Objective C, Cocoa</description>
	<lastBuildDate>Thu, 29 Jul 2010 01:33:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>iPhone Game Kit Review</title>
		<link>http://iphonedev.net/2010/07/21/iphone-game-kit/</link>
		<comments>http://iphonedev.net/2010/07/21/iphone-game-kit/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 04:24:54 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://iphonedev.net/?p=117</guid>
		<description><![CDATA[There is no doubt that Cocos2d can accelerate our game development on iPhone. But do you want to be faster? You may consider iPhone Game Kit. What is iPhone Game Kit? You may treat it as a higher level game development framework (or engine) which is built upon iPhone SDK and Cocos2d. Developers can use [...]]]></description>
			<content:encoded><![CDATA[<p>There is no doubt that <a href="http://cocos2d-iphone.org">Cocos2d</a> can accelerate our game development on iPhone. But do you want to be faster? You may consider <a href="http://iphonegamekit.com" target="_blank">iPhone Game Kit</a>.<span id="more-117"></span><strong></strong></p>
<p><strong>What is iPhone Game Kit</strong>? You may treat it as a higher level game development framework (or engine) which is built upon iPhone SDK and Cocos2d. Developers can use it as a starting point for their iPhone game development.</p>
<p><strong>Why</strong>? Normally, it is still difficult for a beginner to complete a relatively complicated game after learning some techniques or doing some tutorials, because they have no ideas where to start and how to utilize the knowledge they have learnt. It is very common that the program written by beginners has a bad or inflexible structure which is difficult to extend or suffers from performance problems. Fortunately, <a href="http://iphonegamekit.com">iPhone Game Kit</a> has built up a reliable and flexible framework for you. What you need to do is to fill in your own stuff, and the kit will handle the rest things. The author of <a href="http://iphonegamekit.com">iPhone Game Kit</a>, who is Net Weiss, has many years game development experiences on different platforms. He knows what structure that a good game should own. The kit also contains a lot of clear codes you can use or customize , such as <em>Joystick touch control&#8230;</em>. The kit will include high resolution support in next version for iPad and iPhone 4, and the guide book will show you how to do that in your development.</p>
<p><strong>Guide Book</strong>: <a href="http://iphonegamekit.com">iPhone Game Kit</a> also provides a good guide book to teach you how to create a game using this kit. Based on my experience, this guide book is very readable and covers most essential things. You will know the structure of the kit and how the kit works after reading the book. Many parts explain the codes piece-by-piece and show you how to complete a task step-by-step. Of course, for some details you need to explore by yourself, but I don&#8217;t think this is difficult when you have a big picture in your head. Surprisingly, this book even covers most essential knowledge of <em>Objective C</em>, which means beginners won&#8217;t have difficulties in reading the codes. In addition, this guide book also shows how to create <em>map</em> using <a href="http://www.mapeditor.org/">Tiled Map Editor</a>, create <em>sprite sheet</em> using <a href="http://zwoptexapp.com/flashversion">Sprite Sheet Maker</a>, and do some simple image processing using <a href="http://opensword.org/Pixen/">Pixen</a>. In a word, the beginner will know the whole story about iPhone game development after reading the book.</p>
<p><strong>Art Works</strong>: The kit provides a collection of art files including characters, items, menu graphics and sound effects. These files come from <a href="http://reinerstileset.4players.de/">Reiner</a>&#8216;s kind sharing. You can use them for free. I think this is very useful for individual developers.</p>
<p><strong>Publishing Guide</strong>: After the developers finish building their games. They need to publish their games to App store. The kit provides a publishing guide to help beginners achieve this.</p>
<p><strong>Where to get it</strong>: You can get the game kit from their web site <a href="http://iphonegamekit.com">iphonegamekit.com</a>. It has a 50% off discount right now until 1st, September. You don&#8217;t have to wait for the newer version because it has free updates for life.</p>
<p>Here I want to use some words from <a href="http://iphonegamekit.com">iPhone Game Kit</a> to end this post: &#8220;<em>Once you have mastered the Game Kit, you will have a solid foundation to develop games on other platforms and languages</em>&#8220;.</p>
<p><em>Update</em>: The new version 2.0 came out. A new chapter about iOS4 high resolution display and multi-thread programming is added. Now people can use Paypal to make a payment.</p>
<p><strong>Disclaimer</strong>: This post is not a commercial ads. The opinions in this post are based on my own research and book reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://iphonedev.net/2010/07/21/iphone-game-kit/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Rope Simulation with Cocos2d and Box2d</title>
		<link>http://iphonedev.net/2010/02/05/rope-simulate-with-cocos2d-and-box2d/</link>
		<comments>http://iphonedev.net/2010/02/05/rope-simulate-with-cocos2d-and-box2d/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 03:46:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://iphonedev.net/?p=111</guid>
		<description><![CDATA[This post presents a good idea on how to simulate a rope using the distance joint in Box2d . I re-implemented it using  Cocos2d.  If you have got problems, please refer to that post for more details or leave a comment. In addition, you can also find another way of simulating a rope using Box2d [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.box2d.org/forum/viewtopic.php?f=6&amp;t=2094">This post</a> presents a good idea on how to simulate a rope using the distance joint in Box2d . I re-implemented it using  Cocos2d.  If you have got problems, please refer to that post for more details or leave a comment. In addition, you can also find another way of simulating a rope using Box2d from <a href="http://www.emanueleferonato.com/2009/10/05/basic-box2d-rope/">here</a>.<span id="more-111"></span></p>
<p><img class="alignnone" title="rope" src="http://farm5.static.flickr.com/4056/4333337757_dafc05d650_m.jpg" alt="" width="125" height="240" /></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><strong>Download</strong>: You can download source codes from <a href="http://iphonedev.net/files/RopeSim.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iphonedev.net/2010/02/05/rope-simulate-with-cocos2d-and-box2d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create Composite Object with Box2D</title>
		<link>http://iphonedev.net/2009/08/14/create-composite-object-with-box2d/</link>
		<comments>http://iphonedev.net/2009/08/14/create-composite-object-with-box2d/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 07:15:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://iphonedev.net/?p=106</guid>
		<description><![CDATA[With Box2D, it&#8217;s very easy to create the composite object, which is composed of different standard small objects (e.g, polygon, circle, etc). This feature is useful when the shape of your sprite is complex. In this article, I will present how to achieve it. Method: 1. Create a body; 2. Using the body to create [...]]]></description>
			<content:encoded><![CDATA[<p>With Box2D, it&#8217;s very easy to create the composite object, which is composed of different standard small objects (e.g, polygon, circle, etc). This feature is useful when the shape of your sprite is complex. In this article, I will present how to achieve it.</p>
<p><span id="more-106"></span><strong>Method</strong>:</p>
<p>1. Create a body;</p>
<p>2. Using the body to create the shapes of all components.</p>
<p>3. Setup body&#8217;s mass.</p>
<p><strong>Example</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">int</span> matrix<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#91;</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">=</span>
<span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#123;</span><span style="color: #2400d9;">1</span>,<span style="color: #2400d9;">0</span><span style="color: #002200;">&#125;</span>,
<span style="color: #002200;">&#123;</span><span style="color: #2400d9;">1</span>,<span style="color: #2400d9;">1</span><span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>;
&nbsp;
        b2BodyDef boxBodyDef;
	boxBodyDef.position.Set<span style="color: #002200;">&#40;</span>150.0f<span style="color: #002200;">/</span>PTM_RATIO, 400.0f<span style="color: #002200;">/</span>PTM_RATIO<span style="color: #002200;">&#41;</span>;
	boxBody <span style="color: #002200;">=</span> world<span style="color: #002200;">-</span>&gt;CreateBody<span style="color: #002200;">&#40;</span><span style="color: #002200;">&amp;</span>boxBodyDef<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i&lt;<span style="color: #2400d9;">2</span>; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> j<span style="color: #002200;">=</span><span style="color: #2400d9;">0</span>; j&lt;<span style="color: #2400d9;">2</span>; j<span style="color: #002200;">++</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>matrix<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#91;</span>j<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
b2PolygonDef<span style="color: #002200;">*</span> boxShapeDef <span style="color: #002200;">=</span> new b2PolygonDef;
boxShapeDef<span style="color: #002200;">-</span>&gt;SetAsBox<span style="color: #002200;">&#40;</span>50.0f<span style="color: #002200;">/</span>PTM_RATIO<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>, 50.0f<span style="color: #002200;">/</span>PTM_RATIO<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>, b2Vec2<span style="color: #002200;">&#40;</span>i<span style="color: #002200;">*</span>50.0f<span style="color: #002200;">/</span>PTM_RATIO,j<span style="color: #002200;">*</span>50.0f<span style="color: #002200;">/</span>PTM_RATIO<span style="color: #002200;">&#41;</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
				boxShapeDef<span style="color: #002200;">-</span>&gt;density <span style="color: #002200;">=</span> 1.0f;
				boxShapeDef<span style="color: #002200;">-</span>&gt;friction <span style="color: #002200;">=</span> 0.3f;
				boxShapeDef<span style="color: #002200;">-</span>&gt;restitution <span style="color: #002200;">=</span> 0.1f;
				boxBody<span style="color: #002200;">-</span>&gt;CreateFixture<span style="color: #002200;">&#40;</span>boxShapeDef<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;
	boxBody<span style="color: #002200;">-</span>&gt;SetMassFromShapes<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>In the codes above, we created a composite object with the help of an array <em>matrix</em>, its values determines where a box should be added. Another point should be noted is the method <em>SetAsBox</em>. You need to specify the location of the box in <em>local</em> coordinate with the third parameter.</p>
<p><img class="alignnone" title="1" src="http://farm3.static.flickr.com/2669/3820113456_14ea3989c5_m.jpg" alt="" width="125" height="240" /></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p><strong>Download</strong>: You can download the source codes from <a href="http://iphonedev.net/files/Composite.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iphonedev.net/2009/08/14/create-composite-object-with-box2d/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Distance Joint of Box2D</title>
		<link>http://iphonedev.net/2009/08/12/distance-joint-of-box2d/</link>
		<comments>http://iphonedev.net/2009/08/12/distance-joint-of-box2d/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 00:11:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://iphonedev.net/?p=103</guid>
		<description><![CDATA[In this article, I will present how to create a distance joint with Box2D. The example in my last article How to Use DebugDraw of Box2d with Cocos2d is used as the basis. A box is added to the world, and a distance joint between the box and ball will be created. Step 1: Create [...]]]></description>
			<content:encoded><![CDATA[<p>In this article, I will present how to create a distance joint with Box2D. The example in my last article <a href="http://iphonedev.net/2009/08/10/how-to-use-debugdraw-of-box2d-with-cocos2d/">How to Use DebugDraw of Box2d with Cocos2d</a> is used as the basis. A box is added to the world, and a distance joint between the box and ball will be created.</p>
<p><span id="more-103"></span><strong>Step 1</strong>: Create a box in the physics world. (in the initialization method)</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">b2BodyDef boxBodyDef;
	boxBodyDef.position.Set<span style="color: #002200;">&#40;</span>200.0f<span style="color: #002200;">/</span>PTM_RATIO, 400.0f<span style="color: #002200;">/</span>PTM_RATIO<span style="color: #002200;">&#41;</span>;
	boxBody <span style="color: #002200;">=</span> world<span style="color: #002200;">-</span>&gt;CreateBody<span style="color: #002200;">&#40;</span><span style="color: #002200;">&amp;</span>boxBodyDef<span style="color: #002200;">&#41;</span>;
	b2PolygonDef boxShapeDef;
	boxShapeDef.SetAsBox<span style="color: #002200;">&#40;</span>50.0f<span style="color: #002200;">/</span>PTM_RATIO<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>, 50.0f<span style="color: #002200;">/</span>PTM_RATIO<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span>;
	boxShapeDef.density <span style="color: #002200;">=</span> 1.0f;
	boxShapeDef.friction <span style="color: #002200;">=</span> 0.3f;
	boxShapeDef.restitution <span style="color: #002200;">=</span> 0.5f;
	boxBody<span style="color: #002200;">-</span>&gt;CreateFixture<span style="color: #002200;">&#40;</span><span style="color: #002200;">&amp;</span>boxShapeDef<span style="color: #002200;">&#41;</span>;
	boxBody<span style="color: #002200;">-</span>&gt;SetMassFromShapes<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p><strong>Step 2</strong>: Create a distance joint between the box and ball. (in the initialization method)</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">b2DistanceJointDef dj;
	dj.Initialize<span style="color: #002200;">&#40;</span>ballBody, boxBody, ballBody<span style="color: #002200;">-</span>&gt;GetPosition<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>,boxBody<span style="color: #002200;">-</span>&gt;GetPosition<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
	dj.collideConnected <span style="color: #002200;">=</span> <span style="color: #a61390;">true</span>;
	m_distanceJoint <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>b2DistanceJoint<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> world<span style="color: #002200;">-</span>&gt;CreateJoint<span style="color: #002200;">&#40;</span><span style="color: #002200;">&amp;</span>dj<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p><strong>Note:</strong> the attribute <em>collideConnected</em> determines if the box and the ball collide. If the valie is false, the box and ball will overlap.</p>
<p>All done!</p>
<p><img class="alignnone" title="1" src="http://farm4.static.flickr.com/3535/3815598161_5b034eb3c9_m.jpg" alt="" width="125" height="240" /></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><strong>Download</strong>: You can download the source codes from <a href="http://iphonedev.net/files/Box2dBouncingBall4.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iphonedev.net/2009/08/12/distance-joint-of-box2d/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Use DebugDraw of Box2d with Cocos2d</title>
		<link>http://iphonedev.net/2009/08/10/how-to-use-debugdraw-of-box2d-with-cocos2d/</link>
		<comments>http://iphonedev.net/2009/08/10/how-to-use-debugdraw-of-box2d-with-cocos2d/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 04:22:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://iphonedev.net/?p=95</guid>
		<description><![CDATA[Cocos2d-iPhone just released v0.8.1-Beta. A great news is DebugDraw of Box2D works with Cocos2d now. I tried DebugDraw with Cocos2d v0.8.0 before, but nothing shows up. In this article, I will briefly introduce how to use DebugDraw with Cocos2d v0.8.1-Beta. Note: The following example is based on the article How to Implement Grabbing a Sprite [...]]]></description>
			<content:encoded><![CDATA[<p>Cocos2d-iPhone just released <a href="http://www.cocos2d-iphone.org/download">v0.8.1-Beta</a>. A great news is <em>DebugDraw</em> of Box2D works with Cocos2d now. I tried DebugDraw with Cocos2d v0.8.0 before, but nothing shows up. In this article, I will briefly introduce how to use DebugDraw with Cocos2d v0.8.1-Beta. Note: The following example is based on the article <a href="http://iphonedev.net/2009/08/05/how-to-grab-a-sprite-with-cocos2d-and-box2d/">How to Implement Grabbing a Sprite with Cocos2d and Box2d</a>. I used DebugDraw instead of the ball sprite. Another thing should be noticed is something changed in Box2d. For example, b2Body::CreateShape is removed, you should use b2Body::CreateFixture instead. You can see some changes from the source codes of following example.</p>
<p><span id="more-95"></span>DebugDraw is a very useful tool for verifying simulating and speeding up your game development. At the initial stage of development, you usually don&#8217;t want to think much of graphics, so you can use DebugDraw to help draw physics entities. When you are confident about the game logic, simulation or some other important things, you can use your own pretty sprites to replace DebugDraw.</p>
<p>In order to use DebugDraw, you need two steps:</p>
<p><strong>Step 1:</strong> Setup <em>DebugDraw</em> in initialization. To use DebugDraw of Box2d, normally we need to inherit from class DebugDraw and implement our own methods (e.g., DrawPolygon, DrawSolidCircle, etc.) of drawing physics entities.  In Cocos2d, we can easily use GLESDebugDraw instead of implementing our own ones. Therefore, in the initialization function, simply add the following codes:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">m_debugDraw <span style="color: #002200;">=</span> new GLESDebugDraw<span style="color: #002200;">&#40;</span>PTM_RATIO<span style="color: #002200;">&#41;</span>;
	uint32 flags <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
	flags <span style="color: #002200;">+=</span> <span style="color: #2400d9;">1</span>	<span style="color: #002200;">*</span> b2DebugDraw<span style="color: #002200;">::</span>e_shapeBit;
	flags <span style="color: #002200;">+=</span> <span style="color: #2400d9;">1</span>	<span style="color: #002200;">*</span> b2DebugDraw<span style="color: #002200;">::</span>e_jointBit;
	flags <span style="color: #002200;">+=</span> <span style="color: #2400d9;">1</span>	<span style="color: #002200;">*</span> b2DebugDraw<span style="color: #002200;">::</span>e_controllerBit;
	flags <span style="color: #002200;">+=</span> <span style="color: #2400d9;">1</span>	<span style="color: #002200;">*</span> b2DebugDraw<span style="color: #002200;">::</span>e_coreShapeBit;
	flags <span style="color: #002200;">+=</span> <span style="color: #2400d9;">1</span>	<span style="color: #002200;">*</span> b2DebugDraw<span style="color: #002200;">::</span>e_aabbBit;
	flags <span style="color: #002200;">+=</span> <span style="color: #2400d9;">1</span>	<span style="color: #002200;">*</span> b2DebugDraw<span style="color: #002200;">::</span>e_obbBit;
	flags <span style="color: #002200;">+=</span> <span style="color: #2400d9;">1</span>	<span style="color: #002200;">*</span> b2DebugDraw<span style="color: #002200;">::</span>e_pairBit;
	flags <span style="color: #002200;">+=</span> <span style="color: #2400d9;">1</span>	<span style="color: #002200;">*</span> b2DebugDraw<span style="color: #002200;">::</span>e_centerOfMassBit;
	m_debugDraw<span style="color: #002200;">-</span>&gt;SetFlags<span style="color: #002200;">&#40;</span>flags<span style="color: #002200;">&#41;</span>;
	world<span style="color: #002200;">-</span>&gt;SetDebugDraw<span style="color: #002200;">&#40;</span>m_debugDraw<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>The value of <em>flags</em> determines what kind of things you want to draw. You can set your own value of flags.</p>
<p><strong>Step 2:</strong> Add b<em>2World::DrawDebugData</em> in <em>draw</em> method. In Cocos2d, drawing stuff should be placed in draw method.</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> draw<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>super draw<span style="color: #002200;">&#93;</span>;
	glEnableClientState<span style="color: #002200;">&#40;</span>GL_VERTEX_ARRAY<span style="color: #002200;">&#41;</span>;
	world<span style="color: #002200;">-</span>&gt;DrawDebugData<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
	glDisableClientState<span style="color: #002200;">&#40;</span>GL_VERTEX_ARRAY<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>All done!</p>
<p><img class="alignnone" title="screenshot" src="http://farm3.static.flickr.com/2485/3809804893_5a33c1d83a_m.jpg" alt="" width="125" height="240" /></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Download</strong>: You can download the source codes from <a href="http://iphonedev.net/files/Box2dBouncingBall3.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iphonedev.net/2009/08/10/how-to-use-debugdraw-of-box2d-with-cocos2d/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Implement Grabbing a Sprite with Cocos2d and Box2d</title>
		<link>http://iphonedev.net/2009/08/05/how-to-grab-a-sprite-with-cocos2d-and-box2d/</link>
		<comments>http://iphonedev.net/2009/08/05/how-to-grab-a-sprite-with-cocos2d-and-box2d/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 05:30:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://iphonedev.net/?p=81</guid>
		<description><![CDATA[With Box2d,  it&#8217;s not difficult to implement an app in which we can grab a sprite with touches. The core function we should use is called mouse joint. In this article, I want to show the basic ideas and steps of implementation. Note: this example is based on one of my previous articles &#8211; Cocos2d Example [...]]]></description>
			<content:encoded><![CDATA[<p>With Box2d,  it&#8217;s not difficult to implement an app in which we can grab a sprite with touches. The core function we should use is called <em>mouse joint</em>. In this article, I want to show the basic ideas and steps of implementation. Note: this example is based on one of my previous articles &#8211; <a href="http://iphonedev.net/2009/07/12/cocos2d-example-box2d/">Cocos2d Example &#8211; Box2d</a>. The only difference is I moved the codes regarding to the sprite ball from <em>MyScene </em>to <em>BallLayer</em>.</p>
<p><span id="more-81"></span><strong>Step 1</strong>: Enable the touch. Add the following line of code into the init function of BallLayer.</p>
<p>isTouchEnabled = YES;</p>
<p><strong>Step 2</strong>:  Response the <em>touch begin event</em> by implementing <strong>ccTouchesBegan </strong>method. In this method, we first need to use the touch position (Note: a coordinate and unit conversion is required) to construct a very small area (the touch position is within this small area). Then we find all the shapes that intersect with this small area using <a href="http://box2d.org/manual.html#d0e544">AABB queries</a> (<strong>b2World::Query</strong>). If such shapes exist, we should get their associated bodies and test whether the body is not static and the touch position is inside the body. The body which is not static and contain the touch position will be selected to create a mouse joint. The codes are as follows:</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>ccTouchesBegan<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>
   UITouch<span style="color: #002200;">*</span> myTouch <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>touches anyObject<span style="color: #002200;">&#93;</span>;
   CGPoint location <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>myTouch locationInView<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>myTouch view<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
   location <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span>convertCoordinate<span style="color: #002200;">:</span>location<span style="color: #002200;">&#93;</span>;
   m_mouseWorld.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>;
   <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>m_mouseJoint <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: #a61390;">return</span>;
   <span style="color: #002200;">&#125;</span>
   b2AABB aabb;
   b2Vec2 d;
   d.Set<span style="color: #002200;">&#40;</span>0.001f, 0.001f<span style="color: #002200;">&#41;</span>;
   aabb.lowerBound <span style="color: #002200;">=</span> m_mouseWorld <span style="color: #002200;">-</span> d;
   aabb.upperBound <span style="color: #002200;">=</span> m_mouseWorld <span style="color: #002200;">+</span> d;
   <span style="color: #a61390;">const</span> int32 k_maxCount <span style="color: #002200;">=</span> <span style="color: #2400d9;">10</span>;
   b2Shape<span style="color: #002200;">*</span> shapes<span style="color: #002200;">&#91;</span>k_maxCount<span style="color: #002200;">&#93;</span>;
   int32 count <span style="color: #002200;">=</span> world<span style="color: #002200;">-</span>&gt;Query<span style="color: #002200;">&#40;</span>aabb, shapes, k_maxCount<span style="color: #002200;">&#41;</span>;
   b2Body<span style="color: #002200;">*</span> nbody <span style="color: #002200;">=</span> <span style="color: #a61390;">NULL</span>;
   <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>int32 i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; count; <span style="color: #002200;">++</span>i<span style="color: #002200;">&#41;</span> 	<span style="color: #002200;">&#123;</span>
     b2Body<span style="color: #002200;">*</span> shapeBody <span style="color: #002200;">=</span> shapes<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span><span style="color: #002200;">-</span>&gt;GetBody<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
     <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>shapeBody<span style="color: #002200;">-</span>&gt;IsStatic<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> <span style="color: #a61390;">false</span> <span style="color: #002200;">&amp;&amp;</span> shapeBody<span style="color: #002200;">-</span>&gt;GetMass<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> &gt; 0.0f<span style="color: #002200;">&#41;</span>
     <span style="color: #002200;">&#123;</span>
          bool inside <span style="color: #002200;">=</span> shapes<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span><span style="color: #002200;">-</span>&gt;TestPoint<span style="color: #002200;">&#40;</span>shapeBody<span style="color: #002200;">-</span>&gt;GetXForm<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>, m_mouseWorld<span style="color: #002200;">&#41;</span>;
          <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>inside<span style="color: #002200;">&#41;</span>
          <span style="color: #002200;">&#123;</span>
              nbody <span style="color: #002200;">=</span> shapes<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span><span style="color: #002200;">-</span>&gt;GetBody<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
              <span style="color: #a61390;">break</span>;
           <span style="color: #002200;">&#125;</span>
     <span style="color: #002200;">&#125;</span>
   <span style="color: #002200;">&#125;</span>
   <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>nbody<span style="color: #002200;">&#41;</span>
   <span style="color: #002200;">&#123;</span>
      b2MouseJointDef md;
      md.body1 <span style="color: #002200;">=</span> world<span style="color: #002200;">-</span>&gt;GetGroundBody<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
      md.body2 <span style="color: #002200;">=</span> nbody;
      md.target <span style="color: #002200;">=</span> m_mouseWorld;
<span style="color: #6e371a;">#ifdef TARGET_FLOAT32_IS_FIXED</span>
      md.maxForce <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>nbody<span style="color: #002200;">-</span>&gt;GetMass<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> &lt; <span style="color: #2400d9;">16.0</span><span style="color: #002200;">&#41;</span>? <span style="color: #002200;">&#40;</span>1000.0f <span style="color: #002200;">*</span> nbody<span style="color: #002200;">-</span>&gt;GetMass<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">:</span> float32<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">16000.0</span><span style="color: #002200;">&#41;</span>;
<span style="color: #6e371a;">#else</span>
      md.maxForce <span style="color: #002200;">=</span> 1000.0f <span style="color: #002200;">*</span> nbody<span style="color: #002200;">-</span>&gt;GetMass<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #6e371a;">#endif</span>
      m_mouseJoint <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>b2MouseJoint<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>world<span style="color: #002200;">-</span>&gt;CreateJoint<span style="color: #002200;">&#40;</span><span style="color: #002200;">&amp;</span>md<span style="color: #002200;">&#41;</span>;
      nbody<span style="color: #002200;">-</span>&gt;WakeUp<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
   <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><strong>Step 3</strong>: Response the <em>touch cancelled event</em> by implementing <strong>ccTouchesCancelled </strong>method. In this method, the created mouse joint is destroyed.</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>ccTouchesCancelled<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: #a61390;">if</span> <span style="color: #002200;">&#40;</span>m_mouseJoint<span style="color: #002200;">&#41;</span>
   <span style="color: #002200;">&#123;</span>
      world<span style="color: #002200;">-</span>&gt;DestroyJoint<span style="color: #002200;">&#40;</span>m_mouseJoint<span style="color: #002200;">&#41;</span>;
      m_mouseJoint <span style="color: #002200;">=</span> <span style="color: #a61390;">NULL</span>;
   <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><strong>Step 4</strong>: Response the <em>touch move event</em> by implementing <strong>ccTouchesMoved </strong>method. Get the new touch position, then update the position of the joint bodies (<strong>b2MouseJoint::SetTarget</strong>).</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>ccTouchesMoved<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>
   UITouch<span style="color: #002200;">*</span> myTouch <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>touches anyObject<span style="color: #002200;">&#93;</span>;
   CGPoint location <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>myTouch locationInView<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>myTouch view<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
   location <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span>convertCoordinate<span style="color: #002200;">:</span>location<span style="color: #002200;">&#93;</span>;
   m_mouseWorld.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>;
&nbsp;
   <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>m_mouseJoint<span style="color: #002200;">&#41;</span>
   <span style="color: #002200;">&#123;</span>
      m_mouseJoint<span style="color: #002200;">-</span>&gt;SetTarget<span style="color: #002200;">&#40;</span>m_mouseWorld<span style="color: #002200;">&#41;</span>;
   <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>All done!</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p><strong>Download</strong>: You can download the source codes from <a href="http://iphonedev.net/files/Box2dBouncingBall1.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iphonedev.net/2009/08/05/how-to-grab-a-sprite-with-cocos2d-and-box2d/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>How to Change the Icon of a Project Template</title>
		<link>http://iphonedev.net/2009/07/31/how-to-change-the-icon-of-a-project-template/</link>
		<comments>http://iphonedev.net/2009/07/31/how-to-change-the-icon-of-a-project-template/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 12:48:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://iphonedev.net/?p=75</guid>
		<description><![CDATA[In last article, I presented how to create a Cocos2d project template. In this article, I will show you how to change the icon of a project template. It is a very easy task. Get into the folder of the project template you want to change the icon. Right click the file ___PROJECTNAME___.xcodeproj. You will [...]]]></description>
			<content:encoded><![CDATA[<p>In last <a href="http://iphonedev.net/2009/07/29/how-to-create-your-own-cocos2d-project-template/">article</a>, I presented how to create a Cocos2d project template. In this article, I will show you how to change the icon of a project template. It is a very easy task.</p>
<p><span id="more-75"></span>Get into the folder of the project template you want to change the icon. Right click the file <em>___PROJECTNAME___.xcodeproj</em>. You will see the following menu:</p>
<p><img class="alignnone" title="menu" src="http://farm4.static.flickr.com/3459/3775047662_b4d57de9ab_m.jpg" alt="" width="237" height="240" /></p>
<p>Select &#8220;Show Package Contents&#8221;. A window which contains some files shows up:</p>
<p><img class="alignnone" title="window" src="http://farm3.static.flickr.com/2503/3775053310_deb92c09fe.jpg" alt="" width="500" height="342" /></p>
<p>What you need to do here is just using your icon to replace the existing icon <em>Templateicon.icns</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iphonedev.net/2009/07/31/how-to-change-the-icon-of-a-project-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Create Your Own Cocos2d Project Template</title>
		<link>http://iphonedev.net/2009/07/29/how-to-create-your-own-cocos2d-project-template/</link>
		<comments>http://iphonedev.net/2009/07/29/how-to-create-your-own-cocos2d-project-template/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 06:37:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://iphonedev.net/?p=65</guid>
		<description><![CDATA[In this article, I will present how to create your own Cocos2d project template. The version of Cocos2d is 0.8. The approach used in this article can also be applied when creating the project template using other static libraries. Step 1: Download the Cocos2d library from here. Untar the file, then move the folder cocos2d-iphone-0.8 [...]]]></description>
			<content:encoded><![CDATA[<p>In this article, I will present how to create your own Cocos2d project template. The version of Cocos2d is 0.8. The approach used in this article can also be applied when creating the project template using other static libraries.</p>
<p><span id="more-65"></span><strong>Step 1</strong>: Download the Cocos2d library from <a href="http://www.cocos2d-iphone.org/download">here</a>. Untar the file, then move the folder <em>cocos2d-iphone-0.8</em> to <em>/Developer/Library</em>. For convenience in following steps, we first add a source entry in <em>xcode Preferences</em> as follows:</p>
<p><em><img class="alignnone" title="path" src="http://farm3.static.flickr.com/2614/3771519260_9c05d8e65c.jpg" alt="" width="500" height="328" /><br />
</em></p>
<p><strong>Step 2</strong>: Make a <em>copy</em> of Window-Based Application Template and name it with &#8220;<em>My Cocos2d Application</em>&#8220;. On my desktop, Window-Based Application Template locates in folder <em>/Developer/Platforms/iphoneos.platform/developer/library/xcode/project templates/application. </em>Place the copied template <em>My  Cocos2d Application</em> in the same folder.</p>
<p><strong>Step 3</strong>: Get into the folder <em>My Cocos2d Application</em>, and open the file <em>___PROJECTNAME___.xcodeproj</em>. Delete <em>MainWindow.xib</em> from the Resources group because Cocos2d project doesn&#8217;t need this nib file.</p>
<p><strong>Step 4</strong>: Edit <em>Info.plist</em> file. Remove entry &#8220;Main nib file base name&#8221;. Add a UIStatusBarHidden entry to hide status bar.</p>
<p><img class="alignnone" title="statusbar" src="http://farm3.static.flickr.com/2488/3771575270_569394012f.jpg" alt="" width="500" height="355" /></p>
<p><strong>Step 5</strong>: Add some required libraries. Double Click the target &#8220;___PROJECTNAME___&#8221; to open Target Info dialog. Click &#8220;+&#8221; button under  Linked Libraries. Add the libraries shown below:</p>
<p><img class="alignnone" title="libraries" src="http://farm3.static.flickr.com/2462/3771532524_af313ee8d2.jpg" alt="" width="316" height="500" /></p>
<p><strong>Step 6</strong>: Go to the folder of Cocos2d library <em>/Developer/Library</em>/<em>cocos2d-iphone-0.8</em>,  drag and drop the file <strong>cocos2d-iphone.xcodeproj</strong> under &#8220;___PROJECTNAME___&#8221; on the sidebar. Please <em>don&#8217;t</em> check &#8220;Copy items into destination group&#8217;s fold (if needed)&#8221;. Select &#8220;Reletive to COCOS2D_SRC&#8221; as the Reference Type. The screen shot is shown below:</p>
<p><img class="alignnone" title="cocos2d" src="http://farm4.static.flickr.com/3563/3770736485_4de2e1b90f.jpg" alt="" width="400" height="374" /></p>
<p>Then what we need to do is ticking the required Cocos2d static libraries (libChipmunk.a, libcocos2d.a, libbox2d.a) as shown below:</p>
<p><img class="alignnone" title="cocos2d libraries" src="http://farm4.static.flickr.com/3451/3771544236_1dda7847f6.jpg" alt="" width="500" height="355" /></p>
<p><strong>Step 7</strong>: Add Dependencies. Double click the target &#8220;___PROJECTNAME___&#8221; to open Target Info dialog. Click &#8220;+&#8221; button under Direct Dependencies. Add box2d, Chipmunk, cocos2d to the dependency list.</p>
<p><img class="alignnone" title="dependency" src="http://farm4.static.flickr.com/3279/3770751915_fb1ee411db_o.jpg" alt="" width="213" height="297" /></p>
<p><strong>Step 8</strong>: Add &#8220;<em>User Header Search Paths</em>&#8220;. Double click &#8220;___PROJECTNAME___&#8221; to open project Info dialog. Under <em>Build Tab</em>, double click &#8220;User Header Search Paths&#8221; and you will see the following dialog. Add the same path shown in the picture.</p>
<p><img class="alignnone" title="path" src="http://farm4.static.flickr.com/3428/3771549436_5dc319012e.jpg" alt="" width="500" height="494" /></p>
<p><strong>Step 9</strong>: Updating the codes. The codes actually depend on your requirements.<em> </em>You can download an example of files <em>main.m</em> and <em>___PROJECTNAMEASIDENTIFIER___AppDelegate.m</em> from <a href="http://iphonedev.net/files/files.zip">here</a>. <strong>Note</strong>: updating the main function in main.m is necessary.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">int</span> main<span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> argc, <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>argv<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSAutoreleasePool</span> <span style="color: #002200;">*</span>pool <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSAutoreleasePool</span> new<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">int</span> retVal <span style="color: #002200;">=</span> UIApplicationMain<span style="color: #002200;">&#40;</span>argc, argv, <span style="color: #a61390;">nil</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;___PROJECTNAMEASIDENTIFIER___AppDelegate&quot;</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#91;</span>pool release<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> retVal;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><strong>Step 10</strong>: Add <a href="http://iphonedev.net/files/fps_images.png">fps_images.png</a> to Resources.<em> </em></p>
<p>All done! Now you can create a new Cocos2d project with the project template you just created.</p>
]]></content:encoded>
			<wfw:commentRss>http://iphonedev.net/2009/07/29/how-to-create-your-own-cocos2d-project-template/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>How to Install Cocos2d 0.8 Project Template</title>
		<link>http://iphonedev.net/2009/07/28/how-to-install-cocos2d-08-project-template/</link>
		<comments>http://iphonedev.net/2009/07/28/how-to-install-cocos2d-08-project-template/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 08:37:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://iphonedev.net/?p=55</guid>
		<description><![CDATA[Step 1: Download Cocos2d 0.8 Beta project template from here. This template works well for 0.8 beta, rc, and final version. Step 2: Unzip the downloaded file in Step 1. Move the the folder to project templates folder. On my desktop, this folder&#8217;s location is /Developer/Platforms/iphoneos.platform/developer/library/xcode/project templates/application. Step 3: Download Cocos2d Library from here. Untar [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Step 1</strong>: Download Cocos2d 0.8 Beta project template from <a href="http://github.com/tjweir/cocos2d-application/tree/master">here</a>. This template works well for 0.8 beta, rc, and final version.</p>
<p><span id="more-55"></span><strong>Step 2</strong>: Unzip the downloaded file in Step 1. Move the the folder to project templates folder. On my desktop, this folder&#8217;s location is <em>/Developer/Platforms/iphoneos.platform/developer/library/xcode/project templates/application.</em></p>
<p><strong>Step 3</strong>: Download <strong>Cocos2d</strong> Library from <a href="http://www.cocos2d-iphone.org/download">here</a>. Untar the file, then move the folder to<em> /Developer/Library.</em></p>
<p><strong>Step 4</strong>:<em> </em>Under <em>xcode &#8211; Preferences &#8211; Source Trees</em>, add a source record. You can set the setting name with <em>COCOS2D_SRC</em>. The path is the location of Cocos2d Library, which is<em> /Developer/Library/cocos2d-iphone-0.8/</em></p>
<p><strong>Step 5:</strong><em> </em>Now, you can create a Cocos2d project in xcode. The Dependency and Linked Library of <em>cocos2d</em> and <em>Chipmunk</em> have been added to the project by default. <em></em></p>
<p><strong>Step 6:</strong><em> </em>If you want to use other libraries (e.g., <strong>Box2d</strong>, etc) integrated in cocos2d, please follow the steps below.</p>
<p><strong>Step 7:</strong> Add Direct Dependency. After a new project is created, right click the target and select <em>Get Info</em>. Under <em>General</em>, click the &#8216;+&#8217; button of Direct Dependencies. You will see a list of target dependencies, just add the dependency you want (e.g., <em>box2d</em>). This step can guarantee the static library always exists (if not, the compiler will build one).</p>
<p><span style="text-decoration: line-through;"><strong>Step 8: </strong>Build the project. The dependency you added in <em>Step 7</em> was built up in this step.</span></p>
<p><strong>Step 9:</strong> Add the <span style="text-decoration: line-through;">Linked</span> Static Library to the project. <span style="text-decoration: line-through;">built up in <em>Step 8</em></span>. <span style="text-decoration: line-through;">Right click the target and select <em>Get Info</em> again. Under General, click the &#8216;+&#8217; button of Linked Libraries. In the popped-up library list, you can&#8217;t  find the library built up in Step 8. You need to click &#8220;<strong>Add Other</strong>&#8221; button. Then you need to find the library yourself. The library just built up is under the folder <em>/Developer/Library/cocos2d-iphone-0.8/build/Debug-iphonesimulator</em>. Select the library you just built up (e.g., <em>libbox2d.a</em>). Now, the library has been added to the project.</span> Click cocos2d-iphone.xcodeproj on the left side, find the target (i.e., Static Library) you want to add from the file list on the right hand side. Just simply tick the target (e.g., libbox2d.a) as shown below:</p>
<p><img class="alignnone" title="example" src="http://farm3.static.flickr.com/2401/3770263425_161ac40cf7.jpg" alt="" width="500" height="344" /></p>
<p>All done!</p>
<p><em>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</em></p>
<p><strong>Update</strong>: In the future, if a newer version of Cocos2d is released, what you need to do is just to replace the old Cocos2d library with the new one. You don&#8217;t need to update the template.<em> </em>It&#8217;s very easy, isn&#8217;t it?<em><br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://iphonedev.net/2009/07/28/how-to-install-cocos2d-08-project-template/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Cocos2d &#8211; Contact Filter in Box2d</title>
		<link>http://iphonedev.net/2009/07/27/cocos2d-contact-filter-in-box2d/</link>
		<comments>http://iphonedev.net/2009/07/27/cocos2d-contact-filter-in-box2d/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 02:51:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone Development]]></category>

		<guid isPermaLink="false">http://iphonedev.net/?p=48</guid>
		<description><![CDATA[In Box2d, we can easily define what kind of shapes can collide with each other. The shapes that do not collide with each other will overlap. Generally, there are three ways to achieve this: Method 1 &#8211; Define collision groups with group index. The shapes which are in the same group and have positive (negative) [...]]]></description>
			<content:encoded><![CDATA[<p>In Box2d, we can easily define what kind of shapes can collide with each other. The shapes that do not collide with each other will overlap. Generally, there are three ways to achieve this:</p>
<p><span id="more-48"></span><strong>Method 1</strong> &#8211; Define collision groups with group index. The shapes which are in the same group and have positive (negative) index will always (never) collide with each other. This is the simplest way to define what kind of shapes can collide with each other, but it has limitations. Collisions between the shapes which are in the different groups need to be filtered in other ways.</p>
<p><em>Example</em>: In our previous <a href="http://iphonedev.net/2009/07/12/cocos2d-example-box2d/">example</a>, if we want the ball doesn&#8217;t collide with the ground, we can just add the following codes in the initialization:</p>
<p>groundShapeDef.filter.groupIndex = -1;</p>
<p>ballShapeDef.filter.groupIndex = -1;</p>
<p><strong>Method 2</strong> &#8211; Define category and mask bits. This method is a little more complex than Method 1, but it can filter the collision not only between the shapes in the same category, but also between the shapes in different categories.</p>
<p><em>Example</em>:</p>
<p>groundShapeDef.filter.categoryBits = 0&#215;0002;<br />
groundShapeDef.filter.maskBits = 0&#215;0008;</p>
<p>ballShapeDef.filter.categoryBits = 0&#215;0008;<br />
ballShapeDef.filter.maskBits = 0&#215;002;</p>
<p>With the codes above, the ball will collide with the ground, but the balls will not collide with each other.</p>
<p><strong>Method 3</strong> &#8211; Implementing our own contact filtering function. We need to derive from class <strong><tt class="classname">b2ContactFilter</tt></strong> and implement the method <strong>ShouldCollide</strong>. From the <a href="http://box2d.org/manual.html#d0e1359">documentation</a>, you can see the default behavior of method ShouldCollide. It can be seen that group filtering (Method 1) has higher precedence than category filtering (Method 2).</p>
]]></content:encoded>
			<wfw:commentRss>http://iphonedev.net/2009/07/27/cocos2d-contact-filter-in-box2d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
