<?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.mitchallen.com</title>
	<atom:link href="http://mitchallen.com/iphone/feed" rel="self" type="application/rss+xml" />
	<link>http://mitchallen.com/iphone</link>
	<description>random notes on iPhone development</description>
	<lastBuildDate>Sat, 30 Jan 2010 00:37:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Getting Cocos2D to work with the iPad</title>
		<link>http://mitchallen.com/iphone/archives/506</link>
		<comments>http://mitchallen.com/iphone/archives/506#comments</comments>
		<pubDate>Fri, 29 Jan 2010 17:53:37 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[game engines]]></category>
		<category><![CDATA[Cocos2D]]></category>
		<category><![CDATA[iPad]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=506</guid>
		<description><![CDATA[If you look at the source code for Cocos2D, you will find this little note in Director.m:

	// XXX it's using hardcoded values.
	// What if the the screen size changes in the future?

This isn&#8217;t a problem if you want to run your iPhone app in what I call &#8220;boxed&#8221; mode &#8211; in it&#8217;s native resolution on [...]]]></description>
			<content:encoded><![CDATA[<p>If you look at the source code for Cocos2D, you will find this little note in <strong>Director.m</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">	<span style="color: #11740a; font-style: italic;">// XXX it's using hardcoded values.</span>
	<span style="color: #11740a; font-style: italic;">// What if the the screen size changes in the future?</span></pre></div></div>

<p>This isn&#8217;t a problem if you want to run your iPhone app in what I call &#8220;boxed&#8221; mode &#8211; in it&#8217;s native resolution on the center of the iPad screen.  But if you want to start working on your code in the native iPad resolution of 1024 x 768 you will need to get the latest build (SVN r1753).</p>
<p>See this thread:  <a href="http://www.cocos2d-iphone.org/forum/topic/4108">http://www.cocos2d-iphone.org/forum/topic/4108</a></p>
<p><strong>Screenshot</strong></p>
<p>Note that the controls are now properly scaled.  Obviously one pending issue is substituting a background graphic with the proper resolution.</p>
<div id="attachment_518" class="wp-caption alignnone" style="width: 310px"><a href="http://mitchallen.com/iphone/wp-content/uploads/2010/01/iPadSim5.png"><img src="http://mitchallen.com/iphone/wp-content/uploads/2010/01/iPadSim5-300x247.png" alt="" title="iPadSim5" width="300" height="247" class="size-medium wp-image-518" /></a><p class="wp-caption-text">iPad app using hacked Cocos2D engine</p></div>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/506/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hitler responds to the iPad (YouTube)</title>
		<link>http://mitchallen.com/iphone/archives/503</link>
		<comments>http://mitchallen.com/iphone/archives/503#comments</comments>
		<pubDate>Fri, 29 Jan 2010 17:32:57 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[funny]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=503</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/lQnT0zp8Ya4&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/lQnT0zp8Ya4&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/503/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The new iPad Simulator</title>
		<link>http://mitchallen.com/iphone/archives/482</link>
		<comments>http://mitchallen.com/iphone/archives/482#comments</comments>
		<pubDate>Thu, 28 Jan 2010 17:00:29 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[IDE]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[simulator]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=482</guid>
		<description><![CDATA[Below are some screenshots of the new iPad simulator.  To use it you will need to install the latest Beta SDK that was announced yesterday, along with the announcement of the new iPad.
To get your app to work in the iPad simulator you will need to do a couple of things:

Switch your build to: [...]]]></description>
			<content:encoded><![CDATA[<p>Below are some screenshots of the new iPad simulator.  To use it you will need to install the latest Beta SDK that was announced yesterday, <strong><a href="http://events.apple.com.edgesuite.net/1001q3f8hhr/event/index.html">along with the announcement of the new iPad</a></strong>.</p>
<p>To get your app to work in the iPad simulator you will need to do a couple of things:</p>
<ol>
<li>Switch your build to: <strong>Simulator 3.2 | Debug</strong></li>
<li>When your app is running in the simulator, select: <strong>Hardware / Device / iPad</strong></li>
</ol>
<p><strong>Universal Applications</strong></p>
<p>The above was just to get you started and see your app running on the iPad in what I call a &#8220;boxed&#8221; version.  Ideally you would want to work towards what Apple refers to as a &#8220;<strong>universal application</strong>&#8221; &#8211; that is optimized for whichever device it happens to be running on.  Though Apple notes that universal binaries won&#8217;t be available in the initial seed release of 3.2.   See the Beta doc for more info.</p>
<p><strong>Creating a true iPad target</strong></p>
<p>To turn an existing app into a native iPad app, right-click on your target and select: <strong>Transition</strong>.  Then change your target executable to the new iPad version.  Note that right-clicking on the iPad target and selecting<strong> Build &#8220;&#8230;-iPad&#8221; Start</strong> doesn&#8217;t work if the wrong target is selected in the IDE dropdown.  Your app will still appear as a boxed iPhone app.  Once you have it running as a true iPad app, if you hard-coded a few things based on the original iPhones resolution, you&#8217;ll have some cleaning up to do.</p>
<p><strong>Just one more thing &#8230;</strong></p>
<p>When working on a 17&#8243; MacBook Pro, I found that the simulator crowds the dock on the bottom of the desktop.  So you may want to consider moving your dock to the side.</p>
<hr size="1" />

<a href='http://mitchallen.com/iphone/archives/482/ipadsim1' title='iPadSim1'><img width="150" height="150" src="http://mitchallen.com/iphone/wp-content/uploads/2010/01/iPadSim1-150x150.png" class="attachment-thumbnail" alt="Default iPad Simulator in Landscape Mode" title="iPadSim1" /></a>
<a href='http://mitchallen.com/iphone/archives/482/ipadsim2' title='iPadSim2'><img width="150" height="150" src="http://mitchallen.com/iphone/wp-content/uploads/2010/01/iPadSim2-150x150.png" class="attachment-thumbnail" alt="iPad Simulator running standard iPhone app - notice 2x option in the lower right corner" title="iPadSim2" /></a>
<a href='http://mitchallen.com/iphone/archives/482/ipadsim3' title='iPadSim3'><img width="150" height="150" src="http://mitchallen.com/iphone/wp-content/uploads/2010/01/iPadSim3-150x150.png" class="attachment-thumbnail" alt="iPad Simulator running standard iPhone app at 2x resolution" title="iPadSim3" /></a>
</p>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/482/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Links for when your iPhone app crashes</title>
		<link>http://mitchallen.com/iphone/archives/469</link>
		<comments>http://mitchallen.com/iphone/archives/469#comments</comments>
		<pubDate>Mon, 18 Jan 2010 23:57:01 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[IDE]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[crash]]></category>
		<category><![CDATA[dSYM]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[symbolicatecrash]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=469</guid>
		<description><![CDATA[As I&#8217;ve mentioned before, my background is in software testing. I&#8217;ve made a career out of making software crash. You may think your app is flawless &#8211; that it can&#8217;t possibly crash. Wait until you hand it off to someone else. If that person is sitting right next to you, you may be able to [...]]]></description>
			<content:encoded><![CDATA[<p>As I&#8217;ve mentioned before, my background is in software testing. I&#8217;ve made a career out of making software crash. You may think your app is flawless &#8211; that it can&#8217;t possibly crash. Wait until you hand it off to someone else. If that person is sitting right next to you, you may be able to walk through the steps in the debugger in the simulator and figure out what happened. But if that person is someone who downloaded your app from iTunes &#8211; or worse, <em>a whole lot of people</em> who bought your app from iTunes &#8211; and it only crashes on the actual device &#8211; then things will get a lot more complicated.</p>
<p><strong>Reproducing a Crash</strong></p>
<p>When a professional software tester, such as myself, crashes a product our job is to try to reproduce the crash and write up detailed steps on how we did it. But when the product crashes in the field customers aren&#8217;t so helpful. Quite often they will tell you that they have no idea how the product crashed, or they don&#8217;t have the patience to try to reproduce it. Hopefully you will at least be able to get them to give you a log. What log is that you may wonder? Is this something that you build in to your product? It could be &#8211; but I&#8217;m talking about the crash log that the iPhone will (hopefully) generate automatically and replicate to their desktop via iTunes.</p>
<p>A great article on where the crash logs are located and how to process them can be found here:</p>
<p><a href="http://www.anoshkin.net/blog/2008/09/09/iphone-crash-logs/">http://www.anoshkin.net/blog/2008/09/09/iphone-crash-logs/</a></p>
<p>In that article you will find out how to use a very useful tool: <strong>symbolicatecrash</strong> .  Pay close attention to the instructions on generating and keeping a <strong>dSYM </strong>file when you release an app.  </p>
<p>The article also contains a few useful links:  </p>
<ul>
<li><a href="http://developer.apple.com/tools/xcode/symbolizingcrashdumps.html">http://developer.apple.com/tools/xcode/symbolizingcrashdumps.html</a></li>
<li><a href="http://developer.apple.com/mac/library/technotes/tn2004/tn2123.html">http://developer.apple.com/mac/library/technotes/tn2004/tn2123.html</a></li>
<li><a href="http://furbo.org/2008/08/08/symbolicatifination/">http://furbo.org/2008/08/08/symbolicatifination/</a></li>
</ul>
<p>For debugging apps you may find these articles useful as well:</p>
<ul>
<li><a href="http://cocoawithlove.com/2008/10/debugging-tips-for-objective-c.html">http://cocoawithlove.com/2008/10/debugging-tips-for-objective-c.html</a></li>
<li><a href="http://siliconbased.wordpress.com/2009/08/19/iphone-sdk-gdb-debugging-cheat-sheet/">http://siliconbased.wordpress.com/2009/08/19/iphone-sdk-gdb-debugging-cheat-sheet/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/469/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Touching Sprites in Cocos2D</title>
		<link>http://mitchallen.com/iphone/archives/424</link>
		<comments>http://mitchallen.com/iphone/archives/424#comments</comments>
		<pubDate>Fri, 30 Oct 2009 14:49:01 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[game engines]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Cocos2D]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=424</guid>
		<description><![CDATA[I&#8217;ve added code to my Cocos2D test harness to show you how to handle coordinating touch events among multiple sprites.  The class I created to manage the sprites was based on code that I found in this article: 
http://juanmunozar.blogspot.com/2009/02/cocos2d-iphone-dynamically-touch.html  
If you have git installed you can retrieve the latest copy of the project [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve added code to my Cocos2D test harness to show you how to handle coordinating touch events among multiple sprites.  The class I created to manage the sprites was based on code that I found in this article: </p>
<p><a href="http://juanmunozar.blogspot.com/2009/02/cocos2d-iphone-dynamically-touch.html">http://juanmunozar.blogspot.com/2009/02/cocos2d-iphone-dynamically-touch.html</a>  </p>
<p>If you have git installed you can retrieve the latest copy of the project via the instructions at the end of this article.</p>
<p><strong>Getting Started</strong></p>
<p>In order to complete this tutorial you first you need to go through the steps of my posts:</p>
<ul>
<li><a href="http://mitchallen.com/iphone/archives/371">Creating a Cocos2D Layer Test Harness</a></li>
<li><a href="http://mitchallen.com/iphone/archives/304">Getting Started with the Cocos2d Game Engine</a></li>
</ul>
<p>If you are using <strong>git</strong> you may want to save and tag the original project and try expanding on it here in a new branch.</p>
<p><strong>Graphic Files</strong></p>
<p>For this tutorial you will need to copy some additional graphic files from the cocos2d-iphone sample folders to your projects Resources folder:</p>
<ul>
<li>Resources/Images/<strong>blocks</strong>.png</li>
</ul>
<p><strong>Classes / TestScene.m</strong></p>
<p>First, you need to add a string identifying the new test layer to the <strong>transitions</strong> array in <strong>TestScene.m</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>transitions<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">=</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;TestLayer01&quot;</span>,
	<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;TestLayer02&quot;</span>,
	<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;TestLayer03&quot;</span>,
<span style="color: #002200;">&#125;</span>;</pre></div></div>

<p><strong>Classes / mcaTouchSprite.h</strong></p>
<p>Here I introduce a new class based on code in the referenced article.  As you can see I&#8217;ve trimmed it down quite a lot to demo just the basics.</p>
<p>Something that you may not have seen before is the &#8220;SEL&#8221; property type.  Think of it as a function pointer.  It lets you dynamically assign a function to call when a sprite is touched.  You will see how this is done later in the code.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  mcaTouchSprite.h</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 10/6/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// References:</span>
<span style="color: #11740a; font-style: italic;">// http://juanmunozar.blogspot.com/2009/02/cocos2d-iphone-dynamically-touch.html</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// See these links for additional info and credit:</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/424</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &lt;UIKIt/UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &quot;cocos2d.h&quot;</span>
<span style="color: #6e371a;">#import &quot;chipmunk.h&quot;</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">@interface</span> mcaTouchSprite <span style="color: #002200;">:</span> Sprite <span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #a61390;">@private</span>
&nbsp;
	<span style="color: #a61390;">SEL</span>		__onTouchBegan;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark properties</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">SEL</span> onTouchBegan;
&nbsp;
<span style="color: #6e371a;">#pragma mark class methods</span>
&nbsp;
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>allMySprites;
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> track<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>mcaTouchSprite <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>aSprite;
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> untrack<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>mcaTouchSprite <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>aSprite;
&nbsp;
<span style="color: #6e371a;">#pragma mark instance methods</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span> rect;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>Classes / mcaTouchSprite.m</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  mcaTouchSprite.m</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 10/6/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// See these links for additional info and credit:</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/424</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;mcaTouchSprite.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> mcaTouchSprite
&nbsp;
<span style="color: #a61390;">@synthesize</span> onTouchBegan <span style="color: #002200;">=</span> __onTouchBegan;
&nbsp;
<span style="color: #a61390;">static</span> <span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span>allMySprites <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
&nbsp;
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>allMySprites <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">@synchronized</span><span style="color: #002200;">&#40;</span>allMySprites<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>allMySprites <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>
            allMySprites <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
        <span style="color: #a61390;">return</span> allMySprites;
    <span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> <span style="color: #a61390;">nil</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span> rect <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">float</span> w <span style="color: #002200;">=</span> self.contentSize.width;
	<span style="color: #a61390;">float</span> h <span style="color: #002200;">=</span> self.contentSize.height;
	<span style="color: #a61390;">float</span> x <span style="color: #002200;">=</span> self.position.x <span style="color: #002200;">-</span> w<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>;
	<span style="color: #a61390;">float</span> y <span style="color: #002200;">=</span> self.position.y <span style="color: #002200;">-</span> h<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>;
	<span style="color: #a61390;">return</span> CGRectMake<span style="color: #002200;">&#40;</span>x,y,w,h<span style="color: #002200;">&#41;</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>track<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>mcaTouchSprite <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>aSprite <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">@synchronized</span><span style="color: #002200;">&#40;</span>allMySprites<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		NSUInteger i, count <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>allMySprites count<span style="color: #002200;">&#93;</span>;
		<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; count ; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
			mcaTouchSprite <span style="color: #002200;">*</span> obj 
				<span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>mcaTouchSprite <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>allMySprites objectAtIndex<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;
			<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>obj <span style="color: #002200;">==</span> aSprite<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
				<span style="color: #a61390;">return</span>;
			<span style="color: #002200;">&#125;</span>
		<span style="color: #002200;">&#125;</span>
&nbsp;
        <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>mcaTouchSprite allMySprites<span style="color: #002200;">&#93;</span> addObject<span style="color: #002200;">:</span>aSprite<span style="color: #002200;">&#93;</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>untrack<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>mcaTouchSprite <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>aSprite <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">@synchronized</span><span style="color: #002200;">&#40;</span>allMySprites<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>mcaTouchSprite allMySprites<span style="color: #002200;">&#93;</span> removeObject<span style="color: #002200;">:</span>aSprite<span style="color: #002200;">&#93;</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>dealloc <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>mcaTouchSprite untrack<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>Classes / mcaBoxSprite.h</strong></p>
<p>This is my first pass at creating a sprite that has some built in functionality.  In this case a <em>turn</em> method that lets you rotate the sprite on the screen through code.  To demo that touch events are actually being processed, the sprite will turn <em>n</em> degrees every time it is touched.  The method does that by adding the amount of degrees desired to self.rotation which it inherits from the base class.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  mcaCarSprite.h</span>
<span style="color: #11740a; font-style: italic;">//  Potholes_001_001</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 10/7/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// See these links for additional info and credit:</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/424</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;mcaTouchSprite.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> mcaBoxSprite <span style="color: #002200;">:</span> mcaTouchSprite <span style="color: #002200;">&#123;</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> turn<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span> n;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>Classes / mcaBoxSprite.m</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  mcaBoxSprite.m</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 10/7/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// See these links for additional info and credit:</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/424</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;mcaBoxSprite.h&quot;</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;math.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> mcaBoxSprite
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> turn<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span> n <span style="color: #002200;">&#123;</span> 
&nbsp;
	self.rotation <span style="color: #002200;">+=</span> n;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>Classes / MyTests.h</strong></p>
<p>Now you need to include references to the new header files and add the interface declaration for our new test layer to <strong>MyTests.h</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  MyTests.h</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/20/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// See these links for additional info and credit:</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/371</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/304</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/424</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;TestScene.h&quot;</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;mcaTouchSprite.h&quot;</span>
<span style="color: #6e371a;">#import &quot;mcaBoxSprite.h&quot;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">///////////////////////////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// Adding Test Layers to Test Game</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// When a  dervied TestLayer is added, you must add it's name to </span>
<span style="color: #11740a; font-style: italic;">// the NSString transitions array in TestScene.m for it to appear </span>
<span style="color: #11740a; font-style: italic;">// in the test game.</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">@interface</span> TestLayer01 <span style="color: #002200;">:</span> TestLayer
<span style="color: #002200;">&#123;</span><span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">@interface</span> TestLayer02 <span style="color: #002200;">:</span> TestLayer
<span style="color: #002200;">&#123;</span><span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #6e371a;">#define LAYER_03_BOXES	4</span>
&nbsp;
<span style="color: #a61390;">@interface</span> TestLayer03 <span style="color: #002200;">:</span> TestLayer
<span style="color: #002200;">&#123;</span>
	mcaBoxSprite <span style="color: #002200;">*</span>box<span style="color: #002200;">&#91;</span> LAYER_03_BOXES <span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>Classes / MyTests.m</strong></p>
<p>Finally, append the code for <strong>TestLayer03</strong> to MyTests.m.</p>
<p>Where as the previous layers did their setup in the <em>onEnter</em> method, here we do setup in the <em>init</em> method.</p>
<p>You will notice that we loop through a collection of box sprites, assigning the function pointer (<em>onTouchBegan</em>) to the method <em>touchBox</em> and flag the box sprite for touch tracking.  We also need to make sure <em>isTouchEnabled</em> is set to <strong>YES</strong>.  When <em>touchBox</em> is called, the <em>turn</em> method on the touched box is called &#8211; rotating the sprite.</p>
<p>Most of the main processing happens in the <em>ccTouchesBegan</em> method.  This method attempts to figure out which if any box sprite was called, then calls whatever method <em>onTouchBegan</em> is pointing to, passing in the object.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TestLayer03
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init <span style="color: #002200;">&#123;</span>
&nbsp;
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>self <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
		<span style="color: #11740a; font-style: italic;">//////////////////////////////</span>
		<span style="color: #11740a; font-style: italic;">// Add Boxes</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; LAYER_03_BOXES; i<span style="color: #002200;">++</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
			<span style="color: #11740a; font-style: italic;">// Copy blocks.png from Cocos2D resources.</span>
&nbsp;
			box<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span> <span style="color: #002200;">=</span> 
			  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>mcaBoxSprite spriteWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;blocks.png&quot;</span><span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span>;
&nbsp;
			box<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span>.onTouchBegan <span style="color: #002200;">=</span> <span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>touchBox<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span>;
&nbsp;
			<span style="color: #002200;">&#91;</span>mcaBoxSprite track<span style="color: #002200;">:</span>box<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
			<span style="color: #a61390;">float</span> bx <span style="color: #002200;">=</span> <span style="color: #2400d9;">50</span>;
			<span style="color: #a61390;">float</span> by <span style="color: #002200;">=</span> <span style="color: #2400d9;">50</span> <span style="color: #002200;">*</span> <span style="color: #002200;">&#40;</span><span style="color: #2400d9;">1</span> <span style="color: #002200;">+</span> i<span style="color: #002200;">&#41;</span>;
&nbsp;
			box<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span>.position <span style="color: #002200;">=</span> cpv<span style="color: #002200;">&#40;</span> bx, by <span style="color: #002200;">&#41;</span>;
&nbsp;
			box<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span>.scaleY <span style="color: #002200;">=</span> 0.5f;
			box<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span>.scaleX <span style="color: #002200;">=</span> 0.5f;
&nbsp;
			box<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span>.rotation <span style="color: #002200;">=</span> 0.0f;
&nbsp;
			<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span> box<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#125;</span>
&nbsp;
		<span style="color: #11740a; font-style: italic;">//////////////////////////</span>
		<span style="color: #11740a; font-style: italic;">// Enable interaction.</span>
&nbsp;
		isTouchEnabled <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;	<span style="color: #11740a; font-style: italic;">// To enable touching</span>
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #a61390;">return</span> self;
<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> onEnter
<span style="color: #002200;">&#123;</span>	
	<span style="color: #002200;">&#91;</span>super onEnter<span style="color: #002200;">&#93;</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> onExit
<span style="color: #002200;">&#123;</span>		
	<span style="color: #002200;">&#91;</span>super onExit<span style="color: #002200;">&#93;</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; LAYER_03_BOXES; i<span style="color: #002200;">++</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
		<span style="color: #002200;">&#91;</span>mcaBoxSprite untrack<span style="color: #002200;">:</span>box<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
<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> touchBox<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> theBox <span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>theBox turn<span style="color: #002200;">:</span> <span style="color: #2400d9;">10</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</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>
&nbsp;
    UITouch <span style="color: #002200;">*</span>touch <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>touches anyObject<span style="color: #002200;">&#93;</span>;
&nbsp;
	CGPoint 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> 
						<span style="color: #002200;">&#91;</span>touch locationInView<span style="color: #002200;">:</span>touch.view<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span> mySprites <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>mcaTouchSprite allMySprites<span style="color: #002200;">&#93;</span>;
    NSUInteger i, count <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>mySprites count<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// NSLog( @&quot;COUNT = %d&quot;, count );</span>
&nbsp;
    <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; count; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
        mcaTouchSprite <span style="color: #002200;">*</span> obj 
			<span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>mcaTouchSprite <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>mySprites objectAtIndex<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;
&nbsp;
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>CGRectContainsPoint<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>obj rect<span style="color: #002200;">&#93;</span>, location<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
            <span style="color: #11740a; font-style: italic;">// code here is only executed if obj has been touched</span>
			<span style="color: #11740a; font-style: italic;">// NSLog( @&quot;Sprite touched.&quot; );</span>
&nbsp;
			<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span>self respondsToSelector<span style="color: #002200;">:</span> obj.onTouchBegan <span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
				<span style="color: #002200;">&#91;</span>self 
					performSelector<span style="color: #002200;">:</span> obj.onTouchBegan 
					withObject<span style="color: #002200;">:</span> obj<span style="color: #002200;">&#93;</span>;
			<span style="color: #002200;">&#125;</span>
&nbsp;
			<span style="color: #a61390;">return</span> kEventHandled;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #a61390;">return</span> <span style="color: #a61390;">false</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</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>
&nbsp;
	<span style="color: #a61390;">return</span> <span style="color: #a61390;">false</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> dealloc
<span style="color: #002200;">&#123;</span>
	<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; LAYER_03_BOXES; i<span style="color: #002200;">++</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
		<span style="color: #002200;">&#91;</span>box<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span> release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> title
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Override the base classes title </span>
	<span style="color: #11740a; font-style: italic;">// that appears on the screen.</span>
&nbsp;
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Test Layer 03 - Touch&quot;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>References</strong></p>
<p><a href="http://juanmunozar.blogspot.com/2009/02/cocos2d-iphone-dynamically-touch.html">http://juanmunozar.blogspot.com/2009/02/cocos2d-iphone-dynamically-touch.html</a></p>
<p><strong>Git Clone</strong></p>
<p>If you have git installed, you can clone a copy of this project with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git clone git://github.com/mitchallen/TestGame.git</pre></div></div>

<p>I may add more code to the repository. So to get back to the original state of this tutorial, you will need to execute the following at the command line:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git checkout v300</pre></div></div>

<p>See previous articles for previous states.</p>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/424/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adobe Flash CS5 applications for iPhone &#8211; www.CS5.org</title>
		<link>http://mitchallen.com/iphone/archives/441</link>
		<comments>http://mitchallen.com/iphone/archives/441#comments</comments>
		<pubDate>Mon, 26 Oct 2009 11:30:02 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[IDE]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=441</guid>
		<description><![CDATA[
I noticed that I still get a lot of hits from sites containing old articles on Flash / ActionScript that I wrote.  I&#8217;m sure those people are wondering where the Flash stuff went.  I haven&#8217;t given up on Flash.  I just decided to make my main focus the iPhone.  In fact [...]]]></description>
			<content:encoded><![CDATA[<p><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/mpEUNqfk4rw&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/mpEUNqfk4rw&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object></p>
<p>I noticed that I still get a lot of hits from sites containing old articles on Flash / ActionScript that I wrote.  I&#8217;m sure those people are wondering where the Flash stuff went.  I haven&#8217;t given up on Flash.  I just decided to make my main focus the iPhone.  In fact in my spare time I&#8217;ve been working on porting some turtle graphics code that I wrote in ActionScript to the iPhone.  I&#8217;ve also been experimenting with writing apps for both the iPhone and Adobe AIR &#8211; which is a subject for another post.</p>
<p>Anyway, as you can see from the video, soon you will be able to create apps in Flash &#8211; then export directly for the iPhone.  As the video points out, they aren&#8217;t talking about a browser plugin (since there isn&#8217;t one).  These are native self-contained apps that you can post and buy from iTunes.</p>
<p>For more info checkout these links:  </p>
<ul>
<li><a href="http://labs.adobe.com/technologies/flashcs5/appsfor_iphone/">http://labs.adobe.com/technologies/flashcs5/appsfor_iphone/</a></li>
<li><a href="http://cs5.org/">http://cs5.org/</a> &#8211; be sure to checkout the Physics in Flash video too.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/441/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Cocos2D Layer Test Harness</title>
		<link>http://mitchallen.com/iphone/archives/371</link>
		<comments>http://mitchallen.com/iphone/archives/371#comments</comments>
		<pubDate>Sun, 20 Sep 2009 20:04:14 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[game engines]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Cocos2D]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=371</guid>
		<description><![CDATA[In this tutorial I&#8217;m going to expand on my previous example TestGame featured in my post Getting Started with the Cocos2d Game Engine.  This follow up borrows heavily from the cocos2d sample file SpritesTest.  If you haven&#8217;t seen the SpritesTest demo, see my article on Running the Cocos2d examples. The objective is to reverse engineer that [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial I&#8217;m going to expand on my previous example <strong>TestGame</strong> featured in my post <a href="http://mitchallen.com/iphone/archives/304">Getting Started with the Cocos2d Game Engine</a>.  This follow up borrows heavily from the cocos2d sample file <strong>SpritesTest</strong>.  If you haven&#8217;t seen the SpritesTest demo, see my article on <a href="http://mitchallen.com/iphone/archives/266">Running the Cocos2d examples</a>. The objective is to reverse engineer that demo and use it to show you how to build your own test app.</p>
<p><strong>Why Build a Test App ?</strong></p>
<p>My background is in testing software libraries.  I have a lot of experience breaking down functionality into manageable test harnesses.  The test harnesses usually let you select one isolated feature and test it.  It&#8217;s a great way for learning how a library works.  It&#8217;s also a great way to try something.  By building a test harness you don&#8217;t have to build a whole project from scratch just to test one feature.  This is especially handy when you run into features that you can only test on the actual device.</p>
<p><strong>Getting Started</strong></p>
<p>In order to complete this tutorial you first you need to go through the steps of my post <a href="http://mitchallen.com/iphone/archives/304">Getting Started with the Cocos2d Game Engine</a>.</p>
<p>If you are using <strong>git</strong> you may want to save and tag the original project and try expanding on it here in a new branch.</p>
<p><strong>Graphic Files</strong></p>
<p>For this tutorial you will need to copy some additional graphic files from the <strong>cocos2d-iphone</strong> sample folders to your projects <strong>Resources</strong> folder:</p>
<ul>
<li>Resources/Images/grossini images/<strong>grossini.png</strong> (<em>male cartoon character</em>)</li>
<li>Resources/Images/grossini images/<strong>grossini_sister1.png</strong> (<em>female cartoon character</em>)</li>
<li>Resources/Images/menu related images/<strong>b1.png</strong> (<em>back arrow</em>)</li>
<li>Resources/Images/menu related images/<strong>b2.png</strong> (<em>back arrow highlighted</em>)</li>
<li>Resources/Images/menu related images/<strong>f1.png</strong> (<em>next arrow</em>)</li>
<li>Resources/Images/menu related images/<strong>f2.png</strong> (<em>next arrow highlighted</em>)</li>
<li>Resources/Images/menu related images/<strong>r1.png</strong> (<em>reset button</em>)</li>
<li>Resources/Images/menu related images/<strong>r2.png</strong> (<em>reset button highlighted</em>)</li>
</ul>
<p><strong>Classes / TestGameAppDelegate.m</strong></p>
<p>For this tutorial I&#8217;ve borrowed from the <strong>SpritesTest</strong> code and added some new functionality to <strong>TestGameAppDelegate.m</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TestGameAppDelegate.m</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/16/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright __MyCompanyName__ 2009. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// Some code and images borrowed from cocos2d SpritesTest sample code.</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// See these links for additional info and credit:</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/371</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/304</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;TestGameAppDelegate.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TestGameAppDelegate
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationDidFinishLaunching<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span> 
&nbsp;
	UIWindow <span style="color: #002200;">*</span>window <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIWindow alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> bounds<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>window setUserInteractionEnabled<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>window setMultipleTouchEnabled<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// DEPRECATED: [[Director sharedDirector] setLandscape: YES];</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> setDeviceOrientation<span style="color: #002200;">:</span> CCDeviceOrientationLandscapeLeft <span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> attachInWindow<span style="color: #002200;">:</span> window<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// display FPS (useful when debugging)</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> setDisplayFPS<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// frames per second</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> setAnimationInterval<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">/</span><span style="color: #2400d9;">60</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Default texture format for PNG/BMP/TIFF/JPEG/GIF images</span>
	<span style="color: #11740a; font-style: italic;">// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565</span>
	<span style="color: #11740a; font-style: italic;">// You can change anytime.</span>
	<span style="color: #002200;">&#91;</span>Texture2D setDefaultAlphaPixelFormat<span style="color: #002200;">:</span>kTexture2DPixelFormat_RGBA8888<span style="color: #002200;">&#93;</span>;
&nbsp;
	TestScene <span style="color: #002200;">*</span>game <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>TestScene node<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> runWithScene<span style="color: #002200;">:</span> game<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// getting a call, pause the game</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> applicationWillResignActive<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> pause<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// call got rejected</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> applicationDidBecomeActive<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> resume<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// purge memroy</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationDidReceiveMemoryWarning<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>TextureMgr sharedTextureMgr<span style="color: #002200;">&#93;</span> removeAllTextures<span style="color: #002200;">&#93;</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> dealloc
<span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// next delta time will be zero</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> applicationSignificantTimeChange<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> setNextDeltaTimeZero<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>Test Scene</strong></p>
<p>There are no changes to <strong>TestScene</strong> from the previous project.  As a reminder:</p>
<ul>
<li>A simple <strong>TestScene</strong> class is defined based on cocos2d <strong>Scene</strong> class</li>
<li>The TestScene loads a <strong>TestLayer</strong> based on a cocos2d <strong>Layer</strong> class</li>
</ul>
<p><strong>Test Layer</strong></p>
<p>There have been several changes made to <strong>TestLayer</strong>.</p>
<ul>
<li>Now<strong> TestLayer</strong> serves as a base class for additional test layers that you can customize based on what you want to test</li>
<li>It manages the loading of two sprites from the cocos2d samples: <em>grossini</em> and <em>tamara</em></li>
<li>It loads a graphical menu for navigating between layers using arrows and restarting a layer</li>
<li>It has several functions to work with the menu to switch between layers</li>
<li>It has a <strong>centerSprites</strong> method for centering the two test sprites</li>
<li>It has a <strong>title</strong> method used by the UI that can be overridden by derived classes</li>
</ul>
<p><strong>Classes/TestScene.h</strong></p>
<p>Both <strong>TestScene</strong> and <strong>TestLayer</strong> are defined in <strong>Classes/TestScene.*</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TestScene.h</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/16/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// See these links for additional info and credit:</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/371</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/304</span>
&nbsp;
<span style="color: #6e371a;">#import</span>
<span style="color: #6e371a;">#import &quot;cocos2d.h&quot;</span>
<span style="color: #6e371a;">#import &quot;chipmunk.h&quot;</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">@interface</span> TestScene <span style="color: #002200;">:</span> Scene <span style="color: #002200;">&#123;</span> <span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">@interface</span> TestLayer <span style="color: #002200;">:</span> Layer <span style="color: #002200;">&#123;</span>
	Sprite <span style="color: #002200;">*</span> grossini;
	Sprite <span style="color: #002200;">*</span>tamara;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> centerSprites;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> title;
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setLayer<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">Class</span><span style="color: #002200;">&#41;</span> classLayer;
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> backCallback<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sender;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> nextCallback<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sender;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> restartCallback<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sender;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>Classes/TestScene.m</strong></p>
<p>One important thing to note here is the global <strong>static</strong> <strong>transitions</strong> string array.  When you add a new class based on <strong>TestLayer</strong> (see <strong>MyTests.*</strong> below), you need to add a string containing the name to the array. The navigation code uses <strong>NSClassFromString</strong> to convert the currently indexed string to a layer object to load.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TestScene.m</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/16/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// See these links for additional info and credit:</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/371</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/304</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;TestScene.h&quot;</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TestScene
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init <span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> self <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>TestLayer node<span style="color: #002200;">&#93;</span> z<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">static</span> <span style="color: #a61390;">int</span> sceneIdx<span style="color: #002200;">=-</span><span style="color: #2400d9;">1</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">///////////////////////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// In order for a test layer to appear you must</span>
<span style="color: #11740a; font-style: italic;">// add a string for its class name to this array.</span>
<span style="color: #11740a; font-style: italic;">// Test layers are defined in MyTests.*</span>
&nbsp;
<span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>transitions<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">=</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;TestLayer01&quot;</span>,
	<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;TestLayer02&quot;</span> <span style="color: #002200;">&#125;</span>;
&nbsp;
<span style="color: #a61390;">Class</span> nextAction<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Retrieve the name of the next layer class</span>
	<span style="color: #11740a; font-style: italic;">// and return a class based on that string.</span>
&nbsp;
	sceneIdx<span style="color: #002200;">++</span>;
	sceneIdx <span style="color: #002200;">=</span> sceneIdx <span style="color: #002200;">%</span> <span style="color: #002200;">&#40;</span> <span style="color: #a61390;">sizeof</span><span style="color: #002200;">&#40;</span>transitions<span style="color: #002200;">&#41;</span> <span style="color: #002200;">/</span> <span style="color: #a61390;">sizeof</span><span style="color: #002200;">&#40;</span>transitions<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#41;</span>;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>r <span style="color: #002200;">=</span> transitions<span style="color: #002200;">&#91;</span>sceneIdx<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">Class</span> c <span style="color: #002200;">=</span> NSClassFromString<span style="color: #002200;">&#40;</span>r<span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">return</span> c;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">Class</span> backAction<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Retrieve the name of the previous layer class</span>
	<span style="color: #11740a; font-style: italic;">// and return a class based on that string.</span>
&nbsp;
	sceneIdx<span style="color: #002200;">--</span>;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> sceneIdx &lt; <span style="color: #2400d9;">0</span> <span style="color: #002200;">&#41;</span>
		sceneIdx <span style="color: #002200;">=</span> <span style="color: #a61390;">sizeof</span><span style="color: #002200;">&#40;</span>transitions<span style="color: #002200;">&#41;</span> <span style="color: #002200;">/</span> <span style="color: #a61390;">sizeof</span><span style="color: #002200;">&#40;</span>transitions<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">1</span>;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>r <span style="color: #002200;">=</span> transitions<span style="color: #002200;">&#91;</span>sceneIdx<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">Class</span> c <span style="color: #002200;">=</span> NSClassFromString<span style="color: #002200;">&#40;</span>r<span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">return</span> c;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">Class</span> restartAction<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Retrieve the name of the current layer class</span>
	<span style="color: #11740a; font-style: italic;">// and return a class based on that string.</span>
&nbsp;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> sceneIdx &lt; <span style="color: #2400d9;">0</span> || sceneIdx &gt;<span style="color: #002200;">=</span> <span style="color: #a61390;">sizeof</span><span style="color: #002200;">&#40;</span>transitions<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#41;</span> <span style="color: #a61390;">return</span> <span style="color: #a61390;">nil</span>;
&nbsp;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>r <span style="color: #002200;">=</span> transitions<span style="color: #002200;">&#91;</span>sceneIdx<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">Class</span> c <span style="color: #002200;">=</span> NSClassFromString<span style="color: #002200;">&#40;</span>r<span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">return</span> c;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TestLayer
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init <span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>self <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>		
&nbsp;
		<span style="color: #11740a; font-style: italic;">// Initialize and add test images so they can be used by derived test layers.</span>
&nbsp;
		<span style="color: #11740a; font-style: italic;">// Note that because we 'retain' the images,</span>
		<span style="color: #11740a; font-style: italic;">// we will need to release them in dealloc.</span>
&nbsp;
		grossini <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Sprite spriteWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;grossini.png&quot;</span><span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span>;
		tamara <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Sprite spriteWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;grossinis_sister1.png&quot;</span><span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span> grossini z<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span> tamara z<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #002200;">&#91;</span>self centerSprites<span style="color: #002200;">&#93;</span>;
&nbsp;
		CGSize s <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> winSize<span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #11740a; font-style: italic;">// Display the title property for the current layer.</span>
&nbsp;
		Label<span style="color: #002200;">*</span> label <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>Label labelWithString<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>self title<span style="color: #002200;">&#93;</span> fontName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Arial&quot;</span> fontSize<span style="color: #002200;">:</span><span style="color: #2400d9;">32</span><span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span> label<span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>label setPosition<span style="color: #002200;">:</span> ccp<span style="color: #002200;">&#40;</span>s.width<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>, s.height<span style="color: #002200;">-</span><span style="color: #2400d9;">50</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #11740a; font-style: italic;">// Create a graphics-based layer navigation menu to be used by all derived test layers.</span>
&nbsp;
		MenuItemImage <span style="color: #002200;">*</span>item1 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MenuItemImage itemFromNormalImage<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;b1.png&quot;</span> selectedImage<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;b2.png&quot;</span> target<span style="color: #002200;">:</span>self selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>backCallback<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
		MenuItemImage <span style="color: #002200;">*</span>item2 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MenuItemImage itemFromNormalImage<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;r1.png&quot;</span> selectedImage<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;r2.png&quot;</span> target<span style="color: #002200;">:</span>self selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>restartCallback<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
		MenuItemImage <span style="color: #002200;">*</span>item3 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MenuItemImage itemFromNormalImage<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;f1.png&quot;</span> selectedImage<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;f2.png&quot;</span> target<span style="color: #002200;">:</span>self selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>nextCallback<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
		Menu <span style="color: #002200;">*</span>menu <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>Menu menuWithItems<span style="color: #002200;">:</span>item1, item2, item3, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
		menu.position <span style="color: #002200;">=</span> CGPointZero;
		item1.position <span style="color: #002200;">=</span> ccp<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">480</span><span style="color: #002200;">/</span><span style="color: #2400d9;">2</span><span style="color: #002200;">-</span><span style="color: #2400d9;">100</span>,<span style="color: #2400d9;">30</span><span style="color: #002200;">&#41;</span>;
		item2.position <span style="color: #002200;">=</span> ccp<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">480</span><span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>, <span style="color: #2400d9;">30</span><span style="color: #002200;">&#41;</span>;
		item3.position <span style="color: #002200;">=</span> ccp<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">480</span><span style="color: #002200;">/</span><span style="color: #2400d9;">2</span><span style="color: #002200;">+</span><span style="color: #2400d9;">100</span>,<span style="color: #2400d9;">30</span><span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span> menu z<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> self;
<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> centerSprites
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Take our two test sprites and center them on the screen.</span>
&nbsp;
	CGSize s <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> winSize<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>grossini setPosition<span style="color: #002200;">:</span> ccp<span style="color: #002200;">&#40;</span>s.width<span style="color: #002200;">/</span><span style="color: #2400d9;">3</span>, s.height<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>tamara setPosition<span style="color: #002200;">:</span> ccp<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">2</span><span style="color: #002200;">*</span>s.width<span style="color: #002200;">/</span><span style="color: #2400d9;">3</span>, s.height<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> title
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Create a default title for the opening layer.</span>
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Test layers should override this call.</span>
&nbsp;
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Press Arrows to Continue&quot;</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> dealloc
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Since our test sprites were retained,</span>
	<span style="color: #11740a; font-style: italic;">// we must now release them.</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>grossini release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>tamara release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</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> setLayer<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">Class</span><span style="color: #002200;">&#41;</span> classLayer <span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Replace the current layer with one based another class object.</span>
&nbsp;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> classLayer <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">&#41;</span> <span style="color: #a61390;">return</span>;
&nbsp;
	Scene <span style="color: #002200;">*</span>s <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>Scene node<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>s addChild<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>classLayer node<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> replaceScene<span style="color: #002200;">:</span> s<span style="color: #002200;">&#93;</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> restartCallback<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sender
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// When the user clicks the restart button</span>
	<span style="color: #11740a; font-style: italic;">// (the green circle in the current UI)</span>
	<span style="color: #11740a; font-style: italic;">// reload the current layer,</span>
	<span style="color: #11740a; font-style: italic;">// triggering a restart of the action</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>self setLayer<span style="color: #002200;">:</span> restartAction<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</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> nextCallback<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sender
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// When the user clicks the next arrow</span>
	<span style="color: #11740a; font-style: italic;">// (the green right arrow in the current UI)</span>
	<span style="color: #11740a; font-style: italic;">// load the next layer in the list.</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>self setLayer<span style="color: #002200;">:</span> nextAction<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</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> backCallback<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sender
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// When the user clicks the back arrow</span>
	<span style="color: #11740a; font-style: italic;">// (the green left arrow in the current UI)</span>
	<span style="color: #11740a; font-style: italic;">// load the previous layer in the list.</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>self setLayer<span style="color: #002200;">:</span> backAction<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>Classes/MyTests.h</strong></p>
<p>When adding a new derived <strong>TestLayer</strong> you generally don&#8217;t have to do a lot in the header file (unless you want to add more functions and things like retained sprites to track).  For simple layers you just need to define interfaces based on <strong>TestLayer</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  MyTests.h</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/20/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// See these links for additional info and credit:</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/371</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/304</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;TestScene.h&quot;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">///////////////////////////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// Adding Test Layers to Test Game</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// When a  dervied TestLayer is added, you must add it's name to</span>
<span style="color: #11740a; font-style: italic;">// the NSString transitions array in TestScene.m for it to appear</span>
<span style="color: #11740a; font-style: italic;">// in the test game.</span>
&nbsp;
<span style="color: #a61390;">@interface</span> TestLayer01 <span style="color: #002200;">:</span> TestLayer
<span style="color: #002200;">&#123;</span><span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@interface</span> TestLayer02 <span style="color: #002200;">:</span> TestLayer
<span style="color: #002200;">&#123;</span><span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>Classes/MyTests.m</strong></p>
<p>For simple layers you just need to define two things:</p>
<ul>
<li>An <strong>onEnter</strong> method for setting up the actions in your layer</li>
<li>A <strong>title</strong> method that overrides the base <strong>TestLayer</strong> title method and returns a pointer to an <strong>NSString</strong> used by the UI</li>
</ul>
<p>You also need to remember this important step:</p>
<ul>
<li>When you add a new layer you need to add the name as a string to the <strong>transistions</strong> array in <strong>TestScene.m</strong></li>
</ul>
<p>For this tutorial I just borrowed the <strong>SpritesTest</strong> demo code from the <strong>SpriteMove</strong> and <strong>SpriteRotate</strong> classes.</p>
<p>You can use this file to add as many test layers as you would like.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  MyTests.m</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/20/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// See these links for additional info and credit:</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/371</span>
<span style="color: #11740a; font-style: italic;">// http://mitchallen.com/iphone/archives/304</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;MyTests.h&quot;</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TestLayer01
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> onEnter
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Code borrowed from cocos2d sample:</span>
	<span style="color: #11740a; font-style: italic;">// SpritesTest.m - SpriteMove class</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>super onEnter<span style="color: #002200;">&#93;</span>;
&nbsp;
	CGSize s <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> winSize<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">id</span> actionTo <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MoveTo actionWithDuration<span style="color: #002200;">:</span> <span style="color: #2400d9;">2</span> position<span style="color: #002200;">:</span>ccp<span style="color: #002200;">&#40;</span>s.width<span style="color: #002200;">-</span><span style="color: #2400d9;">40</span>, s.height<span style="color: #002200;">-</span><span style="color: #2400d9;">40</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">id</span> actionBy <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MoveBy actionWithDuration<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span>  position<span style="color: #002200;">:</span> ccp<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">80</span>,<span style="color: #2400d9;">80</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">id</span> actionByBack <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>actionBy reverse<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>tamara runAction<span style="color: #002200;">:</span> actionTo<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>grossini runAction<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>Sequence actions<span style="color: #002200;">:</span>actionBy, actionByBack, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> title
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Override the base classes title</span>
	<span style="color: #11740a; font-style: italic;">// that appears on the screen.</span>
&nbsp;
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Test Layer 01 - Move&quot;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TestLayer02
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> onEnter
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Code borrowed from cocos2d sample:</span>
	<span style="color: #11740a; font-style: italic;">// SpritesTest.m - SpriteRotate class</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>super onEnter<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>self centerSprites<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">id</span> actionTo <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>RotateTo actionWithDuration<span style="color: #002200;">:</span> <span style="color: #2400d9;">2</span> angle<span style="color: #002200;">:</span><span style="color: #2400d9;">45</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">id</span> actionBy <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>RotateBy actionWithDuration<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span>  angle<span style="color: #002200;">:</span> <span style="color: #2400d9;">360</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">id</span> actionByBack <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>actionBy reverse<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>tamara runAction<span style="color: #002200;">:</span> actionTo<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>grossini runAction<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>Sequence actions<span style="color: #002200;">:</span>actionBy, actionByBack, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> title
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Override the base classes title</span>
	<span style="color: #11740a; font-style: italic;">// that appears on the screen.</span>
&nbsp;
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Test Layer 02 - Rotate&quot;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>Compile and Run</strong></p>
<ul>
<li>Click: <strong>Build and Go</strong></li>
</ul>
<p><strong>Git Clone</strong></p>
<p>If you have <strong>git</strong> installed, you can clone a copy of this project with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git clone git://github.com/mitchallen/TestGame.git</pre></div></div>

<p>For my next tutorial I will be adding code to the repository.  So to get back to the original state of this tutorial, you will need to execute the following at the command line:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git checkout v200</pre></div></div>

<p>To get back to the state used in the <em>previous</em> tutorial you can use:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git checkout v100</pre></div></div>

<p>Both v100 and v200 are tags that I&#8217;ve set on the master branch.</p>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/371/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Git Project Samples</title>
		<link>http://mitchallen.com/iphone/archives/361</link>
		<comments>http://mitchallen.com/iphone/archives/361#comments</comments>
		<pubDate>Thu, 17 Sep 2009 21:16:40 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[github]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=361</guid>
		<description><![CDATA[If you scroll to the bottom of my previous post you will notice that I&#8217;ve updated it with a new section:

Git Clone
If you have git installed, you can clone a copy of this project with the following command:

git clone git://github.com/mitchallen/TestGame.git


Going forward, I will attempt to post all sample code using git.  Usually this means that [...]]]></description>
			<content:encoded><![CDATA[<p>If you scroll to the bottom of my <a href="http://mitchallen.com/iphone/archives/304">previous post</a> you will notice that I&#8217;ve updated it with a new section:</p>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px;"><strong>Git Clone</strong></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px;">If you have <strong>git</strong> installed, you can clone a copy of this project with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git clone git://github.com/mitchallen/TestGame.git</pre></div></div>

</blockquote>
<p>Going forward, I will attempt to post all sample code using git.  Usually this means that it will come wrapped in a full Xcode project.</p>
<p>I have several reasons for using git:</p>
<ul>
<li>I don&#8217;t have to wrestle with creating a zip file and uploading it to some obscure server somewhere</li>
<li>You don&#8217;t have to wrestle with downloading a zip file and expanding it somewhere</li>
<li>You don&#8217;t need an account to copy my public repositories</li>
<li>All you have to do is enter one line in a terminal window</li>
<li>You instantly end up with a local copy of the repository that you can copy and branch any which way you like</li>
<li>It forces you to think about source control <img src='http://mitchallen.com/iphone/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>If something is missing, I can just checkin new stuff and do a refresh</li>
<li>If I hack an existing project, I can just add a branch instead of forcing you and I to deal with multiple projects</li>
</ul>
<p>So if you still haven&#8217;t installed <strong>git</strong> on your Mac yet, I suggest you go back and <a href="http://mitchallen.com/iphone/archives/291">read my post on the subject</a> again.  Also if you have, you may want to read it again.  I&#8217;ve added a few more links and info on filtering out certain files to keep your repository from getting cluttered.</p>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/361/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting Started with the Cocos2D Game Engine</title>
		<link>http://mitchallen.com/iphone/archives/304</link>
		<comments>http://mitchallen.com/iphone/archives/304#comments</comments>
		<pubDate>Wed, 16 Sep 2009 17:22:19 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[game engines]]></category>
		<category><![CDATA[Cocos2D]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=304</guid>
		<description><![CDATA[Introduction
What follows are notes that I gathered from looking at various tutorials on getting started with the Cocos2D Game Engine. You can find the tutorials that I used as a source for my notes here:

http://monoclestudios.com/cocos2d_whitepaper.html
http://morethanmachine.com/macdev/?p=83

Additional links may be found in my entry here:

http://mitchallen.com/iphone/archives/254

This tutorial was tested with cocos2d-iphone-0.8 &#8211;  I had trouble compiling with [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>What follows are notes that I gathered from looking at various tutorials on getting started with the Cocos2D Game Engine. You can find the tutorials that I used as a source for my notes here:</p>
<ul>
<li><a title="http://monoclestudios.com/cocos2d_whitepaper.html" href="http://monoclestudios.com/cocos2d_whitepaper.html">http://monoclestudios.com/cocos2d_whitepaper.html</a></li>
<li><a title="http://morethanmachine.com/macdev/?p=83" href="http://morethanmachine.com/macdev/?p=83">http://morethanmachine.com/macdev/?p=83</a></li>
</ul>
<p>Additional links may be found in my entry here:</p>
<ul>
<li><a title="http://mitchallen.com/iphone/archives/254" href="http://mitchallen.com/iphone/archives/254">http://mitchallen.com/iphone/archives/254</a></li>
</ul>
<p>This tutorial was tested with cocos2d-iphone-0.8 &#8211;  I had trouble compiling with 0.8.<strong>1</strong>.</p>
<p><strong>UPDATE</strong>: I&#8217;ve added some notes for compiling using 0.8.2 &#8211; with the help of some reader comments below.</p>
<p><strong>Build Options</strong></p>
<p>There are a number of options for creating a Cocos2D Game Project:</p>
<ol>
<li>Use the engine as a shared library</li>
<li>Start from a template</li>
<li>Copy the engine components and put them in your project</li>
</ol>
<p>For simplicity this article covers Option #3 &#8211; copying the engine components to your project.</p>
<p>If you would like to know more about the other options, see these links:</p>
<ul>
<li><a href="http://www.clintharris.net/2009/iphone-app-shared-libraries/">http://www.clintharris.net/2009/iphone-app-shared-libraries/</a></li>
<li><a href="http://iphonedev.net/2009/07/29/how-to-create-your-own-cocos2d-project-template/">http://iphonedev.net/2009/07/29/how-to-create-your-own-cocos2d-project-template/</a></li>
</ul>
<p><strong>Setting Up the Project</strong></p>
<ul>
<li>Download and unpack the latest <em>stable</em> release of the Cocos2D Game Engine from here: <a href="http://code.google.com/p/cocos2d-iphone/">http://code.google.com/p/cocos2d-iphone/</a></li>
<li>Launch Xcode</li>
<li>Select: <strong>File / New Project &#8230; / [<em>iPhone OS : Application</em></strong><strong>] / Window-based Application / Choose &#8230;</strong></li>
<li><strong>Save As</strong>: <em>TestGame</em>, <strong>Save</strong></li>
<li>Delete: <em>Resources / MainWindow.xib</em></li>
<li>Edit: <em>TestGame-Info.plist</em>:</li>
<li>Delete the line: <strong>Main nib file base name : MainWindow</strong></li>
<li>Add the line: <strong>Status bar is initially hidde</strong><strong>n</strong> &#8211; and check it</li>
<li>Save the file</li>
<li>Click on the <em>TestGame</em> folder icon at the top of the <strong>Groups &amp; Files</strong> pane</li>
<li>Select: <strong>Project / Add to Project &#8230;</strong> / <em>cocos2d-phone-<strong>x.y.z </strong>/ cocos2d</em></li>
<li>Hold down the <strong>Apple-key</strong> and also select: <em>external</em></li>
<li>Click: <strong>Add</strong></li>
<li>Check: <strong>Copy items in destination group&#8217;s folder (if needed)</strong></li>
<li>Click: <strong>Recursively create groups for any added folders</strong></li>
<li>Click: <strong>Add</strong></li>
<li>Note that if you mess up and need to delete the folders, you also may have to go to the project folder itself and delete them.  Otherwise you may get an error if trying to add them again.</li>
<li>In the <em>external</em> folder, delete everything that is <strong>NOT</strong> the <em><strong>Chipmunk</strong></em> folder (if you are using 0.8.2 keep the <strong>FontLabel</strong> folder too!).  Why?  Because some of those items are experimental and may not compile.</li>
<li>From within the <em>external / Chipmunk</em> folder, delete everything that is <strong>NOT</strong> the <em><strong>src</strong></em> folder.</li>
<li>Right-click on the <em>Resources</em> folder and select: <strong>Add / Existing Files &#8230;</strong></li>
<li>If using 0.8: <em>cocos2d / Resources / <strong>Images</strong> / fps_images.png</em></li>
<li>If using 0.8.2: <em>cocos2d / Resources / <strong>Fonts</strong> / fps_images.png</em></li>
<li><strong>Add</strong> / Check <strong>Copy &#8230;</strong>, <strong>Recursive &#8230;</strong>, <strong>Add</strong></li>
<li>Right-click on the <em>Frameworks</em> folder and select: <strong>Add / Existing Frameworks &#8230;</strong></li>
<li>Select the <em>Frameworks</em> folder</li>
<li>Select: <strong>OpenGLES.framework</strong></li>
<li>Click <strong>Shift</strong> and also select: <strong>QuartzCore.framework</strong> and click: <strong>Add</strong>, click <strong>Add</strong> again</li>
</ul>
<p><strong>Additional Steps for 0.8.2</strong></p>
<p>If you are using 0.8.2 (or possibly a later version) you will need to also do the following steps to get the project to compile:</p>
<ul>
<li>Double-click on <strong>Targets \ TestGame</strong></li>
<li>Make sure that the <strong>General</strong> tab is selected in the dialog box</li>
<li>There are two sets of <strong>+  / -</strong> buttons in the dialog, click the <strong>+</strong> button on the bottom under the list of <strong>Linked Librarie</strong>s</li>
<li>Select <strong>libz.1.2.3.dylib</strong> and <strong>Add</strong> it
</ul>
<p><strong>Add New Files</strong></p>
<ul>
<li>Right-click on the <em>Classes</em> folder and select:</li>
<li><strong>Add / New File &#8230; / </strong>[<strong><em>iPhone OS : Cocoa Touch Class</em></strong> ] / <strong>Object-C class</strong> / [<strong><em>NSObject</em></strong>] / <strong>Next</strong></li>
<li><strong>File Name: </strong><em>TestScene.m</em>, leave <strong>Also create &#8220;TestScene.h</strong><em>&#8220;</em> checked and click <strong>Finish</strong></li>
</ul>
<p>Make the following changes to <strong>Classes / TestScene.h</strong>:</p>
<ul>
<li>Remove the line:  <em>#import &lt;Foundation/Foundation.h&gt; </em></li>
<li>Add the following import lines:</li>
<li><strong>#import &lt;UIKit/UIKit.h&gt;</strong></li>
<li><strong>#import &#8220;cocos2d.h&#8221;</strong></li>
<li><strong>#import &#8220;chipmunk.h&#8221;</strong></li>
<li>Change the class definition so that it is based on <strong>Scene</strong> instead of <strong>NSObject</strong></li>
<li>At the bottom of the file add another <strong>@interface</strong> called <strong>TestLayer</strong> based on <strong>Layer</strong></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TestScene.h</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/16/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import</span>
<span style="color: #6e371a;">#import &quot;cocos2d.h&quot;</span>
<span style="color: #6e371a;">#import &quot;chipmunk.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> TestScene <span style="color: #002200;">:</span> Scene <span style="color: #002200;">&#123;</span> <span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@interface</span> TestLayer <span style="color: #002200;">:</span> Layer <span style="color: #002200;">&#123;</span> <span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Make the following changes to <strong>Classes / TestScene.m</strong>:</p>
<ul>
<li>Add <strong>init</strong> method that adds a <strong>TestLayer</strong> to the scene</li>
<li>Add an <strong>@implementation</strong> for <strong>TestLayer</strong></li>
<li>Add <strong>init</strong> method to <strong>TestLayer</strong> that puts something on the screen</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TestScene.m</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/16/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 __MyCompanyName__. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;TestScene.h&quot;</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TestScene
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init <span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> self <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>TestLayer node<span style="color: #002200;">&#93;</span> z<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TestLayer
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init <span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>self <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #11740a; font-style: italic;">// Note that if you spell the fontName wrong, the label won't appear.</span>
		Label <span style="color: #002200;">*</span>test <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>Label labelWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Hello World&quot;</span> fontName<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Helvetica&quot;</span> fontSize<span style="color: #002200;">:</span> <span style="color: #2400d9;">24</span><span style="color: #002200;">&#93;</span>;
		test.position <span style="color: #002200;">=</span> cpv<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">160</span>, <span style="color: #2400d9;">240</span><span style="color: #002200;">&#41;</span>;	<span style="color: #11740a; font-style: italic;">// cpv = Chipmunk vector</span>
		<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span> test<span style="color: #002200;">&#93;</span>;	<span style="color: #11740a; font-style: italic;">// Add the label to the layer.</span>
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>Edit the Existing Files</strong></p>
<p>Make the following changes to <strong>Classes / TestGameAppDelegate.h</strong>:</p>
<ul>
<li>Add two #import statements:</li>
<li><strong>#import &#8220;cocos2d.h&#8221;</strong></li>
<li><strong>#import &#8220;TestScene.h&#8221;</strong></li>
<li>Remove the two lines referencing the <strong>window</strong> property</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TestGameAppDelegate.h</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/16/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright __MyCompanyName__ 2009. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import </span>
&nbsp;
<span style="color: #6e371a;">#import &quot;cocos2d.h&quot;</span>
<span style="color: #6e371a;">#import &quot;TestScene.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> TestGameAppDelegate <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span>  <span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Make the following changes to <strong>Classes / TestGameAppDelegate.m</strong>:</p>
<ul>
<li>Remove the line: <em>@synthesize window;</em></li>
<li>Remove the <strong>dealloc</strong> method</li>
<li>Clear the contents of the method: <strong>applicationDidFinishLaunching</strong> and replace it with the code below</li>
<li>If you don&#8217;t want your game to start in landscape mode, comment out the line containing <strong>setDeviceOrientation</strong></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  TestGameAppDelegate.m</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/16/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright __MyCompanyName__ 2009. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;TestGameAppDelegate.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> TestGameAppDelegate
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationDidFinishLaunching<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span> 
&nbsp;
	UIWindow <span style="color: #002200;">*</span>window <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIWindow alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> bounds<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>window setUserInteractionEnabled<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>window setMultipleTouchEnabled<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// DEPRECATED: [[Director sharedDirector] setLandscape: YES];</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> setDeviceOrientation<span style="color: #002200;">:</span> CCDeviceOrientationLandscapeLeft <span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> attachInWindow<span style="color: #002200;">:</span> window<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;
&nbsp;
	TestScene <span style="color: #002200;">*</span>game <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>TestScene node<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> runWithScene<span style="color: #002200;">:</span> game<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Make the following changes to <strong>Other Sources / main.m</strong>:</p>
<ul>
<li>Change the last argument in the call to <strong>UIApplicationMain</strong> to a string containing the name of the delegate: <strong>@&#8221;TestGameAppDelegate&#8221;</strong></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  main.m</span>
<span style="color: #11740a; font-style: italic;">//  TestGame</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mitchell Allen on 9/16/09.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright __MyCompanyName__ 2009. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import </span>
&nbsp;
<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>
&nbsp;
    <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: #002200;">&#91;</span><span style="color: #400080;">NSAutoreleasePool</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// MCA - changed last argument to name of delegate.</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;TestGameAppDelegate&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
    <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>Compile and Run</strong></p>
<ul>
<li>Click: <strong>Build and Go</strong></li>
</ul>
<p><strong>Git Clone</strong></p>
<p>If you have <strong>git</strong> installed, you can clone a copy of this project with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git clone git://github.com/mitchallen/TestGame.git</pre></div></div>

<p>For my next tutorial I will be adding code to the repository.  So to get back to the original state of this tutorial, you will need to execute the following at the command line:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git checkout v100</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/304/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Source Control with Git</title>
		<link>http://mitchallen.com/iphone/archives/291</link>
		<comments>http://mitchallen.com/iphone/archives/291#comments</comments>
		<pubDate>Fri, 04 Sep 2009 21:11:57 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[source control]]></category>
		<category><![CDATA[Git]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=291</guid>
		<description><![CDATA[Over the years I&#8217;ve worked with many source control management systems (CVS, SVN, SourceSafe, PerForce).   The problem is that they are oriented towards a central server.  Git on the other hand is a new and improved type of source control.  It can work with a server - in fact, it can work with many servers.  But it can [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years I&#8217;ve worked with many source control management systems (CVS, SVN, SourceSafe, PerForce).   The problem is that they are oriented towards a central server.  Git on the other hand is a new and improved type of source control.  It can work with a server - in fact, it can work with many servers.  But it can also work with just your collaborators workstation across the hall &#8211; bypassing the need for a server completely.</p>
<p>If you are just working by yourself (as many iPhone developers are) you can run it on your local workstation &#8211; even without a network connection.  If later you want to make your repository available to others &#8212; or just create an offsite backup &#8212; you can either open up a share on your workstation or clone a repository to a server.</p>
<p>Instead of going into too much detail, I&#8217;m just going to provide links to resources for you to look at.  You can decide for yourself if it is right for you:</p>
<ul>
<li><a href="http://git-scm.com/">Git Home Page</a></li>
<li><a href="http://progit.org/book/">http://progit.org/book/</a> - A free Web-based version of the book <strong>Pro Git</strong>.</li>
<li><a href="http://www.apress.com/book/view/1430218339">Pro Git on Apress</a> &#8211; You can help the author of <strong>Pro Git</strong> out by buying a PDF or hard-copy.</li>
<li><a href="http://code.google.com/p/git-osx-installer/">Git for OS X</a> &#8211; This is what you&#8217;ll need to install it on your Mac.  In my case I had to make sure that I got the latest Intel / Leopard DMG file.</li>
<li><a href="http://dysinger.net/2007/12/30/installing-git-on-mac-os-x-105-leopard/">Installing Git on Leopard</a> &#8211; For the most part you will just want the <strong>Git for OS X</strong> installer &#8211; but see the notes on setting up your config.</li>
<li><a href="http://gitx.frim.nl/">Gitx</a> &#8211; GitX is a git GUI made for Mac OS X</li>
<li><a href="http://docs.heroku.com/git">Heroku tips on Git</a> &#8211; Heroku is a cloud-based host for Rails apps &#8211; but you may find some of the generic tips and links useful.</li>
<li><a href="http://code.google.com/p/msysgit">Windows Installer</a> &#8211; Why would an iPhone developer need a Windows installer?  It could make it easy to trade *.cpp files with your PC.  Plus you can use it for your other projects.  Git is platform independent.</li>
<li><a href="http://github.com/">GitHub.com</a> &#8211; Free hosting for your open source projects.  Paid options also available.</li>
<li><a href="http://unfuddle.com">Unfuddle </a>- Also offers free hosting.  Unlike GitHub, the free plan can be private.</li>
</ul>
<p><strong>Installing on the Mac</strong></p>
<p>When you download <strong><a href="http://code.google.com/p/git-osx-installer/">Git for OS X</a></strong> the DMG file should open up.  Launch the installer.</p>
<p>After installation completes, open up a terminal window and configure it via the command line (substitute your name and e-mail address):</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git config --global user.name &quot;John Doe&quot;
git config --global user.email &quot;john.doe@gmail.com&quot;</pre></div></div>

<p>When that is done type the following:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git config --list</pre></div></div>

<p><strong>Ignoring Files</strong></p>
<p>On a PC, you would see several items listed.  On the Mac, apparently you have to set those yourself.  See the link <a href="http://dysinger.net/2007/12/30/installing-git-on-mac-os-x-105-leopard/"><strong>Installing Git on Leopard</strong></a> for what other globals you have to set.  Be sure to configure the ability to use a <strong>.gitignor</strong><strong>e</strong> file for filtering what goes into the repository.</p>
<p>The link suggests that you put your <strong>.gitignore</strong> file in your user directory.  I prefer to put the file in the root of the project.  Yes, it is a hassle to always copy the file from project to project.  But it helps you make sure that whomever else downloads your repository has the right filter too.</p>
<p>So I would configure my globals like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git config --global core.excludesfile .gitignore</pre></div></div>

<p>For iPhone SDK projects, here is what I have for a .gitignore file:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># xcode noise
build/*
*.xcclassmodel/*
*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3
&nbsp;
# old skool
.svn
&nbsp;
# osx noise
.DS_Store
profile</pre></div></div>

<p>Here is what I have for <strong>.gitattributes</strong> &#8211; which also sits in the root directory of the project:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">.pbxproj -crlf -diff -merg</pre></div></div>

<p>For more info, see these links:</p>
<p><a style="color: #551a8b;" rel="nofollow" href="http://shanesbrain.net/2008/7/9/using-xcode-with-git" target="_blank">http://shanesbrain.net/2008/7/9/using-xcode-with-git</a></p>
<p><a style="color: #551a8b;" rel="nofollow" href="http://rudifa.wordpress.com/2009/05/19/git-xcode-and-projectlocker/" target="_blank">http://rudifa.wordpress.com/2009/05/19/git-xcode-and-projectlocker/</a></p>
<p><strong>Hidden Files</strong></p>
<p>One thing to note is that when you create a local repository it goes into a subfolder called &#8220;<strong>.git</strong>&#8221; under your projects directory.  On Windows you can see this folder.  It&#8217;s hidden by default on the Mac.  The same is true for <strong>.gitignore</strong> and <strong>.gitattributes</strong>.  If you are in a Terminal window, you can view hidden files using the <strong>-A</strong> flag for <strong>ls</strong>.  Example:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">apple$ ls -l -A</pre></div></div>

<p>If you would like to be able to view hidden files and folders in Finder enter this line from a Terminal window:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">defaults write com.apple.Finder AppleShowAllFiles YES</pre></div></div>

<p>The hidden files won&#8217;t appear until you restart Finder.  For more info, see <a href="http://www.macworld.com/article/51830/2006/07/showallfinder.html">this link</a>. (Note: their steps for restarting Finder didn&#8217;t work for me &#8211; I just rebooted).</p>
<p><strong>Git Hosting</strong></p>
<p>If you do decide to setup a Git server, it can be a bit of work.  To get around that problem at work I just use file shares.  The good thing about Git is that it can refer to a server based reposiory either via http:// or file:/// (example:  file:///\\mywinsever\git\myproject.git &#8211; note that there are three slashes after &#8220;file:&#8221; ).  If that makes no sense to you now, don&#8217;t worry.  It will once you come up to speed.</p>
<p>If you want to share your project with the world, hosts like <a href="http://github.com/">GitHub.com</a> and <a href="http://unfuddle.com">Unfuddle</a> can also save you a lot of work.   These sites are new and suffer from a lack of documentation.  But if you don&#8217;t mind being on the bleeding edge you may find them useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/291/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
