<?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 &#187; game engines</title>
	<atom:link href="http://mitchallen.com/iphone/archives/category/game-engines/feed" rel="self" type="application/rss+xml" />
	<link>http://mitchallen.com/iphone</link>
	<description>random notes on iPhone development</description>
	<lastBuildDate>Tue, 10 Aug 2010 20:36:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>[plug] Learning Cocos2D (The Simple Way)</title>
		<link>http://mitchallen.com/iphone/archives/584</link>
		<comments>http://mitchallen.com/iphone/archives/584#comments</comments>
		<pubDate>Wed, 16 Jun 2010 02:07:14 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[game engines]]></category>
		<category><![CDATA[shameless plugs]]></category>
		<category><![CDATA[Cocos2D]]></category>
		<category><![CDATA[iPhoneGameKit]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=584</guid>
		<description><![CDATA[I&#8217;ve decided to introduce a new category: shameless plugs. It&#8217;s a place where individuals or small businesses can plug their apps or software that may be of interest to readers of this blog.  First up, The iPhone Game Kit. Learning Cocos2D (The Simple Way) If you are reading Mitch&#8217;s blog, we assume you already have [...]]]></description>
			<content:encoded><![CDATA[<p><em>I&#8217;ve decided to introduce a new category: </em><strong><em>shameless plugs</em></strong><em>.  It&#8217;s a place where individuals or small businesses can plug their apps or software that may be of interest to readers of this blog.  First up, The iPhone Game Kit.</em></p>
<p><strong>Learning Cocos2D (The Simple Way)<br />
</strong><br />
If you are reading Mitch&#8217;s blog, we assume you already have a good grasp of Cocos2D. But do you remember how you took your first steps towards learning Cocos2D? Was it a simple, straightforward experience or did you have to deal with lack of resources, or other difficulties making your way into Objective-C? And how would you do it if you had to start learning all over again? These are some of the questions that Nathanael Weiss asked himself when he began working on the iPhone Game Kit. His idea? Create a simple, methodic and straightforward guide to learning Cocos2D and getting started on iPhone Game Development.</p>
<p>The iPhone Game Kit is an entry-level guide on Xcode basics, Objective-C and App Store publishing. This is not a simple drag-and-drop editor, but a comprehensive tutorial to learn iPhone game development basics using Cocos2D. The idea behind the Game kit is to lay a genuine foundation to game design, allowing users to use it as a stepping stone for larger, more complex projects.</p>
<p>Included in the Kit is the Cocos2D engine itself, a 700MB art library, the step-by-step guide and an App Publishing walkthrough. We are also featuring a tutorials section on our website, covering some of the points in the guide and extending its functionality. The Game Kit is currently available as a digital download, and you can learn more about it on <a href="http://www.iphonegamekit.com/" target="_blank">www.iPhoneGameKit.com </a></p>
<p><em>If you have an app or software that you&#8217;d like to pitch to my readers, let me know.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/584/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Particle Designer works with Cocos2D</title>
		<link>http://mitchallen.com/iphone/archives/580</link>
		<comments>http://mitchallen.com/iphone/archives/580#comments</comments>
		<pubDate>Wed, 19 May 2010 14:28:57 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[game engines]]></category>
		<category><![CDATA[71squared]]></category>
		<category><![CDATA[Cocos2D]]></category>
		<category><![CDATA[particle generator]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=580</guid>
		<description><![CDATA[There&#8217;s a new video out from 71 Squared that demos their Particle Designer. It also discusses how to use it with the latest Cocos2D game engine. The video is hosted on Vimeo &#8211; which hasn&#8217;t quite worked out HTML5 embedding. So if I embed it here, you can&#8217;t view it on an iPad or iPhone. [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a new video out from 71 Squared that demos their Particle Designer.  It also discusses how to use it with the latest Cocos2D game engine.</p>
<p><a href="http://mitchallen.com/iphone/wp-content/uploads/2010/05/Screen-shot-2010-05-19-at-7.26.30-AM1.png"><img src="http://mitchallen.com/iphone/wp-content/uploads/2010/05/Screen-shot-2010-05-19-at-7.26.30-AM1-300x195.png" alt="" title="Particle Designer Tutorial on Vimeo" width="300" height="195" class="aligncenter size-medium wp-image-582" /></a></p>
<p>The video is hosted on Vimeo &#8211; which hasn&#8217;t quite worked out HTML5 embedding.  So if I embed it here, you can&#8217;t view it on an iPad or iPhone.  But you can view the video on their site using those devices.  So here is the link:</p>
<p><a href="http://vimeo.com/11852511">http://vimeo.com/11852511</a></p>
<p>For more info, see here:</p>
<p><a href="http://particledesigner.71squared.com">http://particledesigner.71squared.com</a></p>
<p>You can download a trial and then opt to pay just under $8 for the version that emits code that can be used by the Cocos2D engine.</p>
<p>The two things that I like are the random and sharing options.  You can opt to add whatever you come up with to a public gallery of emitters.</p>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/580/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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 [...]]]></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>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 via the [...]]]></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>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>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; [...]]]></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>iPhone Cool Projects</title>
		<link>http://mitchallen.com/iphone/archives/271</link>
		<comments>http://mitchallen.com/iphone/archives/271#comments</comments>
		<pubDate>Fri, 14 Aug 2009 17:21:06 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[book review]]></category>
		<category><![CDATA[game engines]]></category>
		<category><![CDATA[Apress]]></category>
		<category><![CDATA[Cocos2D]]></category>
		<category><![CDATA[Pandora]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=271</guid>
		<description><![CDATA[I paid for and downloaded a PDF copy of iPhone Cool Projects from Apress. You can find a copy of it here: http://www.apress.com/book/view/143022357x.  Or if you prefer the old fashioned way, see my book store links if you want to order a copy from Amazon. I haven&#8217;t had time to read much of the book. [...]]]></description>
			<content:encoded><![CDATA[<p>I paid for and downloaded a PDF copy of <strong>iPhone Cool Projects</strong> from Apress.  You can find a copy of it here: <a title="http://www.apress.com/book/view/143022357x" href="http://www.apress.com/book/view/143022357x">http://www.apress.com/book/view/143022357x</a>.  Or if you prefer the old fashioned way, see my book store links if you want to order a copy from Amazon.</p>
<p>I haven&#8217;t had time to read much of the book. So instead of a book review, this is more of an FYI.</p>
<p>I was interested in the book for the following reasons:</p>
<ul>
<li><strong>Apress</strong> did a great job with <a href="http://mitchallen.com/iphone/archives/119">Beginning iPhone Development</a> and <a href="http://mitchallen.com/iphone/archives/221">iPhone Games Projects</a></li>
<li>There&#8217;s a chapter that covers <strong>cocos2d</strong> and the <strong>Chipmunk</strong> physics engine</li>
<li>Neil Mix &#8211; who wrote <strong>Pandora Radio</strong> for the iPhone &#8211; has a chapter on audio streaming</li>
<li>There&#8217;s a chapter on multi-threading</li>
<li>There&#8217;s another chapter on writing a game</li>
</ul>
<p>As always, Apress goes for quality over quantity.  If you like your books by the pound, you may be disappointed to find that the book only has seven chapters.  But it looks to me like there is a wealth of information in it.</p>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/271/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running the Cocos2D examples</title>
		<link>http://mitchallen.com/iphone/archives/266</link>
		<comments>http://mitchallen.com/iphone/archives/266#comments</comments>
		<pubDate>Fri, 31 Jul 2009 22:15:16 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[game engines]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=266</guid>
		<description><![CDATA[If you want to play around with the Cocos2D Game Engine, the first thing that you need to do is download and unzip it to your Mac. You can get the library / project from here:  http://code.google.com/p/cocos2d-iphone/ Then if you are like a lot of people you are going to want to run the examples [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to play around with the Cocos2D Game Engine, the first thing that you need to do is download and unzip it to your Mac.</p>
<p>You can get the library / project from here:  <a title="http://code.google.com/p/cocos2d-iphone/" href="http://code.google.com/p/cocos2d-iphone">http://code.google.com/p/cocos2d-iphone/</a></p>
<p>Then if you are like a lot of people you are going to want to run the examples next.  But if you are new to Xcode you will probably be perplexed as to how to do that.</p>
<p>The information is buried in one of the links from the <a title="previous post" href="http://mitchallen.com/iphone/archives/254">previous post</a> (see <a href="http://www.cocos2d-iphone.org/forum/topic/737">http://www.cocos2d-iphone.org/forum/topic/737</a>).  But I will bring that information forward and reiterate here.  Thanks to <a title="PhilM" href="http://www.cocos2d-iphone.org/forum/profile/25">PhilM</a> of that forum for this info.</p>
<ol>
<li>Download and unzip the latest <strong>cocos2d-iphone-<em>x.y.z</em></strong> project from <a title="http://code.google.com/p/cocos2d-iphone/" href="http://code.google.com/p/cocos2d-iphone">http://code.google.com/p/cocos2d-iphone/</a></li>
<li>Double click on <strong>cocos2d-iphone.xcodeproj</strong> to launch the project in Xcode</li>
<li>On the Xcode main menu select: <strong>View / Customize Toolbar ..</strong>.</li>
<li>Drag <strong>Active Target</strong> and <strong>Active Executable</strong> to the toolbar (the person who wrote the original note also likes to use Active SDK)</li>
<li>I like to also set at the bottom <strong>Show: Icon &amp; Text</strong> and check <strong>Use Small Size</strong> &#8211; then click <strong>Done</strong></li>
<li>Now you can select any target from <strong>Active Target</strong>, click <strong>Build &amp; Go</strong> and it will run in the simulator</li>
</ol>
<p>Remember while running the examples to look at the code under the <strong>tests</strong> folder in the project.</p>
<p>Next I&#8217;d recommend looking at this tutorial:  <a title="Whitepaper: Introduction to Cocos2D iPhone" href="http://monoclestudios.com/cocos2d_whitepaper.html">http://monoclestudios.com/cocos2d_whitepaper.html</a></p>
<p>Then I&#8217;d recommend reading up on shared libraries: <a title="Easy, Modular Code Sharing Across iPhone Apps: Static Libraries and Cross-Project References" href="http://www.clintharris.net/2009/iphone-app-shared-libraries/">http://www.clintharris.net/2009/iphone-app-shared-libraries/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/266/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cocos2D Game Engine</title>
		<link>http://mitchallen.com/iphone/archives/254</link>
		<comments>http://mitchallen.com/iphone/archives/254#comments</comments>
		<pubDate>Fri, 24 Jul 2009 14:09:29 +0000</pubDate>
		<dc:creator>Mitch  Allen</dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[game engines]]></category>
		<category><![CDATA[Cocos2D]]></category>

		<guid isPermaLink="false">http://mitchallen.com/iphone/?p=254</guid>
		<description><![CDATA[Even though I&#8217;m trying to master 3D game development, I&#8217;m also interested in developing 2D games.  I&#8217;ve been looking at various iPhone game engines and am currently exploring Cocos2D.  The thing I like most about it is the price &#8211; you can download it for free.  See the project page for licensing info. I&#8217;m still [...]]]></description>
			<content:encoded><![CDATA[<p>Even though I&#8217;m trying to master 3D game development, I&#8217;m also interested in developing 2D games.  I&#8217;ve been looking at various iPhone game engines and am currently exploring Cocos2D.  The thing I like most about it is the price &#8211; you can download it for free.  See the project page for licensing info.</p>
<p>I&#8217;m still exploring the SDK, so don&#8217;t have a lot of code to show myself.  So to get you started, here are a few links:</p>
<ul>
<li><a title="http://code.google.com/p/cocos2d-iphone/" href="http://code.google.com/p/cocos2d-iphone/">http://code.google.com/p/cocos2d-iphone/</a> &#8211; the project source with info and pointers to other resources.</li>
<li><a href="http://www.cocos2d.org/doc/programming_guide/">http://www.cocos2d.org/doc/programming_guide/</a></li>
<li><a href="http://morethanmachine.com/macdev/?tag=game-demo-tutorial-series">http://morethanmachine.com/macdev/?tag=game-demo-tutorial-series</a> &#8211; some tutorials to get you started.</li>
<li><a title="http://www.cocos2d-iphone.org" href="http://www.cocos2d-iphone.org">http://www.cocos2d-iphone.org</a></li>
<li><a href="http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index">http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index</a></li>
<li><a href="http://monoclestudios.com/cocos2d_whitepaper.html">http://monoclestudios.com/cocos2d_whitepaper.html</a> &#8211; a great first tutorial.</li>
<li><a href="http://lukehatcher.com/2009/04/coloring-sprites-with-cocos2d-iphone/">http://lukehatcher.com/2009/04/coloring-sprites-with-cocos2d-iphone/</a> &#8211; an article on getting multiple sprites for free.</li>
<li><a href="http://www.bit-101.com/blog/?p=2233">http://www.bit-101.com/blog/?p=2233</a> &#8211; an article on understanding how memory management is used.</li>
<li><a href="http://www.clintharris.net/2009/iphone-app-shared-libraries/">http://www.clintharris.net/2009/iphone-app-shared-libraries/</a> &#8211; a general article on iPhone shared libraries.</li>
<li><a title="http://iphonedev.net" href="http://iphonedev.net">http://iphonedev.net</a> &#8211; tutorials.</li>
<li><a title="http://www.cocos2d-iphone.org/forum/topic/737" href="http://www.cocos2d-iphone.org/forum/topic/737">http://www.cocos2d-iphone.org/forum/topic/737</a> &#8211; &#8220;<em>Things you wish you knew when you started with cocos2d?</em>&#8221; &#8211; some useful tips from the forum participants.</li>
<li><a title="http://maniacdev.com/2009/07/a-look-at-8-different-iphone-game-engines-2d-and-3d/" href="http://maniacdev.com/2009/07/a-look-at-8-different-iphone-game-engines-2d-and-3d/">http://maniacdev.com/2009/07/a-look-at-8-different-iphone-game-engines-2d-and-3d/</a> &#8211; a nice summary of the most popular game engines for the iPhone.</li>
<li><a title="http://blog.sapusmedia.com/2008/12/how-to-use-tilemap-editor-for-cocos2d.html" href="http://blog.sapusmedia.com/2008/12/how-to-use-tilemap-editor-for-cocos2d.html">http://blog.sapusmedia.com/2008/12/how-to-use-tilemap-editor-for-cocos2d.html</a> &#8211; how to use the tilemap editor.</li>
<li><a title="http://kwigbo.com/wp/2009/03/15/cocos2d-alternative-map-editor/" href="http://kwigbo.com/wp/2009/03/15/cocos2d-alternative-map-editor/">http://kwigbo.com/wp/2009/03/15/cocos2d-alternative-map-editor</a>/ &#8211; alternative tilemap editor</li>
<li><a title="cocos2d-iphone-discuss about tile map editors" href="http://groups.google.com/group/cocos2d-iphone-discuss/browse_thread/thread/982a48f0f03458b0/f55ef55db4f68406?lnk=raot">cocos2d-iphone-discuss about tile map editors.</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mitchallen.com/iphone/archives/254/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
