<?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>myCodeStudio</title>
	<atom:link href="http://www.mycodestudio.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mycodestudio.com/blog</link>
	<description></description>
	<lastBuildDate>Sat, 24 Mar 2012 13:53:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Cocos2d for iPhone 0.99 Beginner&#8217;s Guide Review</title>
		<link>http://www.mycodestudio.com/blog/2011/03/25/cocos2d-for-iphone-0-99-beginners-guide-review/</link>
		<comments>http://www.mycodestudio.com/blog/2011/03/25/cocos2d-for-iphone-0-99-beginners-guide-review/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 01:34:19 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[cocos2d]]></category>

		<guid isPermaLink="false">http://www.mycodestudio.com/blog/?p=157</guid>
		<description><![CDATA[Book Summary The book, Cocos2d for iPhone 0.99 Beginner's Guide by Pablo Ruiz, is an introduction to game development using the cocos2d for iPhone framework (http://www.cocos2d-iphone.org/). cocos2d for iPhone is an open source game development framework for Objective-C based on the cocos2d framework originally written in Python. As the 2d in the title suggests, it [...]]]></description>
			<content:encoded><![CDATA[<h2>Book Summary</h2>
<p>The book, <a href="http://link.packtpub.com/ahECpv">Cocos2d for iPhone 0.99 Beginner's Guide</a> by Pablo Ruiz, is an introduction to game development using the cocos2d for iPhone framework (<a href="http://www.cocos2d-iphone.org/">http://www.cocos2d-iphone.org/</a>). cocos2d for iPhone is an open source game development framework for Objective-C based on the cocos2d framework originally written in Python. As the 2d in the title suggests, it is really geared towards 2D games, although there can be 3D effects. The framework is free to use even in commercial products and is actively maintained with a large community. The framework has even branched out towards iPad and Mac OS X development.<span id="more-157"></span></p>
<p>The book presents the cocos2d framework by walking the reader through building three different games: Coloured Stones (Bejeweled-like game), AerialGun (vertical shooter), and Totem Balance (physics puzzler). These games are presented through a series of steps, starting with installing cocos2d on through developing nearly complete games. Each of the steps are fairly small and the author doesn't present too many concepts in each step. However each step provides a concrete result so that the reader can quickly see the results of what was just added to the code. For example, one of the first steps in AerialGun simply displays the main player sprite. Then it quickly moves on to adding the enemy sprites and making them move and shoot. From there, steps are added to handle the accelerometer to steer the player sprite, shoot bullets from the player sprite, and handle collisions between sprites.</p>
<p>While none of these games are overly complex - there are probably hundreds in the app store like them - these games do hit the main concepts of cocos2d as well as provide an introduction to game development concepts. There are topics on touch/accelerometer handling, sprites, collisions, animations, scoreboards/huds, tile maps, menus, transitions, particles and physics. The author even adds the little extra "flash" to the games, especially in the Coloured Stones example. These include animating the appearance and disappearance of the stones, animating the background on major events, and animating score for the removed stones. While this does extend out the example a bit, it is nice that the author shows that adding effects like these are really simple to do in cocos2d yet add tremendous value visually.</p>
<p>In addition to just describing cocos2d, the author adds some game development insights along the way especially with respect to game performance such as sprite reuse, tiling backgrounds, avoiding large images, image and sound loading, and tips on using the physics engine. He also provides a brief tutorial on several common game development tools used to create tile maps and particle effects. At the end there is even a chapter on integrating OpenFeint, one of the more popular social networks for games.</p>
<h2>My Thoughts</h2>
<p><em> Full disclosure: I was sent a copy of this book to review by the publisher. However, this fact has no bearing on my review.</em></p>
<p>This book is geared towards beginners in cocos2d and to some extent game development. The author assumes the reader has basic knowledge of iPhone development and Objective-C. While a reader can start iPhone game development with this book, not having any other background in iPhone development will be an issue. If keywords like @selector, retain, and autorelease are not familiar to the reader, a good Objective-C and/or iPhone development book will be handy to have nearby.</p>
<p>In addition, while it touches on some concepts of game development as its primary purpose is cocos2d and so it does not provide information on items like artificial intelligence, multi-player, networking, and general game design. Another book or online resource is needed for these and other advanced topics.</p>
<p>As mentioned in the book summary above, the author does provide that extra little bit of detail on some of the examples to add some polish. However, I wish the book editing went through the same level of detail. There are numerous errors throughout, both in the code examples and the surrounding text, that detract from the overall book. These may confuse the reader, especially if they are truly beginners.</p>
<p>The other issue, which is common with all technical books detailing an active framework, is keeping up with the latest version of the cocos2d library (currently version 0.99.5, but 1.0 is on its way). For example, the book mentions the PVR textures can only be used for 2 or 4 bit textures, but the 0.99.5 release allows you to pack any type of texture in the PVR format for image loading speed gains.</p>
<p>As an experienced iPhone developer, with some previous exposure to cocos2d in the past, I found the book to be a good refresher on cocos2d basics. I did find the book really useful in its explanation of the more advanced topics like particle effects, node actions, and the Chipmunk physics engine. There were times I wish the book went into more details, but then again this book is a "beginner's guide" so that is expected.</p>
<p>Overall, I think this book is a good starting point for someone who wants to come up to speed on cocos2d. While a lot of information is available on the web, having all the information in one spot and presented in a consistent manner is very useful. That being said, unless the book is updated for the newer releases, the book will need to be used in conjunction with the latest API documentation on the website.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mycodestudio.com/blog/2011/03/25/cocos2d-for-iphone-0-99-beginners-guide-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocos2d Book</title>
		<link>http://www.mycodestudio.com/blog/2011/01/11/cocos2d-boo/</link>
		<comments>http://www.mycodestudio.com/blog/2011/01/11/cocos2d-boo/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 01:57:01 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[cocos2d]]></category>

		<guid isPermaLink="false">http://www.mycodestudio.com/blog/?p=150</guid>
		<description><![CDATA[I've been reading Cocos2d for iPhone 0.99 Beginner's Guide by Pablo Ruiz in preparation for an upcoming game I am writing. I'll post a review soon.]]></description>
			<content:encoded><![CDATA[<p>I've been reading <a href="http://link.packtpub.com/ahECpv">Cocos2d for iPhone 0.99 Beginner's Guide</a> by Pablo Ruiz in preparation for an upcoming game I am writing. I'll post a review soon.</p>
<p style="text-align: center;"><a href="http://link.packtpub.com/ahECpv" target="_blank"><img class="aligncenter size-full wp-image-130" style="margin-top: 10px; margin-bottom: 10px; padding: 10px; border: 1px solid #666666;" title="Cocos2D For iPhone Beginner's Guide" src="http://www.mycodestudio.com/images/Cocos2d.jpg" alt="" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mycodestudio.com/blog/2011/01/11/cocos2d-boo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Core Animation</title>
		<link>http://www.mycodestudio.com/blog/2011/01/10/coreanimation/</link>
		<comments>http://www.mycodestudio.com/blog/2011/01/10/coreanimation/#comments</comments>
		<pubDate>Tue, 11 Jan 2011 04:49:02 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[Core Animation]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.mycodestudio.com/blog/?p=108</guid>
		<description><![CDATA[It's been a while since I did a post, but I've spent some time recently exploring different aspects of Core Animation for an upcoming app. One effect I wanted to achieve was a flip effect similar to the UIViewAnimationOptionTransitionFlipFromLeft or UIViewAnimationOptionTransitionFlipFromRight on UIView. The problem with these animated transitions is that they only work when swapping [...]]]></description>
			<content:encoded><![CDATA[<p>It's been a while since I did a post, but I've spent some time recently exploring different aspects of Core Animation for an upcoming app. One effect I wanted to achieve was a flip effect similar to the <code>UIViewAnimationOptionTransitionFlipFromLeft</code> or <code>UIViewAnimationOptionTransitionFlipFromRight</code> on <code>UIView</code>. The problem with these animated transitions is that they only work when swapping out a whole view for another. These transitions don't work on sub-views. So after much googling, there didn't seem to be an example of exacting what I needed so I put one together myself. I've posted a <a href="http://www.youtube.com/watch?v=jzdDvQOo2UE" target="_blank">video</a> on YouTube showing the effect I am after (sorry for the video quality!).<br />
<span id="more-108"></span></p>
<p>You can download the sample project from <a href="http://www.mycodestudio.com/code/FlipTest.zip">here</a>, but the screenshots below show the transition in progress. Since Core Animation is focused around CALayers, my example creates to simple layers, one brown and one green, to transition between. The bottom scroll bar determines the amount of scaling that happens during the flip from one side to another - a positive setting makes it pop out towards the user. Setting this to 1.0 means the effect is just rotation around the y-axis (think of a playing card flipping from right to left around the middle), while a smaller number makes the side shrink during the flip. Click on one of the images to see the full application.</p>

<a href='http://www.mycodestudio.com/blog/2011/01/10/coreanimation/flip01/' title='Flip01'><img width="150" height="150" src="http://www.mycodestudio.com/blog/wp-content/uploads/2011/01/Flip01-150x150.png" class="attachment-thumbnail" alt="Flip01" title="Flip01" /></a>
<a href='http://www.mycodestudio.com/blog/2011/01/10/coreanimation/flip02/' title='Flip02'><img width="150" height="150" src="http://www.mycodestudio.com/blog/wp-content/uploads/2011/01/Flip02-150x150.png" class="attachment-thumbnail" alt="Flip02" title="Flip02" /></a>
<a href='http://www.mycodestudio.com/blog/2011/01/10/coreanimation/flip03/' title='Flip03'><img width="150" height="150" src="http://www.mycodestudio.com/blog/wp-content/uploads/2011/01/Flip03-150x150.png" class="attachment-thumbnail" alt="Flip03" title="Flip03" /></a>
<a href='http://www.mycodestudio.com/blog/2011/01/10/coreanimation/flip04/' title='Flip04'><img width="150" height="150" src="http://www.mycodestudio.com/blog/wp-content/uploads/2011/01/Flip04-150x150.png" class="attachment-thumbnail" alt="Flip04" title="Flip04" /></a>
<a href='http://www.mycodestudio.com/blog/2011/01/10/coreanimation/flip05/' title='Flip05'><img width="150" height="150" src="http://www.mycodestudio.com/blog/wp-content/uploads/2011/01/Flip05-150x150.png" class="attachment-thumbnail" alt="Flip05" title="Flip05" /></a>
<a href='http://www.mycodestudio.com/blog/2011/01/10/coreanimation/flip06/' title='Flip06'><img width="150" height="150" src="http://www.mycodestudio.com/blog/wp-content/uploads/2011/01/Flip06-150x150.png" class="attachment-thumbnail" alt="Flip06" title="Flip06" /></a>

<p>Now onto the code!</p>
<p>I started the example with a "View Based Application" iPhone template. First things first, be sure to QuartzCore.framework into your project to avoid build issues. The second thing to do is to include the QuartzCore header into any file that deals with Core Animation. In the example, this would be at the top of your ViewController.m file.</p>
<pre>#import &lt;QuartzCore/QuartzCore.h&gt;</pre>
<p>For this example, I create the two layers in the viewDidLoad function. I've rounded the corners to make it look a little nicer.</p>
<pre>- (void)viewDidLoad {
	[super viewDidLoad];

	isFlipped = NO;

	topLayer= [CALayer layer];
	topLayer.doubleSided = NO;
	topLayer.name = @"1";
	topLayer.frame = CGRectMake(0.0f, 0.0f, 125.0f,125.0f);
	topLayer.position = CGPointMake(160.0f, 240.0f);
	topLayer.backgroundColor = [[UIColor brownColor] CGColor];
	[topLayer setCornerRadius:8.0f];
	[topLayer setMasksToBounds:YES];

	bottomLayer = [CALayer layer];
	bottomLayer.doubleSided = NO;
	bottomLayer.name = @"2";
	bottomLayer.frame = CGRectMake(0.0f, 0.0f, 125.0f,125.0f);
	bottomLayer.position = CGPointMake(160.0f, 240.0f);
	bottomLayer.backgroundColor = [[UIColor greenColor] CGColor];
	[bottomLayer setCornerRadius:8.0f];
	[bottomLayer setMasksToBounds:YES];

        // FIX for flipping over an image
        // Assuming this is over a background UIImageView (optional for folks)
        UIImageView* v = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Space-03.jpg"]];
        // add this as the root of the current view; you can do this in IB
        [self.view insertSubview:v atIndex:0];

        // now add the flipping layers to a different view, above the UI Image, but below the controls
        // defined in the XIB
        UIView* flipView = [[UIView alloc] initWithFrame:self.view.frame];
        [self.view insertSubview:flipView aboveSubview:v];
        [v release];

        // add bottom first; add to the NEW view, not self
	[flipView.layer addSublayer:bottomLayer];
	[flipView.layer addSublayer:topLayer];
        [flipView release];

        [self updateLabel];
}</pre>
<p>Now that we have the two layers created, I set the Flip button to perform the animation.</p>
<pre>- (IBAction) flip: (id) sender
{
	// if we currently transitioning, ignore any further taps on the button until we are done
	if (isTransitioning)
		return;
	// figure out which layer is the current visible one
	CALayer* top = topLayer;
	CALayer* bot = bottomLayer;

	if ( isFlipped ) {
		top = bottomLayer;
		bot = topLayer;
	}

	CAAnimation *topAnimation = [self flipAnimationWithDuration:1.0f forLayerBeginningOnTop:YES scaleFactor:self.slider.value];
	CAAnimation *bottomAnimation = [self flipAnimationWithDuration:1.0f forLayerBeginningOnTop:NO scaleFactor:self.slider.value];

	CGFloat zDistance = 1500.0f;
	CATransform3D perspective = CATransform3DIdentity;
	perspective.m34 = -1. / zDistance;
	top.transform = perspective;
	bot.transform = perspective;

	topAnimation.delegate = self;
	[CATransaction begin];
	[top addAnimation:topAnimation forKey:@"flip"];
	[bot addAnimation:bottomAnimation forKey:@"flip"];
	[CATransaction commit];
}</pre>
<p>Where all the magic happens is in the flipAnimationWithDuration:forLayerBeginningOnTop:scaleFactor: function which creates the animation for the actual flip of the layer. If the scale is 1.0 then it skips the scaling part.</p>
<pre>-(CAAnimation *)flipAnimationWithDuration:(NSTimeInterval)aDuration forLayerBeginningOnTop:(BOOL)beginsOnTop scaleFactor:(CGFloat)scaleFactor
{
	isTransitioning = YES;
	// Rotating halfway (pi radians) around the Y axis gives the appearance of flipping
	CABasicAnimation *flipAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
	CGFloat startValue = beginsOnTop ? 0.0f : M_PI;
	CGFloat endValue = beginsOnTop ? -M_PI : 0.0f;
	flipAnimation.fromValue = [NSNumber numberWithDouble:startValue];
	flipAnimation.toValue = [NSNumber numberWithDouble:endValue];

 	// Shrinking the view makes it seem to move away from us, for a more natural effect
	// Can also grow the view to make it move out of the screen
 	CABasicAnimation *shrinkAnimation = nil;
    	if (self.slider.value != 1.0f ) {
        	shrinkAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        	shrinkAnimation.toValue = [NSNumber numberWithFloat:scaleFactor];

        	// We only have to animate the shrink in one direction, then use autoreverse to "grow"
        	shrinkAnimation.duration = aDuration * 0.5;
        	shrinkAnimation.autoreverses = YES;
    	}

    	// Combine the flipping and shrinking into one smooth animation
    	CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
    	animationGroup.animations = [NSArray arrayWithObjects:flipAnimation, shrinkAnimation, nil];

    	// As the edge gets closer to us, it appears to move faster. Simulate this in 2D with an easing function
    	animationGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
	animationGroup.duration = aDuration;

	// this really means keep the state of the object at whatever the anim ends at
	// if you don't do this then it reverts back to the original state (e.g. brown layer)
    	animationGroup.fillMode = kCAFillModeForwards;
    	animationGroup.removedOnCompletion = NO;

	return animationGroup;
}</pre>
<p>Now to reset the state at after the animation is complete use the following function:</p>
<pre>-(void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag
{
	isFlipped = !isFlipped;
	isTransitioning = NO;
}</pre>
<p>Feel free to reuse the source as you see fit. <strong>Note</strong> the <code>flip:</code> and <code>flipAnimationWithDuration:forLayerBeginningOnTop:scaleFactor:</code> functions were modified from Drew McCormack's <a href="http://www.mentalfaculty.com/mentalfaculty/Blog/Entries/2010/9/22_FLIPPIN_OUT_AT_NSVIEW.html">blog post</a> for NSViews for the Mac. He placed his code in the public domain.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mycodestudio.com/blog/2011/01/10/coreanimation/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Wading in the Free Pool</title>
		<link>http://www.mycodestudio.com/blog/2010/03/18/wading-in-the-free-pool/</link>
		<comments>http://www.mycodestudio.com/blog/2010/03/18/wading-in-the-free-pool/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 15:19:47 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.mycodestudio.com/blog/?p=100</guid>
		<description><![CDATA[On March 13th, Kascade was available for free through OpenFeint's Free Game Of The Day promotion. As this was the first time Kascade was available for free, I wasn't sure what the demand would be. Well as it turns out people love free stuff! I was quite surprised by the demand! I'm sure OpenFeint's marketing [...]]]></description>
			<content:encoded><![CDATA[<p>On March 13th, <a href="http://itunes.apple.com/us/app/kascade/id306361038?mt=8">Kascade</a> was available for free through <a href="http://openfeint.com">OpenFeint</a>'s <a href="http://freegameoftheday.com/">Free Game Of The Day</a> promotion. As this was the first time Kascade was available for free, I wasn't sure what the demand would be. </p>
<p>Well as it turns out people love free stuff! I was quite surprised by the demand! I'm sure OpenFeint's marketing helped drive up the demand in addition to the free cost. </p>
<p>So for the 28 hours (approximately) that Kascade was given away, the final numbers are:</p>
<p>- Total downloaded: 36,142<br />
- Peaked at #91 for all the Free Apps (US)<br />
- Peaked at #52 on the Free Games category<br />
- Peaked at #8 on the Free Games - Puzzle category<br />
- Peaked at #8 on the Free Games - Family category</p>
<p>After Kascade returned to the normal $0.99 price, there was a definite uptick in sales. Still early to tell if the sales will continue to stay at a higher level or will eventually return to the pre-sale levels. </p>
<p>Overall, I am quite pleased with participating in their giveaway.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mycodestudio.com/blog/2010/03/18/wading-in-the-free-pool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UITextView Scrolling</title>
		<link>http://www.mycodestudio.com/blog/2009/12/22/uitextview-scrolling/</link>
		<comments>http://www.mycodestudio.com/blog/2009/12/22/uitextview-scrolling/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 04:10:38 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://mycodestudio.com/blog/?p=83</guid>
		<description><![CDATA[After hours of fiddling (and cursing) with the UITextView scrolling behavior, I finally got the behavior I wanted. If you ever need to programmatically insert text into a UITextView and move the cursor to right after the insertion point, the following code snippet should work. Make sure you do the bolded items otherwise the UITextView [...]]]></description>
			<content:encoded><![CDATA[<p>After hours of fiddling (and cursing) with the UITextView scrolling behavior, I finally got the behavior I wanted. If you ever need to programmatically insert text into a UITextView and move the cursor to right after the insertion point, the following code snippet should work. Make sure you do the bolded items otherwise the UITextView won't scroll properly. <span id="more-83"></span></p>
<pre><strong>textview.scrollEnabled = NO;</strong>
NSString *contentsToAdd = @"some string";
NSInteger len = [contentsToAdd length];
NSRange cursorPosition = [self.textview selectedRange];
NSMutableString *tfContent = [[NSMutableString alloc] initWithString:[self.textview text]];

<span style="color: #008000;">// insert the string or replace the selection</span>
NSUInteger loc = cursorPosition.location;
if (cursorPosition.length == 0)
  [tfContent insertString:contentsToAdd atIndex:loc];
else
  [tfContent replaceCharactersInRange:cursorPosition withString:contentsToAdd];

<span style="color: #008000;">// now update the text view</span>
[self.text setText:tfContent];
cursorPosition.location = loc + len;
cursorPosition.length = 0;

<span style="color: #008000;">// should move the cursor</span>
<strong>textview.scrollEnabled = YES;</strong>
self.textview.selectedRange = cursorPosition;
[tf release];</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mycodestudio.com/blog/2009/12/22/uitextview-scrolling/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>cocos2d Part1</title>
		<link>http://www.mycodestudio.com/blog/2009/12/06/cocos2dpt1/</link>
		<comments>http://www.mycodestudio.com/blog/2009/12/06/cocos2dpt1/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 02:40:09 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[cocos2d]]></category>

		<guid isPermaLink="false">http://mycodestudio.com/blog/?p=57</guid>
		<description><![CDATA[Just started development of a new iPhone game and decided to use cocos2d for the game engine (versus the one built for Kascade). Since there are upcoming API changes, I started with the latest 0.9 alpha/beta (latest tips from subversion) since it will likely be released before the game will be completed. This entry is [...]]]></description>
			<content:encoded><![CDATA[<p>Just started development of a new iPhone game and decided to use <a href="http://www.cocos2d-iphone.org/" target="_blank">cocos2d</a> for the game engine (versus the one built for Kascade). Since there are upcoming API changes, I started with the latest 0.9 alpha/beta (latest tips from subversion) since it will likely be released before the game will be completed.</p>
<p>This entry is part 1 of a series that provides a starting point for anyone using cocos2d. This post kicks things off with useful links and setting up your project.<br />
<span id="more-57"></span></p>
<h2>Starting Links</h2>
<p>In addition to the main <a href="http://www.cocos2d-iphone.org/">cocos2d</a> site, the following is a list of links that I found helpful in starting development:</p>
<ul>
<li><a href="http://monoclestudios.com/cocos2d_whitepaper.html" target="_blank">http://monoclestudios.com/cocos2d_whitepaper.html</a></li>
<li><a href="http://lethain.com/entry/2008/oct/03/notes-on-cocos2d-iphone-development/" target="_blank">http://lethain.com/entry/2008/oct/03/notes-on-cocos2d-iphone-development/</a></li>
<li><a href="http://beta.letstalkiphone.com/2009/05/tic-tac-toe-in-cocos2d/" target="_blank">http://beta.letstalkiphone.com/2009/05/tic-tac-toe-in-cocos2d/</a></li>
<li><a href="http://mitchallen.com/iphone/archives/254" target="_blank">Misc links including the ones above</a></li>
</ul>
<p>All the links above refer to the older versions of cocos2d and so all the examples will have to be slightly modified (new in 0.9 is that all classes are now prefixed with CC).</p>
<h2>Setting Up</h2>
<p>The good news that as of 0.8.1, cocos2d provides XCode templates to start your own project. It installs three templates: basic cocos2d, cocos2d + Box2D, and cocos2d + Chipmunk. Box2D and Chipmunk are two different physics engines (Chipmunk was derived from an early version of Box2D). Box2D is C++ and Chipmunk is C.</p>
<p>Once you select the XCode template, you have a simple example application that runs in the simulator after a build.</p>
<p>One thing to note is that the template copies all the cocos2d files (and its dependencies) into your project directory. This will be problematic if you to update your cocos2d install like I will need to do (especially with the pre-beta) since I would need to recopy all the files again. That sounds painful so there should be a better/easier way... static libraries to the rescue!</p>
<h2>Static Libraries</h2>
<p>Doing some research on the web, these two links provided most of the relevant information to enable making cocos2d a static library.</p>
<ul>
<li><a href="http://blog.stormyprods.com/2008/11/using-static-libraries-with-iphone-sdk.html" target="_blank">http://blog.stormyprods.com/2008/11/using-static-libraries-with-iphone-sdk.html</a></li>
<li><a href="http://www.clintharris.net/2009/iphone-app-shared-libraries/" target="_blank">http://www.clintharris.net/2009/iphone-app-shared-libraries/</a></li>
</ul>
<p>The first link shows how to create static libraries and use them in XCode for the iPhone. I'm not sure about prior releases, but the 0.9 version comes with static libraries already included as targets in the XCode project file so this link wasn't as relevant for the setup side of things (although it is a great read).</p>
<p>However, it did point out that you would need a version for every device/simulator combination you want to work with. Not ideal. After reading the second article, there is a way to avoid that.</p>
<p>Before I get into that, you should remove the 'cocos2d sources' from your newly created project. Down in the <strong>Targets</strong> section, remove the 'cocos2d libraries'.</p>
<p><img class="aligncenter size-full wp-image-75" title="LeftSide" src="http://mycodestudio.com/blog/wp-content/uploads/2009/12/LeftSide.png" alt="LeftSide" width="280" height="450" /></p>
<p>Right click on your main target and <strong>Get Info</strong>. On the <strong>General</strong> tab, remove the 'cocos2d libraries' reference from the <strong>Direct Dependencies</strong> as well as under the <strong>Linked Libraries</strong> section.</p>
<p><img class="aligncenter size-full wp-image-78" title="TargetInfo" src="http://mycodestudio.com/blog/wp-content/uploads/2009/12/TargetInfo.png" alt="TargetInfo" width="488" height="411" /></p>
<p>At this point, I followed Clint's steps (from the second article) - except I skipped his first one: <strong>Set up a <em>shared build output </em></strong><strong>directory that will be shared by all Xcode projects.</strong></p>
<p>I didn't do this and everything seems to work fine since the referenced project will build based on your current settings. Of course, I just started my development with this so time will tell if I really needed it.</p>
<p>Once you get to the step called <strong>Configure the Library Dependencies, Linking, and Header Files</strong>, you just copy the subset of libraries from the cocos2d project reference. A good starting point for inclusion: cocos2d. Chipmunk (for physics), libpng, and CocosDenshion (for sound).</p>
<h3>A Few Notes</h3>
<p>In 0.9 libcocos2d.a actually includes FontLabel so you don't need to explicitly pull that in (if you do you will have an issue with a duplicate symbol).</p>
<p>You will need to make a single change in this version of cocos2d in order to get the libpng.a to work. Open the cocos2d project and for the libpng target, remove (uncheck) the pngtest.c from the libpng static library target. This file has a main which causes a duplicate symbol issue when compiled in with your application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mycodestudio.com/blog/2009/12/06/cocos2dpt1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenFeint Integration</title>
		<link>http://www.mycodestudio.com/blog/2009/12/01/openfeint-integration/</link>
		<comments>http://www.mycodestudio.com/blog/2009/12/01/openfeint-integration/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 02:32:08 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://mycodestudio.com/blog/?p=45</guid>
		<description><![CDATA[Well Kascade 1.1 finally hit the App Store today! It now integrates with OpenFeint, but just their Achievements and not their online Scoreboard (as they only have a single scoreboard and the current Kascade scoreboard breaks it down by all-time and the last 7 days). The OpenFeint Achievement system is pretty nice and adds an [...]]]></description>
			<content:encoded><![CDATA[<p>Well Kascade 1.1 finally hit the App Store today! It now integrates with <a href="http://www.openfeint.com">OpenFeint</a>, but just their Achievements and not their online Scoreboard (as they only have a single scoreboard and the current Kascade scoreboard breaks it down by all-time and the last 7 days). The OpenFeint Achievement system is pretty nice and adds an extra incentive to keep playing.</p>
<p>The integration was painless. After registering on their site, I followed the post on <a href="http://vimeo.com/5633994">how to integrate OpenFeint in 19 minutes</a>. For the Achievements, you use the OpenFeint website to create one or more achievements to unlock (Kascade currently has 60). Originally, you had to enter your achievements in the order that you wanted them to appear, but they've pushed out an update that now allows reordering - that really helps! I used a spreadsheet to list all the names and point values for all 60 achievements so it would be easier to change and balance rather than flipping through different webpages. Then I entered them in one by one.<br />
<span id="more-45"></span><br />
A few things to note:</p>
<ul>
<li>OpenFeint is in C++ so you have to change any files that reference it to .mm (instead of .m). To minimize this, I created an OFHandler class that made the majority of the OpenFeint API calls. My classes would then my OFHandler singleton. See the code snippet below.</li>
<li>OpenFeint's SDK has all the source code, so its easier to figure out how things really work. For example, I wanted to call their [OFAchievementService unlockAchievement: &lt;insert_value_here&gt;] API call every time a certain number of blocks were removed. I didn't want to do a network hit every time for this, but the code showed it used a database to store the achievements that were already awarded so it wouldn't make the network call again.</li>
<li>OpenFeint's Achievements do not work offline (unlike their scoreboard). Hopefully they will fix this in a new release as this would be very useful. I could write my own logic, but I'll wait and see first.</li>
<li>They auto generate #defines for all your achievements so you don't have to know the numeric value. See the OFHandler.mm section below for an example of usage.</li>
</ul>
<p>All-in-all, the OpenFeint system has been great to work with. They seem committed to adding new features and provide excellent support. If your game can take advantage of an online scoreboard/leaderboard or achievements I highly recommend it!</p>
<p><img class="aligncenter size-full wp-image-51" title="Blocks33" src="http://mycodestudio.com/blog/wp-content/uploads/2009/12/Blocks33.jpg" alt="Blocks33" width="480" height="320" /></p>
<h3>OFHandler.h</h3>
<pre>// your class would differ based on your achievements</pre>
<pre>@interface OFHandler : NSObject {

}

- (void) unlockAchievementForRemaining: (NSInteger) remaining colorCount: (GameMode) colorMode;

- (void) unlockAchievementForScore: (NSInteger) score;

- (void) unlockAchievementForColumns: (NSInteger) colCount totalCount: (NSInteger) total colorCount: (GameMode) colorMode;

- (void) unlockAchievementForHistory: (GameHistory*) hist;

- (void) unlockAchievementForRemovedBlocks: (NSInteger) numRemoved wildCards: (NSInteger) numWild;

+ (OFHandler*) singleton;

@end</pre>
<h3>OFHandler.mm</h3>
<pre>// A snippet of one of the calls. The #defines were auto generated by the OF site.
/**
 * This should be called upon every game over and checks the number of blocks remaining achievements.
 */
- (void) unlockAchievementForRemaining: (NSInteger) remaining colorCount: (GameMode) colorMode
{
 switch (remaining)
 {
   case 6:
     [OFAchievementService unlockAchievement:NO_BONUS_FOR_YOU_];
     break;
   case 5:
     [OFAchievementService unlockAchievement:FINALLY_A_BONUS_];
     break;
   case 4:
     [OFAchievementService unlockAchievement:OOOH_A_BIGGER_BONUS];
     break;
   ...
 }
 ...
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mycodestudio.com/blog/2009/12/01/openfeint-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit Tests for the iPhone</title>
		<link>http://www.mycodestudio.com/blog/2009/08/02/38/</link>
		<comments>http://www.mycodestudio.com/blog/2009/08/02/38/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 14:29:38 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://mycodestudio.com/blog/?p=38</guid>
		<description><![CDATA[Notes on one way to run iPhone Unit Tests.]]></description>
			<content:encoded><![CDATA[<p>In XCode 3.0 (not sure when they added it), there are options to add Unit Tests to your iPhone application but I was not able to get this to work properly using the <strong>iPhone</strong> Unit Test target. However I did find a <a href="http://www.mobileorchard.com/ocunit-integrated-unit-testing-in-xcode/">reference</a> to add <strong>Cocoa</strong> Unit Tests to your iPhone project. If you follow the link, you will find all the information you need. It's quick to add to your project and will allow your tests to run every time you build.</p>
<p><span id="more-38"></span></p>
<h3>Google Framework</h3>
<p>After some further work, the above setup allows easy running of unit tests. However, debugging those Unit Tests is another story. I found another <a href="http://www.luisdelarosa.com/2009/02/17/is-iphone-unit-testing-possible/">page</a> that walks<br />
through using the Google Toolkit for Mac to do unit testing. This allows you to run the unit tests as an executable and at least output console output (still can't seem to debug it). Note that with this framework, you need to set the active executable to your Testing executable in order to run. Any NSLog calls will be output to the console.</p>
<h3>Unit Test Assertions</h3>
<p>The table below is a quick reference to the different types of assertions that can be done in the UnitTest.</p>
<table border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th scope="col">OCUnit Macro</th>
<th scope="col">Purpose</th>
</tr>
</thead>
<tbody>
<tr>
<td>STAssertNil(a1, description, ...)</td>
<td>Generates an error if a1 is not nil.</td>
</tr>
<tr>
<td>STAssertNotNil(a1, description, ...)</td>
<td>Generates an error if a1 is nil.</td>
</tr>
<tr>
<td>STAssertTrue(expression, description, ...)</td>
<td>Generates an error if expression does not evaluate to true</td>
</tr>
<tr>
<td>STAssertFalse(expression, description, ...)</td>
<td>Generates an error if expression does not evaluate to false</td>
</tr>
<tr>
<td>STAssertEqualObjects(a1, a2, description, ...)</td>
<td>Generates an error if a1 is not equal to a2. Both must be Objective-C objects.</td>
</tr>
<tr>
<td>STAssertEquals(a1, a2, description, ...)</td>
<td>Generates an error if a1 is not equal to a2. Both must be C scalar values.</td>
</tr>
<tr>
<td>STAssertEqualsWithAccuracy(left, right, accuracy, description, ...)</td>
<td>Generates an error if a1 and a2 are not within a certain amount of each other. Primarily for use with floats and doubles to take into account small rounding errors due to the way they store values.</td>
</tr>
<tr>
<td>STAssertThrows(expression, description, ...)</td>
<td>Generates an error if expression does not throw an exception.</td>
</tr>
<tr>
<td>STAssertThrowsSpecific(expression, specificException, description, ...)</td>
<td>Generates an error if expression does not throw an exception of a specified class.</td>
</tr>
<tr>
<td>STAssertThrowsSpecificNamed(expr, specificException, aName, description, ...)</td>
<td>Generates an error if expression doesn’t throw an exception with a specific name.</td>
</tr>
<tr>
<td>STAssertNoThrow(expression, description, ...)</td>
<td>Generates an error if expression throws an exception.</td>
</tr>
<tr>
<td>STAssertNoThrowSpecific(expression, specificException, description, ...)</td>
<td>Generates an error if expression throws an exception of a specified class.</td>
</tr>
<tr>
<td>STAssertNoThrowSpecificNamed(expr, specificException, aName, description, ...)</td>
<td>Generates an error if expression throws an exception with a specific name.</td>
</tr>
<tr>
<td>STFail(description, ...)</td>
<td>Generates an error.</td>
</tr>
<tr>
<td>STAssertTrueNoThrow(expression, description, ...)</td>
<td>Generates an error if expression is false or if it throws an exception.</td>
</tr>
<tr>
<td>STAssertFalseNoThrow(expron, description, ...)</td>
<td>Generates an error if expression is true or if it throws an exception</td>
</tr>
</tbody>
</table>
<p style="text-align: center;"><strong>Table 1:</strong> Macros Available in OCUnit from <a href="http://developer.apple.com/mac/articles/tools/unittestingwithxcode3.html">Apple</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mycodestudio.com/blog/2009/08/02/38/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Secure Hashes</title>
		<link>http://www.mycodestudio.com/blog/2009/08/02/secure-hashes/</link>
		<comments>http://www.mycodestudio.com/blog/2009/08/02/secure-hashes/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 14:01:26 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://mycodestudio.com/blog/?p=28</guid>
		<description><![CDATA[Code to execute the SHA-1 hash over an NSString and output a hex-encoded NSString.]]></description>
			<content:encoded><![CDATA[<p>If your application requires generation of secure hashes, you can use the raw Crypto APIs. These are actually C calls and do not have nice Objective C objects to interface with. The code snippet below shows how this is done for SHA-1. The input is any NSString and the output is a hex-encoded NSString version of the hashcode. If you need other types of hashing besides SHA-1, then you will need to change the SHA1 names in the functions and constants.</p>
<p><span id="more-28"></span></p>
<pre>+ (NSString*) getHash:(NSString *) text
{
    NSData* myData =
         [text dataUsingEncoding:NSStringEncodingConversionAllowLossy];
    CC_SHA1_CTX ctx;
    uint8_t * hashBytes = NULL;
    NSData * hash = nil;

   <span style="color: #008000;"> // Malloc a buffer to hold hash.</span>
    hashBytes = malloc( CC_SHA1_DIGEST_LENGTH * sizeof(uint8_t) );
    memset((void *)hashBytes, 0x0, CC_SHA1_DIGEST_LENGTH);

    <span style="color: #008000;">// Initialize the context.</span>
    CC_SHA1_Init(&amp;ctx);
    <span style="color: #008000;">// Perform the hash.</span>
    CC_SHA1_Update(&amp;ctx, (void *)[myData bytes], [myData length]);
    <span style="color: #008000;">// Finalize the output.</span>
    CC_SHA1_Final(hashBytes, &amp;ctx);

    <span style="color: #008000;">// Build up the SHA1 data.</span>
    hash = [NSData dataWithBytes:(const void *)hashBytes
                          length:(NSUInteger)CC_SHA1_DIGEST_LENGTH];

    <span style="color: #008000;">// if could not create, then exit otherwise clean up</span>
    if(hashBytes)
      free(hashBytes);
    else
      return nil;

    <span style="color: #008000;">// now return this as an hex-encoded string</span>
    NSMutableString *stringBuffer = [NSMutableString
                                     stringWithCapacity:([hash length] * 2)];
    const unsigned char *dataBuffer = [hash bytes];
    int i;
    for (i = 0; i &lt; [hash length]; ++i)
    {
        [stringBuffer appendFormat:@"%02X", (unsigned long)dataBuffer[i]];
    }

    return [[stringBuffer copy] autorelease];
}</pre>
<p>One thing to note is the you need to include the following line:</p>
<pre>#import &lt;CommonCrypto/CommonDigest.h&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mycodestudio.com/blog/2009/08/02/secure-hashes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Let There Be Lite</title>
		<link>http://www.mycodestudio.com/blog/2009/07/30/let-there-be-light/</link>
		<comments>http://www.mycodestudio.com/blog/2009/07/30/let-there-be-light/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 04:03:22 +0000</pubDate>
		<dc:creator>Gary</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://mycodestudio.com/blog/?p=11</guid>
		<description><![CDATA[Learn how to easily create a Lite or Free version of your application with XCode project settings.]]></description>
			<content:encoded><![CDATA[<p>Creating a Lite or Free version (don't call it a 'Demo' on the App Store) of your application is  pretty easy to do assuming there your application can support reduced functionality. One way you could do this is just copy your whole project and start modifying your code to make it Lite. The biggest drawback to this is the dual maintenance of code if you have to fix a bug in both the full and Lite versions. The alternative is to create a new target in the same XCode project with different settings. This is the approach I took with Flik.</p>
<p>Fortunately for me, a Lite version of Flik translates into providing just a few levels instead of the full set of levels and so I could focus on those changes.The steps below outline what was done.<span id="more-11"></span></p>
<h3>Change Your Code</h3>
<p>Where your Lite version differs from the full version at the code level, you should add #ifdef areas that are applicable to the Lite version versus the full version. While you can do an explicit #define in your code and change this before compilation, see the 'XCode Build Settings' below to see how to have XCode do this for you.</p>
<p><code>#ifdef LITE<br />
<span style="color: #008000;">// LITE logic goes here</span><br />
#else<br />
<span style="color: #008000;">// FULL logic does here</span><br />
#endif</code></p>
<blockquote><p>To test that your targets are setup correctly, add this code somewhere:<br />
<code>#ifndef LITE<br />
#error "Not Lite"<br />
#endif <span style="color: #008000;">// LITE</span></code></p>
<p style="text-align: left;">That will cause your build to FAIL on all non-Lite builds, and SUCCEED (assuming no other compile issues) on all Lite builds.   -<a href="http://neonscape.net/">William</a> (from <a href="https://devforums.apple.com/message/31039#31039">Apple Forums</a>)</p>
</blockquote>
<h3>Copy Your Target</h3>
<p>In XCode, expand the Targets item and select your application. Right click and say duplicate. At this point you probably should rename this to end in 'Lite' or 'Free'. You may want to rename the Info.plist file as well.</p>
<p><img src="/images/devLite04.png" alt="Show Targets" width="284" /></p>
<h3>XCode Build Settings</h3>
<p>For each Build Configuration that you need (e.g. Debug, Debug Device, Device Ad Hoc Distribution, Device App Store Distribution), you need to change the following settings for the Lite version. This can be found on the Build tab of the Project Settings for your Lite Target (select your target and then select the Project &gt; Edit Active Target ... Lite).</p>
<ul>
<li>Info.plist File</li>
<li>Product Name</li>
</ul>
<blockquote><p>You can actually specify "Configuration: All Configurations" in the top left of that screen to avoid the hassle of doing this multiple times. -<a href="http://neonscape.net/">William</a> (from <a href="https://devforums.apple.com/message/31039#31039">Apple Forums</a>)</p></blockquote>
<p><img src="/images/devLite02.png" alt="XCode Settings" width="625" /></p>
<p>One other item to change on this tab is the Preprocessor Macro. This is the same as doing a #define in your code. See the section aboe on where this can be used in code.</p>
<p><img src="/images/devLite01.png" alt="Macros" width="626" /></p>
<h3>XCode Properties Settings</h3>
<p>If you add a space in your product name, this causes an issue in the Identifier field on the Properties tab. This normally starts out with: com.yourcompany.${PRODUCT_NAME:identifier}. If your name is 'App Lite', then this will fail during the upload process to Apple. You should explicitly set this to something unique, following Apple's recommended scheme.</p>
<p><img src="/images/devLite03.png" alt="Macros" width="649" /></p>
<p>While you are on this screen, you should change the Icon File to the file you will create next.</p>
<h3>Graphics and Other Files</h3>
<div class="figure57a"><img src="/images/IconLite.png" alt="Flik Lite" width="57" align="right" /></div>
<p>You should create a different icon to be displayed on the App Store. The simple way to do this is just add the word 'Lite' to it. You should make sure that this icon is added to just your Lite target and not your full target. Conversely, you should also make sure the Lite icon is <strong>not</strong> in the full target.</p>
<p><img src="/images/devLite05.png" alt="targets" width="372" /></p>
<p>You should do this with all the other images or files that should be in one version and not another. You also need to prepare other images for the iTunes App Store.<br />
That should be it. At this point you should be able to build both your full and Lite versions of your application easily. Just change the Active Target before you build.</p>
<address style="text-align: center;">Note: This was taken from the <a href="/devnotes.html">original page</a> and posted to this blog.</address>
]]></content:encoded>
			<wfw:commentRss>http://www.mycodestudio.com/blog/2009/07/30/let-there-be-light/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
