<?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>Learning Iphone</title>
	<atom:link href="http://www.learningiphone.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learningiphone.com</link>
	<description>Iphone Development musings focusing on: Visual Programming / User Interaction / Game Development</description>
	<lastBuildDate>Fri, 04 Jan 2013 20:09:05 +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>Endless loop on background thread</title>
		<link>http://www.learningiphone.com/2013/01/endless-loop-on-background-thread/</link>
		<comments>http://www.learningiphone.com/2013/01/endless-loop-on-background-thread/#comments</comments>
		<pubDate>Fri, 04 Jan 2013 20:09:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://www.learningiphone.com/?p=391</guid>
		<description><![CDATA[There are times when for whatever reason, you need to have a thread run in the background an extended period of time. Here&#8217;s a simple way of accomplishing that. In the .h ( Note that we have set the variable to atomic, this is required to prevent one thread from writing while the other one [...]]]></description>
			<content:encoded><![CDATA[<p>There are times when for whatever reason, you need to have a thread run in the background an extended period of time.<br />
Here&#8217;s a simple way of accomplishing that.</p>
<p>In the .h <strong>( Note that we have set the variable to atomic, this is required to prevent one thread from writing while the other one is reading </strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> TestViewController <span style="color: #002200;">:</span> UIViewController <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">BOOL</span> _shouldContinue;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>atomic, assign<span style="color: #002200;">&#41;</span><span style="color: #a61390;">BOOL</span> shouldContinue;</pre></div></div>

<p><strong>In the .m</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewDidLoad <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>super viewDidLoad<span style="color: #002200;">&#93;</span>;
	<span style="color: #11740a; font-style: italic;">// Do any additional setup after loading the view, typically from a nib.</span>
	<span style="color: #002200;">&#91;</span>self startQueue<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>startQueue <span style="color: #002200;">&#123;</span>
	self.shouldContinue  <span style="color: #002200;">=</span> <span style="color: #a61390;">true</span>;
&nbsp;
	dispatch_queue_t aQueue <span style="color: #002200;">=</span> dispatch_get_global_queue<span style="color: #002200;">&#40;</span>DISPATCH_QUEUE_PRIORITY_DEFAULT, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
	dispatch_async<span style="color: #002200;">&#40;</span>aQueue, <span style="color: #002200;">^</span><span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">while</span><span style="color: #002200;">&#40;</span> self.shouldContinue <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
			NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Do some work here&quot;</span><span style="color: #002200;">&#41;</span>;
			<span style="color: #002200;">&#91;</span><span style="color: #400080;">NSThread</span> sleepForTimeInterval<span style="color: #002200;">:</span> <span style="color: #2400d9;">1.0</span><span style="color: #002200;">/</span><span style="color: #2400d9;">60.0</span><span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.learningiphone.com/2013/01/endless-loop-on-background-thread/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Cinder in an iOS project</title>
		<link>http://www.learningiphone.com/2012/12/using-cinder-in-an-ios-project/</link>
		<comments>http://www.learningiphone.com/2012/12/using-cinder-in-an-ios-project/#comments</comments>
		<pubDate>Fri, 07 Dec 2012 18:01:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[CCGL]]></category>
		<category><![CDATA[cinder]]></category>
		<category><![CDATA[combining]]></category>

		<guid isPermaLink="false">http://www.learningiphone.com/?p=384</guid>
		<description><![CDATA[One of the problems when using Cinder in an iOS project, is that the default template essentially wants to take over the entire application. No more Objective-C, or UIKit. Which you might think, Oh no! I don&#8217;t want to re-implement all those UI elements people are accustomed to on iOS. Luckily there islibrary out currently [...]]]></description>
			<content:encoded><![CDATA[<p>One of the problems when using <a href="http://libcinder.org">Cinder</a> in an iOS project, is that the default template essentially wants to take over the entire application. No more Objective-C, or UIKit. Which you might think, Oh no! I don&#8217;t want to re-implement all those UI elements people are accustomed to on iOS.</p>
<p>Luckily there islibrary out currently which allows you to use Cinder in an iOS project.<br />
<strong>CCGLTouch Is a great library</strong> from <a href="http://smalllab.org">smalllab.org</a>, the repository is located at<br />
<a href="https://github.com/smallab/CCGLTouch-XCode-Templates">https://github.com/smallab/CCGLTouch-XCode-Templates</a></p>
<p>Currently there are two bugs in it, which will cause the application to crash in an ARC project.<br />
However they&#8217;re both simple fixes,  just modify these two functions in the project:</p>
<p><strong>MyAppDelegate.mm</strong> Remove duplicate allocation of MyCCGLView</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>launch <span style="color: #002200;">&#123;</span>    
	<span style="color: #11740a; font-style: italic;">// our CCGLTouchView being added as a subview</span>
	ccglView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MyCCGLView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">0.0</span>, <span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span>.bounds.size.width, <span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span>.bounds.size.height<span style="color: #002200;">-</span><span style="color: #2400d9;">70.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>viewController view<span style="color: #002200;">&#93;</span> addSubview<span style="color: #002200;">:</span>ccglView<span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// set our view controller's prop that will hold a pointer to our newly created CCGLTouchView</span>
    <span style="color: #002200;">&#91;</span>viewController setCCGLView<span style="color: #002200;">:</span>ccglView<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// viewController as the root view for our window</span>
    super.window.rootViewController <span style="color: #002200;">=</span> viewController;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><strong> CCGLTouchView.mm</strong> Prevent application crash on dealloc by invalidating CADisplaylink</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>super stopAnimation<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>EAGLContext currentContext<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> context<span style="color: #002200;">&#41;</span>
        <span style="color: #002200;">&#91;</span>EAGLContext setCurrentContext<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>context release<span style="color: #002200;">&#93;</span>;
    context <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    sharegroup <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #002200;">&#91;</span>ccglCapture release<span style="color: #002200;">&#93;</span>;
    ccglCapture <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>It&#8217;s a really great library, works wonderfully under iOS with no hiccups when the view is removed from the display hierarchy !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.learningiphone.com/2012/12/using-cinder-in-an-ios-project/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Combining Cocos2D with UIKit and UIToolbar</title>
		<link>http://www.learningiphone.com/2011/03/combining-cocos2d-with-uikit-and-uitoolbar/</link>
		<comments>http://www.learningiphone.com/2011/03/combining-cocos2d-with-uikit-and-uitoolbar/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 04:05:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[cocos2d]]></category>
		<category><![CDATA[uikit]]></category>

		<guid isPermaLink="false">http://www.learningiphone.com/?p=350</guid>
		<description><![CDATA[Cocos2D is an awesome 2D iphone game engine, it&#8217;s just really really good and the code inside is nicely organized. However, to a beginner using Cocos2D it would seem that it does not work with UIKit based applications, this impression is largely Cocos2D&#8217;s fault. I recently started a new game, and my plan is to [...]]]></description>
			<content:encoded><![CDATA[<p>Cocos2D is an awesome 2D iphone game engine, it&#8217;s just really really good and the code inside is nicely organized.<br />
However, to a beginner using Cocos2D it would seem that it does not work with UIKit based applications, this impression is largely Cocos2D&#8217;s fault.</p>
<p>I recently started a new game, and my plan is to use UIKit for some of the level-creation and imo there&#8217;s no need to use Cocos2D to simulate UIKit when UIKit is already an amazing UIKit simulator and readily available.</p>
<p>Last time I posted a similar idea, a lot of people found it useful, I started doing a write-up but to be honest it involves many steps that need explaining, and i&#8217;m not great at it.</p>
<p>So this time i&#8217;m instead providing it as a xcode project which you can open and compile and just start using!</p>
<h1>Download / Repository</h1>
<p><a href="https://github.com/onedayitwillmake/Cocos2D-UIToolbar">https://github.com/onedayitwillmake/Cocos2D-UIToolbar</a></p>
<h1>Preview</h1>
<p><a href="http://www.learningiphone.com/wp-content/uploads/2011/03/Screen-shot-2011-03-19-at-12.25.42-AM.png"><img title="Screen shot 2011-03-19 at 12.25.42 AM" src="http://www.learningiphone.com/wp-content/uploads/2011/03/Screen-shot-2011-03-19-at-12.25.42-AM.png" alt="" width="580" height="298" /></a></p>
<h1><a href="http://www.learningiphone.com/wp-content/uploads/2011/03/Screen-shot-2011-03-19-at-1.30.33-AM.png"><img class="alignnone size-full wp-image-359" title="Screen shot 2011-03-19 at 1.30.33 AM" src="http://www.learningiphone.com/wp-content/uploads/2011/03/Screen-shot-2011-03-19-at-1.30.33-AM.png" alt="" width="580" height="298" /></a></h1>
<h1>Slight detail</h1>
<ul>
<li>Cocos2D lives in side a EAGLView, and EAGLView is just a view that you can insert into other views!</li>
<li>Especially in recent versions of iOS it plays very very nicely with other UIView&#8217;s occupying the screen at the same time</li>
<li>I started off with Cocos2D Box2D template, put the default logic in RootViewController inside of a new UIViewController and made sure Cocos2D was not attaching itself to the window.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.learningiphone.com/2011/03/combining-cocos2d-with-uikit-and-uitoolbar/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Cocos2D Forced Kerning</title>
		<link>http://www.learningiphone.com/2011/01/cocos2d-forced-kerning/</link>
		<comments>http://www.learningiphone.com/2011/01/cocos2d-forced-kerning/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 00:28:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[categories]]></category>
		<category><![CDATA[cocos2d]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[obj-c-runtime]]></category>

		<guid isPermaLink="false">http://www.learningiphone.com/?p=338</guid>
		<description><![CDATA[In Cocos2D you display text, any number of ways. A popular method for displaying text is to use BitmapFont, that is &#8211; a font created in a program which outputs two files. A bitmap (say a png for example), and a plain text &#8216;.fnt&#8217; file, containing information regarding where each character is in that file. [...]]]></description>
			<content:encoded><![CDATA[<p>In Cocos2D you display text, any number of ways. A popular method for displaying text is to use BitmapFont, that is &#8211; a font created in a program which outputs two files. A bitmap (say a png for example), and a plain text &#8216;.fnt&#8217; file, containing information regarding where each character is in that file.</p>
<p>There are many programs that do this well, I use Heiro which is a free java based bitmap font creator.<br />
A benefit of these programs as well, is that can &#8216;bake&#8217; in certain effects such as an inset/glow/drop shadow &#8211; on to the text so it doesn&#8217;t have to be calculated every frame.</p>
<p>The problem with that however, is that it requires a lot of &#8216;padding&#8217; on the font so the glow from the letter &#8216;A&#8217; doesn&#8217;t spill to the letter &#8216;B&#8217;.</p>
<h2>So you end up with something that looks like this</h2>
<p><a href="http://www.learningiphone.com/wp-content/uploads/2011/01/GothamBoldOrangeWithGlowAt20pts1.png"><img class="alignnone size-full wp-image-342" title="GothamBoldOrangeWithGlowAt20pts" src="http://www.learningiphone.com/wp-content/uploads/2011/01/GothamBoldOrangeWithGlowAt20pts1.png" alt="" width="256" height="256" /></a><a href="http://www.learningiphone.com/wp-content/uploads/2011/01/Screen-shot-2011-01-30-at-7.13.28-PM.png"><img class="alignnone size-medium wp-image-343" title="Screen shot 2011-01-30 at 7.13.28 PM" src="http://www.learningiphone.com/wp-content/uploads/2011/01/Screen-shot-2011-01-30-at-7.13.28-PM-300x200.png" alt="" width="300" height="200" /></a></p>
<h2>However what you would really like is something like this:</h2>
<p><a href="http://www.learningiphone.com/wp-content/uploads/2011/01/Screen-shot-2011-01-30-at-7.15.20-PM.png"><img class="alignnone size-medium wp-image-344" title="Screen shot 2011-01-30 at 7.15.20 PM" src="http://www.learningiphone.com/wp-content/uploads/2011/01/Screen-shot-2011-01-30-at-7.15.20-PM-300x203.png" alt="" width="300" height="203" /></a></p>
<hr />
<p>Much better!</p>
<p>So how do we get that, well my method was to implement a iVar &#8216;forcedKerning&#8217; variable into the bitmap font class &#8211; CCLabelBMFont .</p>
<p>This left me with a problem, when i upgraded Cocos2D, i over wrote my changes, and also for a while before that i was afraid to upgrade Cocos2D library version because of what i would break. So i started trying to figure out a different way to implement it using Categories.</p>
<h1>Storing a variable using categories:</h1>
<p>﻿The Main problem, was that I needed to store the variable &#8216;forcedKerning&#8217; for each instance of the class, however I did not want to create a global dictionary or the like, and you cannot create iVars in a category.</p>
<p>Since iOS 3.1, and OSX 10.6 there is something called &#8216;<strong>objc_getAssociatedObject</strong>&#8216; and &#8216;<strong>objc_setAssociatedObject</strong>&#8216;<br />
Which allows you to, essentially create a dynamic property to an existing class.</p>
<p>The &#8216;get&#8217; takes two parameters, the object itself (the class instance), and a void <em>UNIQUE</em> pointer. Because that is used as the key. So the other bit of trickiery was figuring out a pointer, i can use that i can then access in a different method. Namely the setter.</p>
<p>The trick was to use @selector(setMyKey) as the pointer to the property!</p>
<h2>Putting it together, how to force extra kerning with Cocos2D Bitmap font!</h2>
<h1>Update for Cocos2D 1.0.x, update by orninn</h1>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #11740a; font-style: italic;">//  CCLabelBMFont+Kerning.m</span>
<span style="color: #11740a; font-style: italic;">//  Junny</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mario Gonzalez on 1/30/11.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2011 Whale Island Games. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #6e371a;">#import &lt;objc/runtime.h&gt;</span>
&nbsp;
&nbsp;
<span style="color: #a61390;">@interface</span> CCLabelBMFont <span style="color: #002200;">&#40;</span>kerning<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> createFontChars;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">float</span> forcedKerning;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> CCLabelBMFont <span style="color: #002200;">&#40;</span>kerning<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span> forcedKerning <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>objc_getAssociatedObject<span style="color: #002200;">&#40;</span>self, <span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>forcedKerning<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> floatValue<span style="color: #002200;">&#93;</span>;
<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> setForcedKerning<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>aValue <span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span>aNumber <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> numberWithFloat<span style="color: #002200;">:</span>aValue<span style="color: #002200;">&#93;</span>;
	objc_setAssociatedObject<span style="color: #002200;">&#40;</span>self, <span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>forcedKerning<span style="color: #002200;">&#41;</span>, aNumber, OBJC_ASSOCIATION_RETAIN_NONATOMIC<span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#91;</span>self createFontChars<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> createFontChars
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">int</span> nextFontPositionX <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
	<span style="color: #a61390;">int</span> nextFontPositionY <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
	unichar prev <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">1</span>;
	<span style="color: #a61390;">int</span> kerningAmount <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
&nbsp;
	CGSize tmpSize <span style="color: #002200;">=</span> CGSizeZero;
&nbsp;
	<span style="color: #a61390;">int</span> longestLine <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
	<span style="color: #a61390;">int</span> totalHeight <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
&nbsp;
	<span style="color: #a61390;">int</span> quantityOfLines <span style="color: #002200;">=</span> <span style="color: #2400d9;">1</span>;
&nbsp;
	NSUInteger stringLen <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>string_ length<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> <span style="color: #002200;">!</span> stringLen <span style="color: #002200;">&#41;</span>
		<span style="color: #a61390;">return</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// quantity of lines NEEDS to be calculated before parsing the lines,</span>
	<span style="color: #11740a; font-style: italic;">// since the Y position needs to be calcualted before hand</span>
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>NSUInteger i<span style="color: #002200;">=</span><span style="color: #2400d9;">0</span>; i &lt; stringLen<span style="color: #002200;">-</span><span style="color: #2400d9;">1</span>;i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		unichar c <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>string_ characterAtIndex<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> c<span style="color: #002200;">==</span><span style="color: #bf1d1a;">'<span style="color: #2400d9;">\n</span>'</span><span style="color: #002200;">&#41;</span>
			quantityOfLines<span style="color: #002200;">++</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	totalHeight <span style="color: #002200;">=</span> configuration_<span style="color: #002200;">-</span>&gt;commonHeight_ <span style="color: #002200;">*</span> quantityOfLines;
	nextFontPositionY <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>configuration_<span style="color: #002200;">-</span>&gt;commonHeight_ <span style="color: #002200;">-</span> configuration_<span style="color: #002200;">-</span>&gt;commonHeight_<span style="color: #002200;">*</span>quantityOfLines<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>NSUInteger i<span style="color: #002200;">=</span><span style="color: #2400d9;">0</span>; i&lt;stringLen; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		unichar c <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>string_ characterAtIndex<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;
		NSAssert<span style="color: #002200;">&#40;</span> c &lt; kCCBMFontMaxChars, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;BitmapFontAtlas: character outside bounds&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
		<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>c <span style="color: #002200;">==</span> <span style="color: #bf1d1a;">'<span style="color: #2400d9;">\n</span>'</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
			nextFontPositionX <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
			nextFontPositionY <span style="color: #002200;">-=</span> configuration_<span style="color: #002200;">-</span>&gt;commonHeight_;
			<span style="color: #a61390;">continue</span>;
		<span style="color: #002200;">&#125;</span>
&nbsp;
		kerningAmount <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self kerningAmountForFirst<span style="color: #002200;">:</span>prev second<span style="color: #002200;">:</span>c<span style="color: #002200;">&#93;</span>;
&nbsp;
        ccBMFontDef <span style="color: #002200;">*</span>fontDef <span style="color: #002200;">=</span> <span style="color: #a61390;">NULL</span>;
        <span style="color: #a61390;">unsigned</span> <span style="color: #a61390;">int</span> charKey <span style="color: #002200;">=</span> c;
        HASH_FIND_INT<span style="color: #002200;">&#40;</span>configuration_<span style="color: #002200;">-</span>&gt;BMFontHash_,<span style="color: #002200;">&amp;</span>charKey, fontDef<span style="color: #002200;">&#41;</span>;
&nbsp;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>fontDef<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>	
			CGRect rect <span style="color: #002200;">=</span> fontDef<span style="color: #002200;">-</span>&gt;rect;
&nbsp;
			CCSprite <span style="color: #002200;">*</span>fontChar;
			fontChar <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>CCSprite<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#91;</span>self getChildByTag<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;
			<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> <span style="color: #002200;">!</span> fontChar <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
				fontChar <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCSprite alloc<span style="color: #002200;">&#93;</span> initWithBatchNode<span style="color: #002200;">:</span>self rectInPixels<span style="color: #002200;">:</span>rect<span style="color: #002200;">&#93;</span>;
				<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span>fontChar z<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span> tag<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;
			<span style="color: #002200;">&#125;</span>
			<span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
				<span style="color: #11740a; font-style: italic;">// reusing fonts</span>
				<span style="color: #002200;">&#91;</span>fontChar setTextureRectInPixels<span style="color: #002200;">:</span>rect rotated<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span> untrimmedSize<span style="color: #002200;">:</span>rect.size<span style="color: #002200;">&#93;</span>;
&nbsp;
				<span style="color: #11740a; font-style: italic;">// restore to default in case they were modified</span>
				fontChar.visible <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
				fontChar.opacity <span style="color: #002200;">=</span> <span style="color: #2400d9;">255</span>;
			<span style="color: #002200;">&#125;</span>
&nbsp;
			<span style="color: #a61390;">float</span> yOffset <span style="color: #002200;">=</span> configuration_<span style="color: #002200;">-</span>&gt;commonHeight_ <span style="color: #002200;">-</span> fontDef.yOffset;
			fontChar.positionInPixels <span style="color: #002200;">=</span> ccp<span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>nextFontPositionX <span style="color: #002200;">+</span> fontDef<span style="color: #002200;">-</span>&gt;xOffset <span style="color: #002200;">+</span> fontDef<span style="color: #002200;">-</span>&gt;rect.size.width<span style="color: #002200;">*</span>0.5f <span style="color: #002200;">+</span> kerningAmount,
											<span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>nextFontPositionY <span style="color: #002200;">+</span> yOffset <span style="color: #002200;">-</span> rect.size.height<span style="color: #002200;">*</span>0.5f <span style="color: #002200;">&#41;</span>;
&nbsp;
&nbsp;
			<span style="color: #11740a; font-style: italic;">// update kerning</span>
&nbsp;
			nextFontPositionX <span style="color: #002200;">+=</span> fontDef<span style="color: #002200;">-</span>&gt;xAdvance <span style="color: #002200;">+</span> kerningAmount;
			nextFontPositionX <span style="color: #002200;">+=</span> <span style="color: #002200;">&#91;</span>self forcedKerning<span style="color: #002200;">&#93;</span>;
&nbsp;
			prev <span style="color: #002200;">=</span> c;
&nbsp;
			<span style="color: #11740a; font-style: italic;">// Apply label properties</span>
			<span style="color: #002200;">&#91;</span>fontChar setOpacityModifyRGB<span style="color: #002200;">:</span>opacityModifyRGB_<span style="color: #002200;">&#93;</span>;
			<span style="color: #11740a; font-style: italic;">// Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on</span>
			<span style="color: #002200;">&#91;</span>fontChar setColor<span style="color: #002200;">:</span>color_<span style="color: #002200;">&#93;</span>;
&nbsp;
			<span style="color: #11740a; font-style: italic;">// only apply opacity if it is different than 255 )</span>
			<span style="color: #11740a; font-style: italic;">// to prevent modifying the color too (issue #610)</span>
			<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> opacity_ <span style="color: #002200;">!=</span> <span style="color: #2400d9;">255</span> <span style="color: #002200;">&#41;</span>
				<span style="color: #002200;">&#91;</span>fontChar setOpacity<span style="color: #002200;">:</span> opacity_<span style="color: #002200;">&#93;</span>;
&nbsp;
			<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>longestLine &lt; nextFontPositionX<span style="color: #002200;">&#41;</span>
				longestLine <span style="color: #002200;">=</span> nextFontPositionX;
		<span style="color: #002200;">&#125;</span>
	<span style="color: #002200;">&#125;</span>
&nbsp;
	tmpSize.width <span style="color: #002200;">=</span> longestLine;
	tmpSize.height <span style="color: #002200;">=</span> totalHeight;
&nbsp;
	<span style="color: #002200;">&#91;</span>self setContentSizeInPixels<span style="color: #002200;">:</span>tmpSize<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<h1>Original version (left for reference)</h1>
<p>// Create a file called CCLabelBMFont+Kerning.m</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;">//  CCLabelBMFont+Kerning.m</span>
<span style="color: #11740a; font-style: italic;">//  Junny</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Mario Gonzalez on 1/30/11.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2011 Whale Island Games. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #6e371a;">#import &lt;objc/runtime.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> CCLabelBMFont <span style="color: #002200;">&#40;</span>kerning<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> createFontChars;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">float</span> forcedKerning;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> CCLabelBMFont <span style="color: #002200;">&#40;</span>kerning<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span> forcedKerning <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>objc_getAssociatedObject<span style="color: #002200;">&#40;</span>self, <span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>forcedKerning<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> floatValue<span style="color: #002200;">&#93;</span>;
<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> setForcedKerning<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>aValue <span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span>aNumber <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> numberWithFloat<span style="color: #002200;">:</span>aValue<span style="color: #002200;">&#93;</span>;
	objc_setAssociatedObject<span style="color: #002200;">&#40;</span>self, <span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>forcedKerning<span style="color: #002200;">&#41;</span>, aNumber, OBJC_ASSOCIATION_RETAIN_NONATOMIC<span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#91;</span>self createFontChars<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> createFontChars
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">int</span> nextFontPositionX <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
	<span style="color: #a61390;">int</span> nextFontPositionY <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
	unichar prev <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">1</span>;
	<span style="color: #a61390;">int</span> kerningAmount <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
&nbsp;
	CGSize tmpSize <span style="color: #002200;">=</span> CGSizeZero;
&nbsp;
	<span style="color: #a61390;">int</span> longestLine <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
	<span style="color: #a61390;">int</span> totalHeight <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
&nbsp;
	<span style="color: #a61390;">int</span> quantityOfLines <span style="color: #002200;">=</span> <span style="color: #2400d9;">1</span>;
	<span style="color: #a61390;">float</span> localForcedKerning <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self forcedKerning<span style="color: #002200;">&#93;</span>;
	NSUInteger stringLen <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>string_ length<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> <span style="color: #002200;">!</span> stringLen <span style="color: #002200;">&#41;</span>
		<span style="color: #a61390;">return</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// quantity of lines NEEDS to be calculated before parsing the lines,</span>
	<span style="color: #11740a; font-style: italic;">// since the Y position needs to be calcualted before hand</span>
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>NSUInteger i<span style="color: #002200;">=</span><span style="color: #2400d9;">0</span>; i &lt; stringLen<span style="color: #002200;">-</span><span style="color: #2400d9;">1</span>;i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		unichar c <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>string_ characterAtIndex<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> c<span style="color: #002200;">==</span><span style="color: #bf1d1a;">'<span style="color: #2400d9;">\n</span>'</span><span style="color: #002200;">&#41;</span>
			quantityOfLines<span style="color: #002200;">++</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	totalHeight <span style="color: #002200;">=</span> configuration_<span style="color: #002200;">-</span>&gt;commonHeight_ <span style="color: #002200;">*</span> quantityOfLines;
	nextFontPositionY <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>configuration_<span style="color: #002200;">-</span>&gt;commonHeight_ <span style="color: #002200;">-</span> configuration_<span style="color: #002200;">-</span>&gt;commonHeight_<span style="color: #002200;">*</span>quantityOfLines<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>NSUInteger i<span style="color: #002200;">=</span><span style="color: #2400d9;">0</span>; i&lt;stringLen; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		unichar c <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>string_ characterAtIndex<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;
		NSAssert<span style="color: #002200;">&#40;</span> c &lt; kCCBMFontMaxChars, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;BitmapFontAtlas: character outside bounds&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
		<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>c <span style="color: #002200;">==</span> <span style="color: #bf1d1a;">'<span style="color: #2400d9;">\n</span>'</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
			nextFontPositionX <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
			nextFontPositionY <span style="color: #002200;">-=</span> configuration_<span style="color: #002200;">-</span>&gt;commonHeight_;
			<span style="color: #a61390;">continue</span>;
		<span style="color: #002200;">&#125;</span>
&nbsp;
		kerningAmount <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#91;</span>self kerningAmountForFirst<span style="color: #002200;">:</span>prev second<span style="color: #002200;">:</span>c<span style="color: #002200;">&#93;</span>;
&nbsp;
		ccBMFontDef fontDef <span style="color: #002200;">=</span> configuration_<span style="color: #002200;">-</span>&gt;BMFontArray_<span style="color: #002200;">&#91;</span>c<span style="color: #002200;">&#93;</span>;
&nbsp;
		CGRect rect <span style="color: #002200;">=</span> fontDef.rect;
&nbsp;
		CCSprite <span style="color: #002200;">*</span>fontChar;
&nbsp;
		fontChar <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>CCSprite<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#91;</span>self getChildByTag<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> <span style="color: #002200;">!</span> fontChar <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
			fontChar <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCSprite alloc<span style="color: #002200;">&#93;</span> initWithBatchNode<span style="color: #002200;">:</span>self rectInPixels<span style="color: #002200;">:</span>rect<span style="color: #002200;">&#93;</span>;
			<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span>fontChar z<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span> tag<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;
			<span style="color: #002200;">&#91;</span>fontChar release<span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#125;</span>
		<span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
			<span style="color: #11740a; font-style: italic;">// reusing fonts</span>
			<span style="color: #002200;">&#91;</span>fontChar setTextureRectInPixels<span style="color: #002200;">:</span>rect rotated<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span> untrimmedSize<span style="color: #002200;">:</span>rect.size<span style="color: #002200;">&#93;</span>;
&nbsp;
			<span style="color: #11740a; font-style: italic;">// restore to default in case they were modified</span>
			fontChar.visible <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
			fontChar.opacity <span style="color: #002200;">=</span> <span style="color: #2400d9;">255</span>;
		<span style="color: #002200;">&#125;</span>
&nbsp;
		<span style="color: #a61390;">float</span> yOffset <span style="color: #002200;">=</span> configuration_<span style="color: #002200;">-</span>&gt;commonHeight_ <span style="color: #002200;">-</span> fontDef.yOffset;
		fontChar.positionInPixels <span style="color: #002200;">=</span> ccp<span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>nextFontPositionX <span style="color: #002200;">+</span> fontDef.xOffset <span style="color: #002200;">+</span> fontDef.rect.size.width<span style="color: #002200;">*</span>0.5f <span style="color: #002200;">+</span> kerningAmount,
										<span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>nextFontPositionY <span style="color: #002200;">+</span> yOffset <span style="color: #002200;">-</span> rect.size.height<span style="color: #002200;">*</span>0.5f <span style="color: #002200;">&#41;</span>;
&nbsp;
		<span style="color: #11740a; font-style: italic;">// update kerning</span>
&nbsp;
		nextFontPositionX <span style="color: #002200;">+=</span> configuration_<span style="color: #002200;">-</span>&gt;BMFontArray_<span style="color: #002200;">&#91;</span>c<span style="color: #002200;">&#93;</span>.xAdvance <span style="color: #002200;">+</span> kerningAmount;
		nextFontPositionX <span style="color: #002200;">+=</span> localForcedKerning;
&nbsp;
		prev <span style="color: #002200;">=</span> c;
&nbsp;
		<span style="color: #11740a; font-style: italic;">// Apply label properties</span>
		<span style="color: #002200;">&#91;</span>fontChar setOpacityModifyRGB<span style="color: #002200;">:</span>opacityModifyRGB_<span style="color: #002200;">&#93;</span>;
		<span style="color: #11740a; font-style: italic;">// Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on</span>
		<span style="color: #002200;">&#91;</span>fontChar setColor<span style="color: #002200;">:</span>color_<span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #11740a; font-style: italic;">// only apply opacity if it is different than 255 )</span>
		<span style="color: #11740a; font-style: italic;">// to prevent modifying the color too (issue #610)</span>
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> opacity_ <span style="color: #002200;">!=</span> <span style="color: #2400d9;">255</span> <span style="color: #002200;">&#41;</span>
			<span style="color: #002200;">&#91;</span>fontChar setOpacity<span style="color: #002200;">:</span> opacity_<span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>longestLine &lt; nextFontPositionX<span style="color: #002200;">&#41;</span>
			longestLine <span style="color: #002200;">=</span> nextFontPositionX;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	tmpSize.width <span style="color: #002200;">=</span> longestLine;
	tmpSize.height <span style="color: #002200;">=</span> totalHeight;
&nbsp;
	<span style="color: #002200;">&#91;</span>self setContentSizeInPixels<span style="color: #002200;">:</span>tmpSize<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p>For now i&#8217;m duplicating the original createFontChars method, via copy paste, this is a big nono &#8211; but im looking to undo that, and it&#8217;s still much better than modifying the Libraries class file and being stuck to it forever. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.learningiphone.com/2011/01/cocos2d-forced-kerning/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>New Stanford course is online</title>
		<link>http://www.learningiphone.com/2011/01/new-stanford-course-is-online/</link>
		<comments>http://www.learningiphone.com/2011/01/new-stanford-course-is-online/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 14:02:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://www.learningiphone.com/?p=333</guid>
		<description><![CDATA[I learned a lot by watching the original course, nothing like having someone explain in lecture form, after reading about these concepts for a while. And now it looks like, they&#8217;ve updated the course. The new instructor has a more calm style, seems like it will be good. http://itunes.apple.com/us/itunes-u/developing-apps-for-ios-sd/id395631522 This is from the first few minutes [...]]]></description>
			<content:encoded><![CDATA[<p>I learned a lot by watching the original course, nothing like having someone explain in lecture form, after reading about these concepts for a while. And now it looks like, they&#8217;ve updated the course.</p>
<p>The new instructor has a more calm style, seems like it will be good.<br />
<a href="http://itunes.apple.com/us/itunes-u/developing-apps-for-ios-sd/id395631522">http://itunes.apple.com/us/itunes-u/developing-apps-for-ios-sd/id395631522</a></p>
<h3>This is from the first few minutes of the first lecture.</h3>
<p><a href="http://www.learningiphone.com/wp-content/uploads/2011/01/Screen-shot-2011-01-27-at-8.50.56-AM.png"><img class="alignnone size-full wp-image-334" title="Screen shot 2011-01-27 at 8.50.56 AM" src="http://www.learningiphone.com/wp-content/uploads/2011/01/Screen-shot-2011-01-27-at-8.50.56-AM.png" alt="" width="380" height="223" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.learningiphone.com/2011/01/new-stanford-course-is-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Better NSLog &#8211; Adding function name / line number to NSLog</title>
		<link>http://www.learningiphone.com/2010/10/better-nslog-adding-function-name-line-number-to-nslog/</link>
		<comments>http://www.learningiphone.com/2010/10/better-nslog-adding-function-name-line-number-to-nslog/#comments</comments>
		<pubDate>Sat, 30 Oct 2010 22:55:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://www.learningiphone.com/?p=301</guid>
		<description><![CDATA[When tracking down a bug, the most useful way to start checking things is to NSLog something. I&#8217;m a heavy user of breakpoints and the debugger. I can&#8217;t live without it, and it&#8217;s saved me countless hours. However I usually see if i can NSLog something first perhaps the problem was an obvious one. A [...]]]></description>
			<content:encoded><![CDATA[<p>When tracking down a bug, the most useful way to start checking things is to NSLog something. I&#8217;m a heavy user of breakpoints and the debugger. I can&#8217;t live without it, and it&#8217;s saved me countless hours. However I usually see if i can NSLog something first perhaps the problem was an obvious one. </p>
<p>A problem that frequently occurs is that when trying to track down a bug, you end up with many NSLog statements in the console and it&#8217;s difficult to know which is which. Often you&#8217;ll see coders start adding things like &#8220;>>>&#8221; or &#8220;#&#8221;, to differentiate this NEW NSLog statement from the ones already showing up.</p>
<p>An easy solution for this, is to use a better logging function one that can tell you the function from which it was called, and the line number.<br />
The compiler has certain special variables you can use that give you this information. With that knowledge, creating a macro for a better log function becomes very simple.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#define VERBOSE_DEBUG_ENABLED_DEBUG 1 // Set to 0 to turn off</span>
<span style="color: #6e371a;">#if !defined(VERBOSE_DEBUG_ENABLED) || VERBOSE_DEBUG_ENABLED == 0 </span>
<span style="color: #6e371a;">#define LOGVERBOSE(...) do{}while(0)</span>
<span style="color: #6e371a;">#else</span>
<span style="color: #6e371a;">#define LOGVERBOSE(__FORMAT__, ...) NSLog(@&quot;%s-Line: %d-&gt;%@&quot;, __func__, __LINE__, [NSString stringWithFormat:__FORMAT__, __VA_ARGS__])</span>
<span style="color: #6e371a;">#endif</span></pre></div></div>

<p>Here we are using the special compiler directives (i&#8217;m not sure what their proper terms are), __func__, and __LINE__ to create a new NSLog statement that then uses, stringWithFormat: to wrap the user&#8217;s log call so that it behaves exactly like NSLog.</p>
<p>In practice it is used like this</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#include SOME_HEADER_FILE_WITH_ABOVE_CODE</span>
...
LOGVERBOSE<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;someVar: %0.2f&quot;</span>, someVar<span style="color: #002200;">&#41;</span>;
<span style="color: #11740a; font-style: italic;">// Outputs</span>
<span style="color: #11740a; font-style: italic;">// -[SomeViewControllerSubclass myFunction:]-Line:32-&gt;someVar: 4.34</span></pre></div></div>

<p>That&#8217;s all there is to it. Very useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.learningiphone.com/2010/10/better-nslog-adding-function-name-line-number-to-nslog/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The best form submission class (asi-http-request)</title>
		<link>http://www.learningiphone.com/2010/10/the-best-form-submission-class-asi-http-request/</link>
		<comments>http://www.learningiphone.com/2010/10/the-best-form-submission-class-asi-http-request/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 15:10:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://www.learningiphone.com/?p=289</guid>
		<description><![CDATA[Small but quick snippet here. Sending multi-part form with image data: NSString *imagePath = NSString *imagePath = &#91;NSString stringWithFormat:@&#34;%@/%@&#34;, &#91;NSSearchPathForDirectoriesInDomains&#40;NSDocumentDirectory, NSUserDomainMask, YES&#41; lastObject&#93;, @&#34;junny.png&#34;&#93;; &#160; UIImage *image = &#91;UIImage imageWithContentsOfFile:imagePath&#93;; NSData * imageData = UIImageJPEGRepresentation&#40;image, 0.75&#41; &#160; ASIFormDataRequest *request = &#91;ASIFormDataRequest requestWithURL:&#91;NSURL URLWithString:http://example.com/form.php]]; &#91;request setPostValue:@&#34;I like brains!&#34; forKey:@&#34;title&#34;&#93;; &#91;request setPostValue:&#91;NSString stringWithFormat:@&#34;%@&#34;, &#91;NSDate date&#93;&#93; forKey:@&#34;session&#34;&#93;;l &#91;request [...]]]></description>
			<content:encoded><![CDATA[<p>Small but quick snippet here.</p>
<p>Sending multi-part form with image data:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">        <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>imagePath <span style="color: #002200;">=</span> 	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>imagePath <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;%@/%@&quot;</span>,
						   <span style="color: #002200;">&#91;</span>NSSearchPathForDirectoriesInDomains<span style="color: #002200;">&#40;</span>NSDocumentDirectory, NSUserDomainMask, <span style="color: #a61390;">YES</span><span style="color: #002200;">&#41;</span> lastObject<span style="color: #002200;">&#93;</span>,
						   <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;junny.png&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
        UIImage <span style="color: #002200;">*</span>image <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageWithContentsOfFile<span style="color: #002200;">:</span>imagePath<span style="color: #002200;">&#93;</span>;
        <span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span> imageData <span style="color: #002200;">=</span> UIImageJPEGRepresentation<span style="color: #002200;">&#40;</span>image, <span style="color: #2400d9;">0.75</span><span style="color: #002200;">&#41;</span>
&nbsp;
	ASIFormDataRequest <span style="color: #002200;">*</span>request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>ASIFormDataRequest requestWithURL<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span>http<span style="color: #002200;">:</span><span style="color: #11740a; font-style: italic;">//example.com/form.php]];</span>
	<span style="color: #002200;">&#91;</span>request setPostValue<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;I like brains!&quot;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;title&quot;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>request setPostValue<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;%@&quot;</span>, <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDate</span> date<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;session&quot;</span><span style="color: #002200;">&#93;</span>;l
	<span style="color: #002200;">&#91;</span>request setPostValue<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;image.png&quot;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Filename&quot;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>request setData<span style="color: #002200;">:</span>imageData forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Filedata&quot;</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// Get image, convert to JPG, get data</span>
	<span style="color: #002200;">&#91;</span>request setDelegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>request startAsynchronous<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>The <a href="http://github.com/pokeb/asi-http-request">ASIFormDataRequest</a>, is the BEST class for handling POST/GET/Multi-Part http request. It has a lot of classes, and its a little bulkier because it does what it does amazingly well. I&#8217;ve tried a few other implementations and this thing saved my life at 4am when I was about to start crying on this project</p>
]]></content:encoded>
			<wfw:commentRss>http://www.learningiphone.com/2010/10/the-best-form-submission-class-asi-http-request/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Parsing Delimited String from XMLNode on iOS using GDataXMLNode</title>
		<link>http://www.learningiphone.com/2010/10/280/</link>
		<comments>http://www.learningiphone.com/2010/10/280/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 16:32:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://www.learningiphone.com/?p=280</guid>
		<description><![CDATA[Often when you work with XML, you need to put a bunch of values into a node, maybe positioning information for example. The best way to do that is to create a &#8220;Delimited String&#8221;, that is &#8220;ABC&#124;123&#124;XYZ&#124;987&#8243;, is delimited by the &#124; character. Here&#8217;s how you get that back in iOS into an array, that [...]]]></description>
			<content:encoded><![CDATA[<p>Often when you work with XML, you need to put a bunch of values into a node, maybe positioning information for example.<br />
The best way to do that is to create a &#8220;Delimited String&#8221;, that is &#8220;ABC|123|XYZ|987&#8243;, is delimited by the | character.</p>
<p>Here&#8217;s how you get that back in iOS into an array, that you can then loop through and make use of:</p>
<p>Btw I&#8217;m using <a href="http://code.google.com/p/gdata-objectivec-client/source/browse/trunk/Source/XMLSupport/">GDataXML</a>, which is googles Objective-C xml reading/writing library. Needless to say it&#8217;s very good, and very fast.</p>
<p>Ok, so let&#8217;s turn this into an array:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pos<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>297.00,30.00<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pos<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Broken into multiple lines to fit, it's a long one!</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>myPositionList <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>xmltree elementsForName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;pos&quot;</span> <span style="color: #002200;">&#93;</span> objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span> stringValue<span style="color: #002200;">&#93;</span>
     stringByTrimmingCharactersInSet<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSCharacterSet</span> whitespaceAndNewlineCharacterSet<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> 
           componentsSeparatedByString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;,&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.learningiphone.com/2010/10/280/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Reading / Creating XML in iOS</title>
		<link>http://www.learningiphone.com/2010/10/reading-and-writing-xml-data-in-ios/</link>
		<comments>http://www.learningiphone.com/2010/10/reading-and-writing-xml-data-in-ios/#comments</comments>
		<pubDate>Mon, 11 Oct 2010 04:21:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[cross-post]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[uikit]]></category>

		<guid isPermaLink="false">http://www.learningiphone.com/?p=274</guid>
		<description><![CDATA[As I&#8217;ve mentioned previously, this blog serves as a kind of social-bookmarker, and exist somewhat in order for me to chronologically log my learning experience with iOS programming. So not everything I post is always a how-to or a tip, but sometimes I will share something which I read that I found useful that people [...]]]></description>
			<content:encoded><![CDATA[<p>As I&#8217;ve mentioned previously, this blog serves as a kind of social-bookmarker, and exist somewhat in order for me to chronologically log my learning experience with iOS programming. So not everything I post is always a how-to or a tip, but sometimes I will share something which I read that I found useful that people learning as I learn might find useful, not to mention I often reference my own blog to remember stuff.</p>
<p>Anyway, this is a great write up on using GDataXML for reading/creating XML in iOS.<br />
<a href="http://www.raywenderlich.com/725/how-to-read-and-write-xml-documents-with-gdataxml ">http://www.raywenderlich.com/725/how-to-read-and-write-xml-documents-with-gdataxml </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.learningiphone.com/2010/10/reading-and-writing-xml-data-in-ios/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Post-A-Day #10 UIViewController&#8217;s views</title>
		<link>http://www.learningiphone.com/2010/10/post-a-day-10-uiviewcontrollers-views/</link>
		<comments>http://www.learningiphone.com/2010/10/post-a-day-10-uiviewcontrollers-views/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 00:34:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://www.learningiphone.com/?p=272</guid>
		<description><![CDATA[-&#40;void&#41; someEventDidOccur EditOptionsViewController *anEditOptionsViewController = &#91;modalViewControllers_ objectForKey:@&#34;someName&#34;&#93;; &#160; // A little note about retain/release // views are not aware of their UIViewController // When they don't have one, and .view is requested UIViewController will simply create a new one. // In the code below, if the order were reversed, &#34;anEditOptionsViewController&#34; would be dealloced // // [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> someEventDidOccur
EditOptionsViewController <span style="color: #002200;">*</span>anEditOptionsViewController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>modalViewControllers_ objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;someName&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// A little note about retain/release</span>
	<span style="color: #11740a; font-style: italic;">//	views are not aware of their UIViewController</span>
	<span style="color: #11740a; font-style: italic;">//		When they don't have one, and .view is requested UIViewController will simply create a new one.</span>
	<span style="color: #11740a; font-style: italic;">//	In the code below, if the order were reversed, &quot;anEditOptionsViewController&quot; would be dealloced</span>
	<span style="color: #11740a; font-style: italic;">//</span>
	<span style="color: #11740a; font-style: italic;">//	After wich the subsequent .view call, or '[anEditOptionsViewController view]' would create a new view, Havoc ensues</span>
	<span style="color: #002200;">&#91;</span>anEditOptionsViewController.view removeFromSuperview<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>modalViewControllers_ removeObjectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;someName&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.learningiphone.com/2010/10/post-a-day-10-uiviewcontrollers-views/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->