<?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>Giv Parvaneh &#187; Objective-c</title>
	<atom:link href="http://www.givp.org/blog/category/objective-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.givp.org/blog</link>
	<description>::::..::..:::::::...:::::....::......:::::::::....::::......::::::::::::::::</description>
	<lastBuildDate>Mon, 23 Jan 2012 17:50:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<meta xmlns="http://www.w3.org/1999/xhtml" name="robots" content="noindex,follow" />
		<item>
		<title>Scrolling Menus in Cocos2d</title>
		<link>http://www.givp.org/blog/2010/12/30/scrolling-menus-in-cocos2d/</link>
		<comments>http://www.givp.org/blog/2010/12/30/scrolling-menus-in-cocos2d/#comments</comments>
		<pubDate>Thu, 30 Dec 2010 13:21:51 +0000</pubDate>
		<dc:creator>Giv</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[Objective-c]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[cocos2d]]></category>

		<guid isPermaLink="false">http://www.givp.org/blog/?p=249</guid>
		<description><![CDATA[EDIT: Please note I am no longer managing this code. It has moved here: https://github.com/cocos2d/cocos2d-iphone-extensions/tree/master/Extensions/CCScrollLayer I must have spent over a week coming up with a good solution for this. The effect I was after was a scrollable menu for my game, similar to Angry Birds where the user can flip between levels but also [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>EDIT:<br />
Please note I am no longer managing this code. It has moved here: <a href="https://github.com/cocos2d/cocos2d-iphone-extensions/tree/master/Extensions/CCScrollLayer" onclick="pageTracker._trackPageview('/outgoing/github.com/cocos2d/cocos2d-iphone-extensions/tree/master/Extensions/CCScrollLayer?referer=');">https://github.com/cocos2d/cocos2d-iphone-extensions/tree/master/Extensions/CCScrollLayer</a></p></blockquote>
<p>I must have spent over a week coming up with a good solution for this. The effect I was after was a scrollable menu for my game, similar to Angry Birds where the user can flip between levels but also see a preview of the previous/next page on either end of the screen. I came across Nate Murray&#8217;s excellent <a href="http://www.xcombinator.com/2010/09/08/a-paging-uiscrollview-in-cocos2d-with-previews/" onclick="pageTracker._trackPageview('/outgoing/www.xcombinator.com/2010/09/08/a-paging-uiscrollview-in-cocos2d-with-previews/?referer=');">UIScrollView solution</a> but it wasn&#8217;t quite what I was looking for and using UIScrollView seemed like too much of an overhead. I needed something simple, preferably wrapped up in a single class. </p>
<p>After searching various community forums I finally came across <a href="http://dk101.net/2010/11/30/implementing-page-scrolling-in-cocos2d/" onclick="pageTracker._trackPageview('/outgoing/dk101.net/2010/11/30/implementing-page-scrolling-in-cocos2d/?referer=');">DK101&#8242;s solution</a> which was exactly what I was looking for. A simple CCLayer subclass that would allow me to create an array of CCLayers then add whatever I wanted to it then add the whole lot to my scene. Simple. You are able to add anything you can add to a CCLayer &#8211; so a label, menu, image etc. It will all work nicely.</p>
<p>I ended up making a few modifications to it like updating it to work with Cocos2d 0.99.5 and adding the option to set the width of the screens for the Angry Birds style preview effect. There was also an issue with the touch delegate on subsequent scenes. I have put my changes up on <a href="https://github.com/givp/Cocos2d-Menu-Scroller" onclick="pageTracker._trackPageview('/outgoing/github.com/givp/Cocos2d-Menu-Scroller?referer=');">Github</a>. Here&#8217;s a sample:</p>
<p><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/ViJoNQDWB5Q?fs=1&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ViJoNQDWB5Q?fs=1&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></p>
<p>To use it in your project:</p>
<p>1. add both files to your project<br />
2. in your scene import CCScrollLayer.h<br />
3. in your scene&#8217;s init method construct each layer and pass it to the CCScrollLayer class:</p>
<p>e.g.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// get screen size</span>
CGSize screenSize <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCDirector sharedDirector<span style="color: #002200;">&#93;</span>.winSize;
&nbsp;
<span style="color: #11740a; font-style: italic;">/////////////////////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// PAGE 1</span>
<span style="color: #11740a; font-style: italic;">////////////////////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// create a blank layer for page 1</span>
CCLayer <span style="color: #002200;">*</span>pageOne <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCLayer alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// create a label for page 1</span>
CCLabelTTF <span style="color: #002200;">*</span>label <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCLabelTTF labelWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Page 1&quot;</span> fontName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Arial Rounded MT Bold&quot;</span> fontSize<span style="color: #002200;">:</span><span style="color: #2400d9;">44</span><span style="color: #002200;">&#93;</span>;
label.position <span style="color: #002200;">=</span>  ccp<span style="color: #002200;">&#40;</span> screenSize.width <span style="color: #002200;">/</span><span style="color: #2400d9;">2</span> , screenSize.height<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span> <span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// add label to page 1 layer</span>
<span style="color: #002200;">&#91;</span>pageOne addChild<span style="color: #002200;">:</span>label<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">/////////////////////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// PAGE 2</span>
<span style="color: #11740a; font-style: italic;">////////////////////////////////////////////////</span>
<span style="color: #11740a; font-style: italic;">// create a blank layer for page 2</span>
CCLayer <span style="color: #002200;">*</span>pageTwo <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCLayer alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// create a custom font menu for page 2</span>
CCLabelBMFont <span style="color: #002200;">*</span>tlabel <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCLabelBMFont labelWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Page 2&quot;</span> fntFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;customfont.fnt&quot;</span><span style="color: #002200;">&#93;</span>;
CCMenuItemLabel <span style="color: #002200;">*</span>titem <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCMenuItemLabel itemWithLabel<span style="color: #002200;">:</span>tlabel 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>testCallback<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
CCMenu <span style="color: #002200;">*</span>menu <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCMenu menuWithItems<span style="color: #002200;">:</span> titem, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
menu.position <span style="color: #002200;">=</span> ccp<span style="color: #002200;">&#40;</span>screenSize.width<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>, screenSize.height<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// add menu to page 2</span>
<span style="color: #002200;">&#91;</span>pageTwo addChild<span style="color: #002200;">:</span>menu<span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">////////////////////////////////////////////////</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// now create the scroller and pass-in the pages (set widthOffset to 0 for fullscreen pages)</span>
CCScrollLayer <span style="color: #002200;">*</span>scroller <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCScrollLayer alloc<span style="color: #002200;">&#93;</span> initWithLayers<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> arrayWithObjects<span style="color: #002200;">:</span> pageOne,pageTwo,pageThree,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span> widthOffset<span style="color: #002200;">:</span> <span style="color: #2400d9;">230</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// finally add the scroller to your scene</span>
<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span>scroller<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p><a href="https://github.com/givp/Cocos2d-Menu-Scroller" onclick="pageTracker._trackPageview('/outgoing/github.com/givp/Cocos2d-Menu-Scroller?referer=');">Download the source</a></p>
<p>And a MASSIVE thank you to <a href="http://dk101.net/" onclick="pageTracker._trackPageview('/outgoing/dk101.net/?referer=');">DK101</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.givp.org/blog/2010/12/30/scrolling-menus-in-cocos2d/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Cocos2d Sprite Sheets (blinking animation)</title>
		<link>http://www.givp.org/blog/2010/11/07/cocos2d-sprite-sheets-blinking-animation/</link>
		<comments>http://www.givp.org/blog/2010/11/07/cocos2d-sprite-sheets-blinking-animation/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 18:12:57 +0000</pubDate>
		<dc:creator>Giv</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[Objective-c]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[cocos2d]]></category>

		<guid isPermaLink="false">http://www.givp.org/blog/?p=225</guid>
		<description><![CDATA[I struggled with this as a n00b in Cocos2d and I finally figured it out so I wanted to share it here in case someone else runs into the same challenge. You may or may not be aware of sprite sheets in traditional 2D games and in CSS where you combine a series of images [...]]]></description>
			<content:encoded><![CDATA[<p>I struggled with this as a n00b in Cocos2d and I finally figured it out so I wanted to share it here in case someone else runs into the same challenge. You may or may not be aware of sprite sheets in traditional 2D games and in CSS where you combine a series of images into a single image, then use x/y offsets to expose the bits of the image you want. Cocos2d makes this process very easy but I wish it was documented better. I&#8217;m new to this so please let me know if you think there&#8217;s a better way to do it.</p>
<p>This example assumes you know your way around an XCode project and know the basics of Objective-C and Cocos2d. If not, there are plenty of good tutorials around. See my <a href="http://www.givp.org/blog/2010/11/01/hello-cocos2d/">previous post</a> for some useful links. Also, I&#8217;m using Cocos2d 0.99.5 so some of this syntax may not work on older versions.</p>
<p>Now, onto the tutorial:</p>
<p>The first thing you want to do is get yourself a sprite sheet and associated plist file. Cocos2d has a bunch of these in its examples folder but you can also make your own using the excellent <a href="http://zwoptexapp.com/" onclick="pageTracker._trackPageview('/outgoing/zwoptexapp.com/?referer=');">Zwoptex</a> app. The app will let you add a bunch of images and it will then re-arrange them, export a single image and also generate a plist file containing all the coordinates. This means you won&#8217;t have to mess around with x/y pixels to get everything lined up.</p>
<p>Important: make sure in the Zwoptex publish settings you select Cocos2d for the coordinates format.</p>
<p>Once you have added the two files to your project, you can load all the individual frames in the cache and use them however you like.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// load the plist file into the frame cache</span>
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCSpriteFrameCache sharedSpriteFrameCache<span style="color: #002200;">&#93;</span> addSpriteFramesWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;mysprite.plist&quot;</span><span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>That&#8217;s it. Zwoptex will give each frame its own name. Look inside the plist file to see what they are called. These will most likely be the original file names of the images before you combined them into one.</p>
<p>Now that the frames are in the cache, we can create and display them as individual sprites like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;">CCSprite <span style="color: #002200;">*</span>sprite <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCSprite spriteWithSpriteFrameName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;dude1.png&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span> sprite<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>You can add any of the other frames to the scene the same way, just make sure you use the correct frame name like dude2.png, dude3.png etc. Again, if you&#8217;re not sure what the names are, just open the plist and look at the frames node.</p>
<p>Now that we have all our frames ready to use, we can do some cool things with it like animate them or use them as rollover effects for menu buttons. In the game I&#8217;m currently developing I wanted the character to blink from time to time. So I used two sprite images, one with the character&#8217;s eyes open and one with its eyes shut. You can then create a sequence and animate them like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Load sprite plist file</span>
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCSpriteFrameCache sharedSpriteFrameCache<span style="color: #002200;">&#93;</span> addSpriteFramesWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;dude_blinking.plist&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Create a blank array to store all the frames	</span>
<span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span>blinkAnimFrames <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> array<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Add the frames 3 times. One with eyes open, one shut and one open again	</span>
<span style="color: #002200;">&#91;</span>blinkAnimFrames addObject<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCSpriteFrameCache sharedSpriteFrameCache<span style="color: #002200;">&#93;</span> spriteFrameByName<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;dude_open.png&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>blinkAnimFrames addObject<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCSpriteFrameCache sharedSpriteFrameCache<span style="color: #002200;">&#93;</span> spriteFrameByName<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;dude_shut.png&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>blinkAnimFrames addObject<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCSpriteFrameCache sharedSpriteFrameCache<span style="color: #002200;">&#93;</span> spriteFrameByName<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;dude_open.png&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Create a 3-frame animation using the array and use 0.2 seconds delay between each frame	</span>
CCAnimation <span style="color: #002200;">*</span>blinkanimation <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCAnimation animationWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;blinker&quot;</span> frames<span style="color: #002200;">:</span>blinkAnimFrames<span style="color: #002200;">&#93;</span>;
CCAnimate <span style="color: #002200;">*</span>blink <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCAnimate actionWithDuration<span style="color: #002200;">:</span>0.2f animation<span style="color: #002200;">:</span>animation restoreOriginalFrame<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Now create the blinking action sequence	</span>
CCAction <span style="color: #002200;">*</span>blinkAction <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCRepeatForever actionWithAction<span style="color: #002200;">:</span>
    <span style="color: #002200;">&#91;</span>CCSequence actions<span style="color: #002200;">:</span>
        <span style="color: #002200;">&#91;</span>CCDelayTime actionWithDuration<span style="color: #002200;">:</span>2.0f<span style="color: #002200;">&#93;</span>,
        blink,
        <span style="color: #002200;">&#91;</span>CCDelayTime actionWithDuration<span style="color: #002200;">:</span>3.0f<span style="color: #002200;">&#93;</span>,
        blink,
        <span style="color: #002200;">&#91;</span>CCDelayTime actionWithDuration<span style="color: #002200;">:</span>0.2f<span style="color: #002200;">&#93;</span>,
        blink,
        <span style="color: #002200;">&#91;</span>CCDelayTime actionWithDuration<span style="color: #002200;">:</span>2.0f<span style="color: #002200;">&#93;</span>,
    <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>
<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Add the actual sprite (first frame from cache) to the scene</span>
CCSprite <span style="color: #002200;">*</span>dude <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCSprite spriteWithSpriteFrameName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;dude_open.png&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span> dude<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Finally, run the blinking animation</span>
<span style="color: #002200;">&#91;</span>dude runAction<span style="color: #002200;">:</span> blinkAction<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>If you study the blinkAction carefully, you&#8217;ll see we have just created an endless loop that runs the 3-frame blink action with some pauses in the middle. The sequence is:</p>
<p>(start loop)<br />
1 &#8211; Pause for 2 seconds<br />
2 &#8211; Blink<br />
3 &#8211; Pause for 3 seconds<br />
4 &#8211; Blink<br />
5 &#8211; Pause for 0.2 seconds<br />
6 &#8211; Blink<br />
7 &#8211; Pause for 2 seconds<br />
(end loop)</p>
<p>This gives us a semi-realistic blinking animation like this: <img src="http://www.givp.org/blog/wp-content/uploads/2010/11/blinker.gif" alt="" title="blinker" width="41" height="39" class="alignnone size-full wp-image-236" /></p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.givp.org/blog/2010/11/07/cocos2d-sprite-sheets-blinking-animation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hello Cocos2d</title>
		<link>http://www.givp.org/blog/2010/11/01/hello-cocos2d/</link>
		<comments>http://www.givp.org/blog/2010/11/01/hello-cocos2d/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 16:09:10 +0000</pubDate>
		<dc:creator>Giv</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[Objective-c]]></category>
		<category><![CDATA[cocos2d]]></category>

		<guid isPermaLink="false">http://www.givp.org/blog/?p=213</guid>
		<description><![CDATA[I&#8217;ve spent the last few weeks testing out various 2D iPhone game engines and frameworks such as GameSalad and Corona. But I&#8217;ve decided to dedicate my time to learning Cocos2d instead. GameSalad uses an intuitive GUI where you can drag and drop sprites and write behaviours to quickly develop games. Similarly, Corona lets you create [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent the last few weeks testing out various 2D iPhone game engines and frameworks such as <a href="http://gamesalad.com/" onclick="pageTracker._trackPageview('/outgoing/gamesalad.com/?referer=');">GameSalad</a> and <a href="http://www.anscamobile.com/corona/" onclick="pageTracker._trackPageview('/outgoing/www.anscamobile.com/corona/?referer=');">Corona</a>. But I&#8217;ve decided to dedicate my time to learning <a href="http://www.cocos2d-iphone.org/" onclick="pageTracker._trackPageview('/outgoing/www.cocos2d-iphone.org/?referer=');">Cocos2d</a> instead. GameSalad uses an intuitive GUI where you can drag and drop sprites and write behaviours to quickly develop games. Similarly, Corona lets you create games using the simple Lua language. But they both cost money to publish to the app store (however, I think GameSalad have just launched a new plan where they take a cut from your sales).</p>
<p>Cocos2d on the other hand is open source and has a pretty big community of developers so it&#8217;s relatively easy to get help by searching or posting questions on its <a href="http://www.cocos2d-iphone.org/forum/" onclick="pageTracker._trackPageview('/outgoing/www.cocos2d-iphone.org/forum/?referer=');">dev forums</a>. It is a pretty mature and flexible framework that comes with a bunch of templates and libraries including Box2D and Chipmunk physics engines. It&#8217;s a proven framework since there are <a href="http://www.cocos2d-iphone.org/games/" onclick="pageTracker._trackPageview('/outgoing/www.cocos2d-iphone.org/games/?referer=');">hundreds of games</a> in the app store that were developed using Cocos2d. <a href="http://www.trainyard.ca/" onclick="pageTracker._trackPageview('/outgoing/www.trainyard.ca/?referer=');">Trainyard</a>, for example, was made entirely with Cocos2d and you probably know it&#8217;s one of the most popular games in the app store at the moment.</p>
<p>It is, however, all in Objective-C and in my opinion a pretty steep learning curve if you don&#8217;t know the language. There are alternatives as mentioned before but if you&#8217;re planning to seriously build games as well as apps for iOS you probably should try and learn Objective-C now.</p>
<p>The Cocos2d documentation isn&#8217;t fantastic so I&#8217;ve had to learn it slowly by looking at tutorials and code samples. Objective-C is an alien world to me so it&#8217;s like learning 2 languages at once. But once you get your head around it, it&#8217;s actually a lot of fun. I&#8217;m going to try and post a few tutorials on my blog from time to time but if you decide to sit down and learn Objective-C and Cocos2d, you may want to start here:</p>
<p>1. <a href="ttp://amzn.com/1430228326">Objetive-C for Absolute Beginners (book)</a><br />
2. <a href="http://www.thenewboston.com/?cat=38&#038;pOpen=tutorial" onclick="pageTracker._trackPageview('/outgoing/www.thenewboston.com/?cat=38_038_pOpen=tutorial&amp;referer=');">The New Boston Objective-C tutorial screencasts</a><br />
3. <a href="http://www.thenewboston.com/?cat=22&#038;pOpen=tutorial" onclick="pageTracker._trackPageview('/outgoing/www.thenewboston.com/?cat=22_038_pOpen=tutorial&amp;referer=');">The New Boston Cocos2d tutorial screencasts</a><br />
4. <a href="http://www.raywenderlich.com/352/how-to-make-a-simple-iphone-game-with-cocos2d-tutorial" onclick="pageTracker._trackPageview('/outgoing/www.raywenderlich.com/352/how-to-make-a-simple-iphone-game-with-cocos2d-tutorial?referer=');">Ray Wenderlich&#8217;s Cocos2d game tutorial</a> (more on his site)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.givp.org/blog/2010/11/01/hello-cocos2d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone App Development with Google App Engine</title>
		<link>http://www.givp.org/blog/2010/02/14/iphone-app-dev-google-app-engine/</link>
		<comments>http://www.givp.org/blog/2010/02/14/iphone-app-dev-google-app-engine/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 12:11:04 +0000</pubDate>
		<dc:creator>Giv</dc:creator>
				<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Objective-c]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[appengine]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[memcached]]></category>

		<guid isPermaLink="false">http://www.givp.org/blog/?p=138</guid>
		<description><![CDATA[After almost a year of messing around with various iPhone development alternatives such as Phonegap and Titanium, I finally decided to learn Objective-C and do it all properly. I actually think those other frameworks are brilliant as they allow you to use familiar languages like Javascript to quickly create nice apps for both iPhone and [...]]]></description>
			<content:encoded><![CDATA[<p>After almost a year of messing around with various iPhone development alternatives such as <a href="http://phonegap.com/" onclick="pageTracker._trackPageview('/outgoing/phonegap.com/?referer=');">Phonegap</a> and <a href="http://www.appcelerator.com/" onclick="pageTracker._trackPageview('/outgoing/www.appcelerator.com/?referer=');">Titanium</a>, I finally decided to learn Objective-C and do it all properly. I actually think those other frameworks are brilliant as they allow you to use familiar languages like Javascript to quickly create nice apps for both iPhone and Android. But since they rely heavily on the web view element for loading HTML, creating sophisticated apps like Skype would be impossible.</p>
<p>So I set out to create an app for the iPhone with Objective-C. My app is pretty simple. It basically pulls in RSS news, audio podcast and video podcast feeds into a <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html?referer=');">UITableView</a> list, allowing the user to read, listen and watch news stories from the <a href="http://www.democracynow.org/" onclick="pageTracker._trackPageview('/outgoing/www.democracynow.org/?referer=');">Democracy Now!</a> website.</p>
<p><img class="alignright" title="Democracy Now! app" src="http://www.givp.org/democracyapp/img/democphone.png" alt="" width="164" height="305" /><br />
I managed to put together the app pretty quickly but I ran into a lot of issues when I tried to parse and massage the XML data. For starters, cocoa does not have native support for regular expressions (but there are several external libraries). I wanted to clean up the content I was getting back before displaying it to the user but I soon realised something that would normally take me a few minutes in Python/PHP/Javascript would take a lot longer in Objective-C. Parsing XML using <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html?referer=');">NSXMLParser</a> was an absolute nightmare and extremely slow. I rarely work with XML these days and find JSON a much easier protocol to deal with. I even tested the app with some sample JSON data using the excellent <a href="http://code.google.com/p/json-framework/" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/json-framework/?referer=');">json-framework</a> libarary and it was much easier and faster. Alas, I only had RSS feeds to work with.</p>
<p>The other problem I ran into was slow HTTP requests. It would sometimes take up to 20 seconds just to load the first screen. This was due to a combination of slow connection speeds, long response times from the data provider and a slow XML parser.</p>
<p>The solution I came up with was to do as little as possible in the phone app as far as the data was concerned. I decided to use Google App Engine to fetch the data from the source, parse, rejig, massage and beautify in Python, then serialise and return the results in JSON to the phone app to use.</p>
<p>It may sound like this would increase response times even more since the phone would have to first call GAE, then GAE would need to call the data source and then all the way back to the phone. This is true, however, once the data is with GAE we have the luxury of using <a href="http://code.google.com/appengine/docs/python/memcache/usingmemcache.html" onclick="pageTracker._trackPageview('/outgoing/code.google.com/appengine/docs/python/memcache/usingmemcache.html?referer=');">memcache</a> and <a href="http://code.google.com/appengine/docs/python/datastore/" onclick="pageTracker._trackPageview('/outgoing/code.google.com/appengine/docs/python/datastore/?referer=');">datastore</a>. The RSS and podcast feeds are updated once a day so there&#8217;s no reason to request the data from the source every time the user loads the app. Because each time we have to make the HTTP call, parse the data and load it up. This is extremely slow and unnecessary. We can just make one request a day, then parse, cleanup and cache the results for the next user that requests it.</p>
<p>So the app only talks to GAE. GAE first checks memcache to see if we have a cached version. If we don&#8217;t, it will make the HTTP call, fetch the data, parse, serialise, cache and return results. If we do have a cached version, there&#8217;s nothing else to do but to return the data. A cron job will also run every 24 hours to make sure memcache is up to date.</p>
<p><img src="http://givp.mugal.org/blog/wp-content/uploads/2010/02/bloggae.gif" alt="" /></p>
<p>If you really want a solid and reliable app, you need to think about all the edge cases also. What happens if the cache expires and the data provider&#8217;s website is down? At that exact moment a user loads the app only to get an error message saying there&#8217;s nothing to show. An unlikely scenario but not impossible. So the way I got around this issue was to store the serialised JSON output in GAE&#8217;s datastore as well. We always use the data from memcache but should memcache be empty and the data source down, we can switch over to the datastore and load yesterday&#8217;s content instead. Not ideal but better than having a broken app.</p>
<p>This is a bit of an overkill for such a simple app but it&#8217;s super fast and efficient and will work well for almost any app that relies on 3rd-party APIs. To be fair, it was my lack of experience with Objective-C that led me to using GAE. I feel much more comfortable in Python than Objective-C and I&#8217;m sure an experienced cocoa developer would have no problems parsing and massaging data in the app itself.</p>
<p>Of course there is one other edge case &#8211; Google App Engine could go down or worst, the interwebz could break. In which case, a simple error message will suffice.</p>
<p>You can download <a href="http://itunes.apple.com/app/democracy-now-war-peace-report/id353540657" onclick="pageTracker._trackPageview('/outgoing/itunes.apple.com/app/democracy-now-war-peace-report/id353540657?referer=');">Democracy Now! app on iTunes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.givp.org/blog/2010/02/14/iphone-app-dev-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>KALX 90.7 FM iPhone App</title>
		<link>http://www.givp.org/blog/2010/02/09/kalx-90-7-fm-iphone-app/</link>
		<comments>http://www.givp.org/blog/2010/02/09/kalx-90-7-fm-iphone-app/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 12:30:37 +0000</pubDate>
		<dc:creator>Giv</dc:creator>
				<category><![CDATA[Objective-c]]></category>

		<guid isPermaLink="false">http://www.givp.org/blog/?p=142</guid>
		<description><![CDATA[My first iPhone/iPod Touch app is out! I&#8217;m waiting for the approval of a second app. When that&#8217;s done, I&#8217;ll do a proper post about all things Objective-C and iPhone SDK. KALX app on iTunes Update, 28 Sep 2010: I have just added multitasking support to this app. You can now listen to the audio [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" title="KALX app" src="http://www.givp.org/kalxapp/img/kalxphone.png" alt="" width="164" height="305" />My first iPhone/iPod Touch app is out! I&#8217;m waiting for the approval of a second app. When that&#8217;s done, I&#8217;ll do a proper post about all things Objective-C and iPhone SDK.</p>
<p><a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=354549285&amp;mt=8" onclick="pageTracker._trackPageview('/outgoing/itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=354549285_amp_mt=8&amp;referer=');">KALX app on iTunes</a></p>
<p>Update, 28 Sep 2010: I have just added multitasking support to this app. You can now listen to the audio in the background while you quit and use other apps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.givp.org/blog/2010/02/09/kalx-90-7-fm-iphone-app/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  www.givp.org/blog/category/objective-c/feed/ ) in 0.38918 seconds, on Feb 4th, 2012 at 4:28 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 4th, 2012 at 5:28 am UTC -->
