<?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>GravityBlast &#187; Cocos2d</title>
	<atom:link href="http://gravityblast.com/category/cocos2d/feed/" rel="self" type="application/rss+xml" />
	<link>http://gravityblast.com</link>
	<description>...coding blast beat!</description>
	<lastBuildDate>Tue, 14 Feb 2012 13:30:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Don&#8217;t abuse NSLog in your iPhone game</title>
		<link>http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/</link>
		<comments>http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 08:12:49 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=403</guid>
		<description><![CDATA[I&#8217;m working on a simple game for iPhone based on cocos2d. Yesterday I installed it on my old iPhone3G and it was veeeeeeeery slow. After a lot of refactoring I found a NSLog call inside my game loop. It basically logged all the collision detection of the player with all the tiles in the map. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a simple game for iPhone based on <a href="http://www.cocos2d-iphone.org/" title="Cocos2d">cocos2d</a>. Yesterday I installed it on my old iPhone3G and it was veeeeeeeery slow. After a lot of refactoring I found a NSLog call inside my game loop. It basically logged all the collision detection of the player with all the tiles in the map. After removing that it&#8217;s even faster then before. So, if you want to log something, do it, but remember to remove all these logging calls later.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;submitHeadline=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game&amp;url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;T=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;title=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game+@+http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/&amp;t=Don%26%238217%3Bt+abuse+NSLog+in+your+iPhone+game" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2010/04/08/dont-abuse-nslog-in-your-iphone-game/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cocos2d: how to make a label to fit the Iphone screen width</title>
		<link>http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/</link>
		<comments>http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 09:13:52 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=196</guid>
		<description><![CDATA[In the iPhone game I&#8217;m working on I need to display a different label every time I start a new game level. Each one of these labels has a random string taken from an array of words, and each one of these strings has different size. So every time I create a new label I [...]]]></description>
			<content:encoded><![CDATA[<p>In the iPhone game I&#8217;m working on I need to display a different label every time I start a new game level. Each one of these labels has a random string taken from an array of words, and each one of these strings has different size. So every time I create a new label I set the maximum font size and then I decrement it until the string size measures less than the iPhone screen. I do that using the <strong>sizeWithFont</strong> method of the <strong>NSString</strong> class:</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;">int</span><span style="color: #002200;">&#41;</span> calculateFontSizeForString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #a61390;">string</span> fontName<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>usedFontName <span style="color: #002200;">&#123;</span>
  <span style="color: #a61390;">int</span> fontSize <span style="color: #002200;">=</span> <span style="color: #2400d9;">120</span>; <span style="color: #11740a; font-style: italic;">// it seems to be the biggest font we can use</span>
  <span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">--</span>fontSize &gt; <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>			
    CGSize size <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #a61390;">string</span> sizeWithFont<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIFont fontWithName<span style="color: #002200;">:</span>usedFontName size<span style="color: #002200;">:</span>fontSize<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>size.width &lt;<span style="color: #002200;">=</span> <span style="color: #2400d9;">480</span> <span style="color: #002200;">&amp;&amp;</span> size.height &lt;<span style="color: #002200;">=</span> <span style="color: #2400d9;">360</span><span style="color: #002200;">&#41;</span>
      <span style="color: #a61390;">break</span>;
  <span style="color: #002200;">&#125;</span>				
&nbsp;
  <span style="color: #a61390;">return</span> fontSize;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>And here a custom scene that you can use to test it:</p>
<p><strong>MyScene.h</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;cocos2d.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> MyScene <span style="color: #002200;">:</span> Scene <span style="color: #002200;">&#123;</span>
  Label    <span style="color: #002200;">*</span>label;
  <span style="color: #400080;">NSArray</span>  <span style="color: #002200;">*</span>strings;
  <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>fontName;
  <span style="color: #a61390;">int</span>      stringIndex;
<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> nextLabel;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>  calculateFontSizeForString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #a61390;">string</span> fontName<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>usedFontName;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> removeCurrentLabel;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> createNextLabel;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> animateLabel;
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSArray</span>  <span style="color: #002200;">*</span>strings;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>fontName;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>MyScene.m</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;MyScene.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> MyScene
&nbsp;
<span style="color: #a61390;">@synthesize</span> strings;
<span style="color: #a61390;">@synthesize</span> fontName;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init <span style="color: #002200;">&#123;</span>
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>self setFontName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Marker Felt&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>self setStrings<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> arrayWithObjects<span style="color: #002200;">:</span>
                      <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Lorem ipsum&quot;</span>, 
                      <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Lorem ipsum dolor&quot;</span>,
                      <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Lorem ipsum dolor sit amet&quot;</span>,
                      <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Lorem ipsum dolor sit amet, consectetur adipisicing elit&quot;</span>,
                      <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.&quot;</span>,
                      <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;		
    stringIndex <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
  <span style="color: #002200;">&#125;</span>
&nbsp;
  <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> onEnter <span style="color: #002200;">&#123;</span>
  <span style="color: #002200;">&#91;</span>super onEnter<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>self nextLabel<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> nextLabel <span style="color: #002200;">&#123;</span>	
  <span style="color: #002200;">&#91;</span>self removeCurrentLabel<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>self createNextLabel<span style="color: #002200;">&#93;</span>;	
  stringIndex<span style="color: #002200;">++</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> removeCurrentLabel <span style="color: #002200;">&#123;</span>
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>label<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#91;</span>self removeChild<span style="color: #002200;">:</span>label cleanup<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
  label <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> createNextLabel <span style="color: #002200;">&#123;</span>
  <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>labelString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>strings objectAtIndex<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>stringIndex <span style="color: #002200;">%</span> <span style="color: #002200;">&#91;</span>strings count<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #a61390;">int</span> fontSize <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self calculateFontSizeForString<span style="color: #002200;">:</span>labelString fontName<span style="color: #002200;">:</span>fontName<span style="color: #002200;">&#93;</span>;	
  label <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>Label labelWithString<span style="color: #002200;">:</span>labelString dimensions<span style="color: #002200;">:</span> CGSizeMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> alignment<span style="color: #002200;">:</span> UITextAlignmentCenter fontName<span style="color: #002200;">:</span>fontName fontSize<span style="color: #002200;">:</span>fontSize<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>label setPosition<span style="color: #002200;">:</span>ccp<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">240</span>, <span style="color: #2400d9;">160</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;	
  <span style="color: #002200;">&#91;</span>label setScale<span style="color: #002200;">:</span><span style="color: #2400d9;">0.5</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span>label<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>self animateLabel<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> animateLabel <span style="color: #002200;">&#123;</span>
  IntervalAction <span style="color: #002200;">*</span>scale <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>ScaleTo actionWithDuration<span style="color: #002200;">:</span><span style="color: #2400d9;">0.5</span> scale<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #a61390;">id</span> delay  <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>DelayTime actionWithDuration<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>; 
  <span style="color: #a61390;">id</span> notify <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CallFunc actionWithTarget<span style="color: #002200;">:</span>self selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>nextLabel<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;	
  Sequence <span style="color: #002200;">*</span>sequence <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>Sequence actions<span style="color: #002200;">:</span>scale, delay, notify, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;	
  <span style="color: #002200;">&#91;</span>label runAction<span style="color: #002200;">:</span>sequence<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;">int</span><span style="color: #002200;">&#41;</span> calculateFontSizeForString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #a61390;">string</span> fontName<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>usedFontName <span style="color: #002200;">&#123;</span>
  <span style="color: #a61390;">int</span> fontSize <span style="color: #002200;">=</span> <span style="color: #2400d9;">120</span>; <span style="color: #11740a; font-style: italic;">// it seems to be the biggest font we can use</span>
  <span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">--</span>fontSize &gt; <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>			
    CGSize size <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #a61390;">string</span> sizeWithFont<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIFont fontWithName<span style="color: #002200;">:</span>usedFontName size<span style="color: #002200;">:</span>fontSize<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>size.width &lt;<span style="color: #002200;">=</span> <span style="color: #2400d9;">480</span> <span style="color: #002200;">&amp;&amp;</span> size.height &lt;<span style="color: #002200;">=</span> <span style="color: #2400d9;">360</span><span style="color: #002200;">&#41;</span>
      <span style="color: #a61390;">break</span>;
  <span style="color: #002200;">&#125;</span>				
&nbsp;
  <span style="color: #a61390;">return</span> fontSize;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> dealloc <span style="color: #002200;">&#123;</span>
  <span style="color: #002200;">&#91;</span>strings retain<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>fontName retain<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>FitFontTestAppDelegate.m</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;FitFontTestAppDelegate.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> FitFontTestAppDelegate
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationDidFinishLaunching<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span>
  window <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIWindow alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> bounds<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>window setUserInteractionEnabled<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>window setMultipleTouchEnabled<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> setDeviceOrientation<span style="color: #002200;">:</span>CCDeviceOrientationLandscapeLeft<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> attachInWindow<span style="color: #002200;">:</span>window<span style="color: #002200;">&#93;</span>;		
  <span style="color: #002200;">&#91;</span>window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;	
&nbsp;
  MyScene <span style="color: #002200;">*</span>scene <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MyScene node<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Director sharedDirector<span style="color: #002200;">&#93;</span> runWithScene<span style="color: #002200;">:</span>scene<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc <span style="color: #002200;">&#123;</span>
  <span style="color: #002200;">&#91;</span>window release<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/&amp;submitHeadline=Cocos2d%3A+how+to+make+a+label+to+fit+the+Iphone+screen+width&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/&amp;title=Cocos2d%3A+how+to+make+a+label+to+fit+the+Iphone+screen+width" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/&amp;title=Cocos2d%3A+how+to+make+a+label+to+fit+the+Iphone+screen+width" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Cocos2d%3A+how+to+make+a+label+to+fit+the+Iphone+screen+width&amp;url=http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/&amp;title=Cocos2d%3A+how+to+make+a+label+to+fit+the+Iphone+screen+width" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/&amp;title=Cocos2d%3A+how+to+make+a+label+to+fit+the+Iphone+screen+width" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/&amp;T=Cocos2d%3A+how+to+make+a+label+to+fit+the+Iphone+screen+width" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/&amp;title=Cocos2d%3A+how+to+make+a+label+to+fit+the+Iphone+screen+width" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/&amp;title=Cocos2d%3A+how+to+make+a+label+to+fit+the+Iphone+screen+width" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/&amp;title=Cocos2d%3A+how+to+make+a+label+to+fit+the+Iphone+screen+width" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Cocos2d%3A+how+to+make+a+label+to+fit+the+Iphone+screen+width+@+http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/&amp;t=Cocos2d%3A+how+to+make+a+label+to+fit+the+Iphone+screen+width" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/07/15/cocos2d-how-to-make-a-label-to-fit-the-iphone-screen-width/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

