<?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>Cocos2D Book</title>
	<atom:link href="http://cocos2dbook.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://cocos2dbook.com</link>
	<description>How to write a game using the Cocos2D Framework</description>
	<lastBuildDate>Wed, 18 Apr 2012 18:30:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Intro to iOS Development</title>
		<link>http://cocos2dbook.com/tutorials/ios101/</link>
		<comments>http://cocos2dbook.com/tutorials/ios101/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 18:30:03 +0000</pubDate>
		<dc:creator>Rod</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://cocos2dbook.com/?p=442</guid>
		<description><![CDATA[Yesterday I did a quick talk+demo on how to begin iOS Development. The talk was for folks just starting out from other languages or new to programming in general. I have added notes to the slides, including links to the Apple Docs, books, source code, and more. My slides for the Intro to iOS Development [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I did a quick talk+demo on how to begin iOS Development.<br />
The talk was for folks just starting out from other languages or new to programming in general.<br />
I have added notes to the slides, including links to the Apple Docs, books, source code, and more.</p>
<p><a href="http://cocos2dbook.com/projects/Strougo_iOSIntroTalk_wNotes.pdf">My slides for the Intro to iOS Development Presentation</a></p>
<p>The books I mentioned/recommend:<br />
<a href="http://www.amazon.com/gp/product/0321706285/ref=as_li_ss_tl? ie=UTF8&#038;tag=cocos2dbookco-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;cr eativeASIN=0321706285">Aaron Hillegass Objective-C Programming</a></p>
<p><a href="http://www.amazon.com/gp/product/1430236051/ref=as_li_ss_tl? ie=UTF8&#038;tag=cocos2dbookco-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;cr eativeASIN=1430236051">Beginning iOS 5 Development</a></p>
<p><a href="http://www.amazon.com/gp/product/0321711386/ref=as_li_ss_tl? ie=UTF8&#038;tag=cocos2dbookco-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;cr eativeASIN=0321711386">Learning Objective-C 2.0</a></p>
<p><a href="http://www.amazon.com/gp/product/0321750403/ref=as_li_ss_tl? ie=UTF8&#038;tag=cocos2dbookco-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;cr eativeASIN=0321750403">Learning iPad Programming</a></p>
<p><strong>And here are some sites to brush up on Objective-C:</strong><br />
<a href="http://cocoadevcentral.com/d/learn_objectivec/">http://cocoadevcentral.com/d/learn_objectivec/</a><br />
and the C language:<br />
<a href="http://cocoadevcentral.com/articles/000081.php">http://cocoadevcentral.com/articles/000081.php</a></p>
<p><strong>Last but not least, the Apple docs:</strong><br />
<a href="https://developer.apple.com/library/ios/#referencelibrary/ GettingStarted/RoadMapiOS/JumpRightIn/iPhone101/Articles/ 00_Introduction.html#//apple_ref/doc/uid/TP40011343-TP40007514-CH1-SW1">Apple&#8217;s Sample iPhone App</a></p>
<p><a href="https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ ObjectiveC/Chapters/ocObjectsClasses.html#//apple_ref/doc/uid/TP30001163- CH11-SW1">How to name your Objective-C Methods</a></p>
<p><a href="https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ ObjectiveC/Introduction/introObjectiveC.html">The Objective-C Language</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cocos2dbook.com/tutorials/ios101/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Performance Optimization for your iOS Games and Apps</title>
		<link>http://cocos2dbook.com/conferences/performancetalk/</link>
		<comments>http://cocos2dbook.com/conferences/performancetalk/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 23:51:46 +0000</pubDate>
		<dc:creator>Rod</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://cocos2dbook.com/?p=432</guid>
		<description><![CDATA[A couple of months ago I had the opportunity to present on Performance Optimizations for iOS Games and Apps in Atlanta, and later in Boston at the Voices that Matter Conference. This talk covers the top 10 things you can do to improve performance of your games or apps. You can get the slides here [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of months ago I had the opportunity to present on Performance Optimizations for iOS Games and Apps in Atlanta, and later in Boston at the Voices that Matter Conference.</p>
<p>This talk covers the top 10 things you can do to improve performance of your games or apps.</p>
<p>You can get the slides <a href="http://cocos2dbook.com/projects/Strougo_PerformanceTalk_Blog.pdf">here</a><br />
The video of the Performance Talk at VTM is here:<br />
<a href="http://click.linksynergy.com/fs-bin/click?id=8SkP5uATnww&#038;offerid=163217.1772256&#038;type=2&#038;subid=0">Voices That Matter: iOS Developers Conference Session: Getting the Most Out of Cocos2D: Performance Tips and Tricks</a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=8SkP5uATnww&#038;bids=163217.1772256&#038;type=2&#038;subid=0" ></p>
<p>A special thanks to the Atlanta iOS Meetup group, for letting me try out and test-run the presentation on them. <img src='http://cocos2dbook.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://cocos2dbook.com/conferences/performancetalk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intro to Cocos2D at 360iDev</title>
		<link>http://cocos2dbook.com/conferences/intro-to-cocos2d-at-360idev2011/</link>
		<comments>http://cocos2dbook.com/conferences/intro-to-cocos2d-at-360idev2011/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 21:09:08 +0000</pubDate>
		<dc:creator>Rod</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[Conferences]]></category>

		<guid isPermaLink="false">http://cocos2dbook.com/?p=384</guid>
		<description><![CDATA[This week Ray and I got to present an Intro to Cocos2D talk at the 360iDev Conference in Denver. We had a great time at the conference, and appreciate all of the people that showed up at our talk. Here are the slides and code for the talk. Hope to see you at the next [...]]]></description>
			<content:encoded><![CDATA[<p>This week Ray and I got to present an Intro to Cocos2D talk at the 360iDev Conference in Denver.<br />
We had a great time at the conference, and appreciate all of the people that showed up at our talk.</p>
<p>Here are the <a href="http://cocos2dbook.com/projects/360iDev2011-IntroToCocos2D.pdf">slides</a> and <a href="http://cocos2dbook.com/projects/CatJump.zip">code</a> for the talk.<br />
Hope to see you at the next conference,<br />
Rod</p>
]]></content:encoded>
			<wfw:commentRss>http://cocos2dbook.com/conferences/intro-to-cocos2d-at-360idev2011/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Intro to iPhone Game Development Workshop</title>
		<link>http://cocos2dbook.com/cocos2d/gamedevworkshop/</link>
		<comments>http://cocos2dbook.com/cocos2d/gamedevworkshop/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 18:36:48 +0000</pubDate>
		<dc:creator>Rod</dc:creator>
				<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Cocos2d]]></category>

		<guid isPermaLink="false">http://cocos2dbook.com/?p=372</guid>
		<description><![CDATA[So you want to be a game developer but missed our last workshop in Atlanta. Fear not, you have two more chances: Ray and I are teaching the Beginning iPhone Game Development Workshop with Cocos2D in two locations: There is a 2 day version: October 15th and 16th in Denver, Colorado. Use the code &#8220;Prop&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>So you want to be a game developer but missed our last workshop in Atlanta. Fear not, you have two more chances:</p>
<p>Ray and I are teaching the Beginning iPhone Game Development Workshop with Cocos2D in two locations:</p>
<p><a href="http://cocos2dbook.com/wp-content/uploads/2011/08/PenguinToss.jpg" rel="lightbox[372]"><img class="aligncenter size-medium wp-image-374" title="PenguinToss" src="http://cocos2dbook.com/wp-content/uploads/2011/08/PenguinToss-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p><strong><a href="http://iphonegamedev.eventbrite.com/">There is a 2 day version:</a></strong><br />
October 15th and 16th in Denver, Colorado.<br />
Use the code &#8220;Prop&#8221; to get $75 dollars off the registration</p>
<p>and</p>
<p><strong><a href="http://ios2011.voicesthatmatter.com/">There is a 1 day version:</a></strong><br />
November 11th-13th in Boston, MA (as part of the <a href="http://ios2011.voicesthatmatter.com/">Voices that Matter Conference</a>)<br />
By the way, if you are going to the Voices that Matter conference, use the code <strong>BSTSPK8</strong> to get $150 dollars off the price of the conference.</p>
<p>In short, this is drinking-from-a-firehose, get your hands dirty type of workshop. We lecture for a short bit, show you some sample code/demos, and then you jump into the labs coding a set of mini games to drive home Cocos2D and Chipmunk knowledge. Of course we typically head for some refreshments at the end of the day <img src='http://cocos2dbook.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>You can see more details on the <a title="Registration for iPhone Game Dev in Denver" href="http://iphonegamedev.eventbrite.com/" target="_blank">registration page for Denver</a>.<br />
Here is what people said about the course the<a title="Reviews of iPhone Game Dev Workshop" href="http://www.raywenderlich.com/forums/viewtopic.php?f=5&amp;t=562" target="_blank"> last time</a> around:</p>
<p>Hope to see you guys in Denver or Boston,<br />
Rod</p>
]]></content:encoded>
			<wfw:commentRss>http://cocos2dbook.com/cocos2d/gamedevworkshop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Recharging and Inspiration</title>
		<link>http://cocos2dbook.com/personal/recharging-and-inspiration/</link>
		<comments>http://cocos2dbook.com/personal/recharging-and-inspiration/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 02:48:01 +0000</pubDate>
		<dc:creator>Rod</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Time Management]]></category>

		<guid isPermaLink="false">http://cocos2dbook.com/?p=357</guid>
		<description><![CDATA[The Learning Cocos2D book is complete and headed to printers. I&#8217;m happy with the way it turned out, and hope you guys find it useful and a good read. Before we get any further, if you want to pre-order the book: On Amazon (paper book) On InformIT (paper, PDF, ePub, etc) The blog posts here [...]]]></description>
			<content:encoded><![CDATA[<p>The Learning Cocos2D book is complete and headed to printers. I&#8217;m happy with the way it turned out, and hope you guys find it useful and a good read.<br />
Before we get any further, if you want to pre-order the book:<br />
On <a title="Learning Cocos2D on Amazon" href="http://www.amazon.com/Learning-Cocos2D-Hands--Building-Chipmunk/dp/0321735625/ref=sr_1_1?ie=UTF8&amp;qid=1306895402&amp;sr=8-1" target="_blank">Amazon</a> (paper book)<br />
On<a title="Learning Cocos2D on InformIT" href="http://www.informit.com/store/product.aspx?isbn=0321735625" target="_blank"> InformIT</a> (paper, PDF, ePub, etc)</p>
<p>The blog posts here have been slower then I would like. First we were busy with the book, you know actually writing and coding, and lately I have been taking some time off to rest and recharge, spending time with my two kids. Our older boy is 3, and it has been a world of fun building train tracks and playing with him. Even though I have a terrible Sir Topham Hatt English accent, he does not seem to mind <img src='http://cocos2dbook.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>If you have no idea who Sir Topham Hatt is, just wait until you have kids, especially boys. You will quickly learn to scour youtube for videos of firetrucks, trash compactors, and our favorite, airplanes landing.</p>
<p>Here is a track we were working on a few night ago:<br />
<a href="http://cocos2dbook.com/wp-content/uploads/2011/05/BuildingTrainsSmall.jpg" rel="lightbox[357]"><img class="aligncenter size-medium wp-image-358" title="Building Train Sets" src="http://cocos2dbook.com/wp-content/uploads/2011/05/BuildingTrainsSmall-224x300.jpg" alt="Building a Thomas and Friends Train Set" width="224" height="300" /></a></p>
<p>I have gotten more game ideas (no, not train related) while playing with them, and re-discovered the kid in me. I&#8217;m sure most parents realize that special opportunity of being a kid once more when playing with your own kids. It is really fun to take some time off from Xcode and clear one&#8217;s head a bit.</p>
<p>What about some Cocos2D content? That will have to wait until next week, I&#8217;ve got a post underway covering how to convert a Cocos2D+Box2D physics game into a Cocos2D+Chipmunk game. Why would you do such a thing&#8230;</p>
<p>Last but not least, I convinced Ray to leave the Northeast for a weekend and come down to Atlanta so we can teach a weekend workshop on Cocos2D (and Chipmunk). There are a couple of seats left, register <a title="Cocos2D at Eventbrite" href="http://cocos2d.eventbrite.com" target="_blank">here</a>.</p>
<p>What inspirations or ideas have you gotten while playing with your kids?</p>
]]></content:encoded>
			<wfw:commentRss>http://cocos2dbook.com/personal/recharging-and-inspiration/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Cocos2D Via Minigames Workshop</title>
		<link>http://cocos2dbook.com/conferences/cocos2d-via-minigames-workshop/</link>
		<comments>http://cocos2dbook.com/conferences/cocos2d-via-minigames-workshop/#comments</comments>
		<pubDate>Mon, 09 May 2011 16:00:45 +0000</pubDate>
		<dc:creator>Rod</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[Conferences]]></category>

		<guid isPermaLink="false">http://cocos2dbook.com/?p=338</guid>
		<description><![CDATA[So you want to be a Game Developer? If you are like us, you have been thinking about making your own games since you were a kid. I started with an Apple ][, some of you way earlier and some of you are just now starting. Either way. the hardest part is taking that first [...]]]></description>
			<content:encoded><![CDATA[<p>So you want to be a Game Developer?</p>
<p>If you are like us, you have been thinking about making your own games since you were a kid. I started with an Apple ][, some of you way earlier and some of you are just now starting. Either way. the hardest part is taking that first step. <a href="http://cocos2dbook.com/wp-content/uploads/2011/05/AppleII.png" rel="lightbox[338]"><img src="http://cocos2dbook.com/wp-content/uploads/2011/05/AppleII-300x206.png" alt="" title="AppleII" width="300" height="206" class="aligncenter size-medium wp-image-341" /></a></p>
<p>Ray and I taught a day long workshop on Learning Cocos2D at the <a href="http://iphonespring2011.crowdvine.com/">Voices That<br />
Matter</a> iPhone conference called <a href="http://cocos2d.eventbrite.com/">Cocos2D via Minigames</a> back in Seattle earlier this year.</p>
<p>We had a great time, and it was wonderful to really get folks started with Game Dev and see the light bulb moments when they crossed that threshold of &#8220;I wish I could make this game&#8221;, to &#8220;I know I can make this game&#8221;. Some attendees even ended up staying up throughout the night after a full day workshop because they wanted to work on their games and apply what they learned. It was really inspirational to see that creative spark, and one of the reasons I really enjoy teaching.</p>
<p>Ray and I are pleased to announce that we are bringing the workshop to Atlanta, GA and expanding it to a full weekend.<br />
The workshop is split between lecture, demos, and labs. We cover the concepts and the demo how to implement it in code, then guide you through hands-on labs in building a series of minigames to re-enforce those concepts. For example, in the first minigame you learn about sprites and actions and movements, then go to build a game about a cat avoiding on-coming cars. We really designed it as hands-on, learn the concepts and code, then turn around and apply it to create a minigame.</p>
<p><a href="http://cocos2dbook.com/wp-content/uploads/2011/05/mockup_catjumps.png" rel="lightbox[338]"><img src="http://cocos2dbook.com/wp-content/uploads/2011/05/mockup_catjumps-300x200.png" alt="" title="mockup_catjumps" width="300" height="200" class="aligncenter size-medium wp-image-346" /></a></p>
<p>There are six minigames in all, several of them fully physics based games.<br />
If you have no Cocos2D experience or even a little, we take you through the Cocos2D basics and then right into animations, scrolling, physics, sounds, and much more.</p>
<p>This session of the Cocos2D via Minigames will be in Atlanta, GA on June 11th and 12th.</p>
<p>If you have been waiting to learn Cocos2D and create your own games, wait no more. </p>
<h2>Sign Me Up!</h2>
<p>So, do you want to start making your own games? <a href="http://cocos2d.eventbrite.com/">Sign up now</a> on the<br />
EventBrite page!</p>
<p>Use the code <em>prop</em> to save $100 off the price of the workshop. You get that just for reading this far down the post <img src='http://cocos2dbook.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>You should have Xcode installed on your machine prior to the workshop. We’ll be using Xcode 4 for demos and such, but if you’re still using<br />
Xcode 3 it’s OK.  You don’t necessarily need to have Cocos2D installed as we’ll cover how in the class.</p>
<p>Last but not least, Ray and I are glad to have <a href="http://shawnsbits.com/">Shawn Grimes</a> helping us out<br />
with the workshop. Shawn will be helping organize the workshop and be a helping hand during the labs, answering your questions along with Ray and I.</p>
<p>Looking forward to seeing you here in Atlanta,<br />
Rod</p>
]]></content:encoded>
			<wfw:commentRss>http://cocos2dbook.com/conferences/cocos2d-via-minigames-workshop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Voices that Matter &#8211; Seattle</title>
		<link>http://cocos2dbook.com/conferences/voices-that-matter-seattle/</link>
		<comments>http://cocos2dbook.com/conferences/voices-that-matter-seattle/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 20:42:24 +0000</pubDate>
		<dc:creator>Rod</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://cocos2dbook.com/?p=307</guid>
		<description><![CDATA[This April 8-10 I will be speaking at the Voices that Matter Conference in Seattle. My talk is on Performance Tips and Tricks for Cocos2D, learn how to keep your game at 60 frames per second even on a iPhone 3G! On April 8th Ray Wenderlich and I are doing a full day long workshop [...]]]></description>
			<content:encoded><![CDATA[<p>This April 8-10 I will be speaking at the <a title="Voices that Matter" href="http://iphonespring2011.crowdvine.com/" target="_blank">Voices that Matter</a> Conference in Seattle.</p>
<p>My talk is on <a title="Performance Tips and Tricks Session" href="http://iphonespring2011.crowdvine.com/talks/16899" target="_blank">Performance Tips and Tricks for Cocos2D</a>, learn how to keep your game at 60 frames per second even on a iPhone 3G!</p>
<p>On April 8th Ray Wenderlich and I are doing a full day long workshop on learning Cocos2D via MiniGames. It&#8217;s part lecture, part hands-on, with lots of sample code and time in Xcode. If you have been waiting to learn Cocos2D this workshop will get you from zero to building your own games in one caffeine filled day. Don&#8217;t just take my word on it, see the other great speakers on the <a title="Voices that Matter Schedule" href="http://iphonespring2011.crowdvine.com/calendar" target="_blank">schedule here</a>:</p>
<p>Lastly, you can still save $100 off the price with the code SEASPK2</p>
<p>Hope to see you in Seattle,</p>
<p>Rod</p>
]]></content:encoded>
			<wfw:commentRss>http://cocos2dbook.com/conferences/voices-that-matter-seattle/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Coding while standing</title>
		<link>http://cocos2dbook.com/personal/coding-while-standing/</link>
		<comments>http://cocos2dbook.com/personal/coding-while-standing/#comments</comments>
		<pubDate>Tue, 11 Jan 2011 23:26:11 +0000</pubDate>
		<dc:creator>Rod</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Workspace]]></category>

		<guid isPermaLink="false">http://cocos2dbook.com/?p=282</guid>
		<description><![CDATA[In the last month I have been working standing up most of the day. Why I chose to do this crazy thing of coding standing up is the topic of this week’s post. As some of may know I come from a certain soccer playing country. We call it futebol, but I’ve lived in the [...]]]></description>
			<content:encoded><![CDATA[<p>In the last month I have been working standing up most of the day. Why I chose to do this crazy thing of coding standing up is the topic of this week’s post.</p>
<p>As some of may know I come from a certain soccer playing <a title="Brasil" href="http://en.wikipedia.org/wiki/Brazil" target="_blank">country</a>. We call it futebol, but I’ve lived in the states long enough to call it soccer. Some years ago I injured my L5 disc by playing soccer badly. No, really badly, the kind of soccer playing that would have made me a hit on youtube, luckily those games were not recorded. These days I am mostly pain free, but sitting for long periods is not good. 2010 was worse then most years, I found myself on long periods of time sitting down in long coding and writing sessions. Turns out writing a book takes a ton of time, who knew <img src='http://cocos2dbook.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>I saw some other <a title="Noel's Standing Desk Experiment" href="http://gamesfromwithin.com/my-standing-desk-experiment">developers</a> <a title="Brandon's Workstation" href="http://brandontreb.com/what-does-your-workspace-look-like/" target="_blank">talk</a> about their standing setups, and decided to give it a try. If nothing else it would help keep my keyboard out of reach of our 2 year old. You have no idea how many Xcode compile errors I can get after he gets a hold of my Mac.</p>
<p>I’ve got a Dell 23inch monitor I use as my main display, so I stacked it and the keyboard+mouse on top of some boxes. This worked pretty well, except that the height was not quite right, and I ended up with a sore neck after some long days. During the first week my feet were killing me. I’ve got a carpeted office upstairs, but I found out wearing some flip flops cured the foot pain. You really need some arch support if you are standing most of the day.</p>
<p>Of course the stacked box system was not that convenient, moving to a sitting position required moving the boxes off the desk and being careful not to drop the monitor and Macbook Pro in the process. After a month I bit the bullet and ordered a <a title="GeekDesk" href="http://www.geekdesk.com/" target="_blank">GeekDesk</a>. I went for the larger desk, as I still do a lot of note taking and design on paper, so I really liked having the extra space. I’ve had the <a title="GekkDesk" href="http://www.geekdesk.com/" target="_blank">GeekDesk</a> since early December, and I can’t say enough good things about it. It works perfect, and it’s a breeze to move it up and down with the electric motor. Here is the desk in the down position:</p>

<div class="ngg-galleryoverview" id="ngg-gallery-14-282">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-15" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://cocos2dbook.com/wp-content/gallery/standingdeskdown/deskondownposition.png" title=" " class="shutterset_set_14"  rel="lightbox[282]">
								<img title="deskondownposition" alt="deskondownposition" src="http://cocos2dbook.com/wp-content/gallery/standingdeskdown/thumbs/thumbs_deskondownposition.png" width="400" height="300" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>


<p>So how is my work like nowdays? I stand up almost the entire day. If I am researching something or reading I will usually sit and use the iPad. The rest of the time I’m standing up. I feel a lot more alert, and have been able to cut down some of my coffee intake, which is good. It is a lot harder to slack off and daydream somewhere else when you are standing up, or you will start to lean and fall over.</p>
<p>Standing up all day is not without side effects, I end up dancing a lot more. That’s all I’m going to say about that <img src='http://cocos2dbook.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Some links on health perils of sitting all day:</p>
<p><a title="Washington Post Covers Health Issues" href="http://www.washingtonpost.com/wp-dyn/content/article/2010/10/16/AR2010101602903.html" target="_blank">Health Issues with Sitting All Day</a><br />
<a title="Sitting is bad for you" href="http://abcnews.go.com/Health/Wellness/sitting-linked-early-death/story?id=11234721" target="_blank">Sitting = Death</a></p>
<p>How do you develop code, and what is your setup like?<br />
Rod</p>
<p>This post is part of <a title="idevblogaday.com" href="http://idevblogaday.com" target="_blank">iDevBlogADay</a>, a group of indie iOS development blogs featuring at least two posts per day. You can keep up with your favorite developers through the <a title="idevblogaday.com" href="http://idevblogaday.com" target="_blank">iDevBlogADay web site</a>, <a title="iDevBlogaDay RSS Feed" href="http://feeds.feedburner.com/idevblogaday" target="_blank">RSS feed</a>, or <a title="iDevBlogaDay on Twitter" href="http://twitter.com/#search?q=%23idevblogaday" target="_blank">Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cocos2dbook.com/personal/coding-while-standing/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Cocos2D on the Mac &#8211; Part 2 (Physics)</title>
		<link>http://cocos2dbook.com/cocos2d/cocos2d-on-the-mac-part-2/</link>
		<comments>http://cocos2dbook.com/cocos2d/cocos2d-on-the-mac-part-2/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 04:41:31 +0000</pubDate>
		<dc:creator>Rod</dc:creator>
				<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://cocos2dbook.com/?p=264</guid>
		<description><![CDATA[Adding in the Physics In the last post you learned how to create a Cocos2D game for the Mac. For this post I am going to cover how you can add the Box2D Physics engine to your Cocos2D Mac games. It is really pretty easy, here you will learn how to get Box2D integrated into [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Adding in the Physics</strong></p>
<p>In the <a href="http://cocos2dbook.com/cocos2d/cocos2d-on-the-mac-part1/">last</a> post you learned how to create a Cocos2D game for the Mac. For this post I am going to cover how you can add the Box2D Physics engine to your Cocos2D Mac games. It is really pretty easy, here you will learn how to get Box2D integrated into your project and mess with gravity, next week I will cover more about the Box2D Debug Renderer. I&#8217;ve tried to make this post somewhat brief, let me know in the comments what else you would like to see as well as any questions.</p>
<p><strong>Step 1 &#8211; Copy the Box2D Folders (excluding the TestBed)</strong><br />
Copy the following Folders into your project.</p>

<div class="ngg-galleryoverview" id="ngg-gallery-11-264">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-12" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://cocos2dbook.com/wp-content/gallery/box2dfoldertocopy/box2dfolderstocopy.png" title=" " class="shutterset_set_11"  rel="lightbox[264]">
								<img title="box2dfolderstocopy" alt="box2dfolderstocopy" src="http://cocos2dbook.com/wp-content/gallery/box2dfoldertocopy/thumbs/thumbs_box2dfolderstocopy.png" width="400" height="300" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>


<p>The TestBed for Box2D includes the Box2D Debug Render Engine for iOS using OpenGL ES. Since we are on the Mac, you want to exclude these for the time being, the next post will show you how to add the older OpenGL Debug Render Engine.</p>
<p><strong>Step 2 &#8211; Change the Header Search Path</strong></p>
<p>If you try to compile now you will get a ton of compile errors, over 2000K, since your code does not know where to find the Box2D classes. Fortunately this is easy to fix.</p>
<p>Click on your Project, and then the Info button, and search for “Header Search Path”<br />
Add a header search path to the actual folder location for your Box2D source files (that you copied in Step 1). Be sure to check the recursive checkbox.</p>

<div class="ngg-galleryoverview" id="ngg-gallery-12-264">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-13" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://cocos2dbook.com/wp-content/gallery/headersearchpath/headersearchpath.png" title=" " class="shutterset_set_12"  rel="lightbox[264]">
								<img title="headersearchpath" alt="headersearchpath" src="http://cocos2dbook.com/wp-content/gallery/headersearchpath/thumbs/thumbs_headersearchpath.png" width="400" height="300" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>


<p><strong>Step 3 – Changing to Objective-C++</strong></p>
<p>Since Box2D code is in C++, your Objective-C files have to be Objective-C++, which just means you can mix and match Objective-C and C++ code. Simple rename all of your .m files to .mm<br />
In your games you only need to change the .m files to .mm for any that include Box2D or classes which themselves include Box2D (or any C++).</p>
<p>Rename: Main.m, Cocos2DMacGame2AppDelegate.m, HelloWorldScene.m to .mm versions.</p>
<p><strong>Step 4 – Adding Box2D to your Game</strong></p>
<p>Open the HelloWorldScene.h Header file and add:</p>
<pre class="brush:objc">#import "Box2D.h"
#define PTM_RATIO 32
</pre>
<p>In the @interface declaration add:</p>
<pre class="brush:objc">// HelloWorld Layer
@interface HelloWorld : CCLayer
{
	b2World* world;
}
</pre>
<p>You should be able to Build your project now without any errors. Test it to make sure everything is good before moving to Step 5.</p>
<p><strong>Step 5 – Creating the Box2D world and ground bodies</strong><br />
Here you are going to add some lines to the init method to setup Box2D, and create ground bodies on the edges of the screen. Without ground bodies your box2d bodies/objects will just fall out of view.<br />
Add this inside the init method:</p>
<pre class="brush:objc">
                // Create the Box2D World
		b2Vec2 gravity;
		gravity.Set(0.0f,-10.0f);
		bool doSleep = true;
		world = new b2World(gravity, doSleep);
		world->SetContinuousPhysics(true);
		
		// Define the ground body.
		b2BodyDef groundBodyDef;
		groundBodyDef.position.Set(0, 0); // bottom-left corner
		
		// Call the body factory which allocates memory for the ground body
		// from a pool and creates the ground box shape (also from a pool).
		// The body is also added to the world.
		b2Body* groundBody = world->CreateBody(&#038;groundBodyDef);
		
		// Define the ground box shape.
		b2PolygonShape groundBox;		
		
		// bottom
		groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(size.width/PTM_RATIO,0));
		groundBody->CreateFixture(&#038;groundBox,0);
		
		// top
		groundBox.SetAsEdge(b2Vec2(0,size.height/PTM_RATIO), b2Vec2(size.width/PTM_RATIO,size.height/PTM_RATIO));
		groundBody->CreateFixture(&#038;groundBox,0);
		
		// left
		groundBox.SetAsEdge(b2Vec2(0,size.height/PTM_RATIO), b2Vec2(0,0));
		groundBody->CreateFixture(&#038;groundBox,0);
		
		// right
		groundBox.SetAsEdge(b2Vec2(size.width/PTM_RATIO,size.height/PTM_RATIO), b2Vec2(size.width/PTM_RATIO,0));
		groundBody->CreateFixture(&#038;groundBox,0);
		
		// Create a Penguin on the middle of the screen
		[self addNewSpriteWithCoords:ccp(size.width/2,size.height/2)];
		
		// Call the update method 60 times a second
		[self scheduleUpdate];
</pre>
<p>Note the call to [self scheduleUpdate]. This will call the update method in Step 8 where the physics simulation will occur.</p>
<p><strong>Step 6 – Adding the Box2D shape to the Sprites</strong><br />
Add the addNewSpriteWithCoords method above the init method in HelloWorldScene.mm, it builds on the same method you wrote on the previous post, adding a Box2D body for each Penguin.</p>
<pre class="brush:objc">
-(void) addNewSpriteWithCoords:(CGPoint)p {
	
	
	CCSprite *sprite = [CCSprite spriteWithFile:@"penguino1.png"];
	[self addChild:sprite];
	
	sprite.position = ccp( p.x, p.y);
	
	// Define the dynamic body.
	//Set up a 1m squared box in the physics world
	b2BodyDef bodyDef;
	bodyDef.type = b2_dynamicBody;
	
	bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
	bodyDef.userData = sprite;
	bodyDef.allowSleep = false;
	b2Body *body = world->CreateBody(&#038;bodyDef);
	
	// Define another box shape for our dynamic body.
	b2PolygonShape dynamicBox;
	dynamicBox.SetAsBox(0.65f, 0.9f);//These are mid points for our 1m box
	
	// Define the dynamic body fixture.
	b2FixtureDef fixtureDef;
	fixtureDef.shape = &#038;dynamicBox;	
	fixtureDef.density = 3.0f;
	fixtureDef.friction = 0.3f;
	fixtureDef.restitution = 0.3f;
	body->CreateFixture(&#038;fixtureDef);
}
</pre>
<p>Normally you want your bodies to be able to sleep, in this example we don&#8217;t because if you left the penguins at rest, changing the gravity would have no effect of them. In other words, having bodies sleep saves CPU cycles, but if you have a world with few collisions (like this example), then you have to be careful not to get your objects stuck. This being an example, the simplest solution is just to not let physics bodies sleep.</p>
<p><strong>Step 7 &#8211; Add the handler for the Mouse and Arrow Keys</strong><br />
In this example the arrow keys change the gravity. If you press up, everything will be pulled towards the sky. Be sure to try out the arrow keys, especially with a few penguins on the screen.</p>
<pre class="brush:objc">
-(BOOL)ccMouseDown:(NSEvent *)event {
	CGPoint location = [event locationInWindow];
	CCLOG(@"Mouse Cick X:%f Y:%f",location.x,location.y);
	
	[self addNewSpriteWithCoords:location];
	return YES;
}
</pre>
<pre class="brush:objc">
-(BOOL) ccKeyDown:(NSEvent *)event
{
	if ([event modifierFlags] &#038; NSNumericPadKeyMask) { // arrow keys have this mask
        NSString *theArrow = [event charactersIgnoringModifiers];
        unichar keyChar = 0;
        if ( [theArrow length] == 0 )
            return YES;            // reject dead keys
        if ( [theArrow length] == 1 ) {
            keyChar = [theArrow characterAtIndex:0];
            if ( keyChar == NSLeftArrowFunctionKey ) {
                CCLOG(@"Left Arrow pressed");
				CGPoint movePosition = ccp(-1,0);
				
				b2Vec2 gravity;
				gravity.Set(-10.0f,0.0f);
				world->SetGravity(gravity);
				
                return YES;
            }
            if ( keyChar == NSRightArrowFunctionKey ) {
                CCLOG(@"Right Arrow pressed");
				CGPoint movePosition = ccp(1,0);
				
				b2Vec2 gravity;
				gravity.Set(10.0f,0.0f);
				world->SetGravity(gravity);
				
				return YES;
            }
            if ( keyChar == NSUpArrowFunctionKey ) {
				CCLOG(@"Up Arrow Pressed");
				CGPoint movePosition = ccp(0,1);
				
				b2Vec2 gravity;
				gravity.Set(0.0f,10.0f);
				world->SetGravity(gravity);
				
                return YES;
            }
            if ( keyChar == NSDownArrowFunctionKey ) {
				CGPoint movePosition = ccp(0,-1);
				
				b2Vec2 gravity;
				gravity.Set(0.0f,-10.0f);
				world->SetGravity(gravity);
				
				CCLOG(@"Down Arrow Pressed");
                return YES;
            }
        }
    }
    return NO;
}
</pre>
<p><strong>Step 8 – Update Method to simulate the physics</strong><br />
Add this method above init to update the physics simulation and the positions of sprites associated to physics bodies. This is the same update method found in the Cocos2D iOS Box2D Templates.</p>
<pre class="brush:objc">
-(void)update:(ccTime)dt {
	
	//It is recommended that a fixed time step is used with Box2D for stability
	//of the simulation, however, we are using a variable time step here.
	//You need to make an informed choice, the following URL is useful
	//http://gafferongames.com/game-physics/fix-your-timestep/
	
	int32 velocityIterations = 8;
	int32 positionIterations = 1;
	
	// Instruct the world to perform a single step of simulation. It is
	// generally best to keep the time step and iterations fixed.
	world->Step(dt, velocityIterations, positionIterations);
	
	
	//Iterate over the bodies in the physics world
	for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
	{
		if (b->GetUserData() != NULL) {
			//Synchronize the AtlasSprites position and rotation with the corresponding body
			CCSprite *myActor = (CCSprite*)b->GetUserData();
			myActor.position = CGPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO);
			myActor.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
		}	
	}
	
}
</pre>
<p>That&#8217;s it! Build and Run and click somewhere on the window. You will see a Penguin fall down to the bottom. Try using the arrow keys to have some fun with gravity.</p>

<div class="ngg-galleryoverview" id="ngg-gallery-13-264">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-14" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://cocos2dbook.com/wp-content/gallery/hellobox2d/hellobox2d.png" title=" " class="shutterset_set_13"  rel="lightbox[264]">
								<img title="hellobox2d" alt="hellobox2d" src="http://cocos2dbook.com/wp-content/gallery/hellobox2d/thumbs/thumbs_hellobox2d.png" width="400" height="300" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>


<p>Here is the project source code:<br />
<a title="Cocos2D on the Mac Project2" href="http://cocos2dbook.com/projects/Cocos2DMacGame2.zip" target="_blank">Cocos2DMacGame2 Source</a></p>
<p>Thanks for reading,<br />
Rod</p>
<p>This post is part of <a title="idevblogaday.com" href="http://idevblogaday.com" target="_blank">iDevBlogADay</a>, a group of indie iOS development blogs featuring at least two posts per day. You can keep up with your favorite developers through the <a title="idevblogaday.com" href="http://idevblogaday.com" target="_blank">iDevBlogADay web site</a>, <a title="iDevBlogaDay RSS Feed" href="http://feeds.feedburner.com/idevblogaday" target="_blank">RSS feed</a>, or <a title="iDevBlogaDay on Twitter" href="http://twitter.com/#search?q=%23idevblogaday" target="_blank">Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cocos2dbook.com/cocos2d/cocos2d-on-the-mac-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cocos2D on the Mac &#8211; Part 1</title>
		<link>http://cocos2dbook.com/cocos2d/cocos2d-on-the-mac-part1/</link>
		<comments>http://cocos2dbook.com/cocos2d/cocos2d-on-the-mac-part1/#comments</comments>
		<pubDate>Wed, 29 Dec 2010 04:29:17 +0000</pubDate>
		<dc:creator>Rod</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://cocos2dbook.com/?p=244</guid>
		<description><![CDATA[Cocos2D is an excellent Objective-C framework for games, and hopefully you have heard or been looking at a certain Cocos2D book on Safari On-Line. Most of the tutorials out there are about running Cocos2D on iOS devices, but as of the last release, it now runs on the Mac too. In fact if your game [...]]]></description>
			<content:encoded><![CDATA[<p>Cocos2D is an excellent Objective-C framework for games, and hopefully you have heard or been looking at a <a title="Learning Cocos2D" href="http://my.safaribooksonline.com/9780132180863" target="_blank">certain Cocos2D book on Safari On-Line</a>. Most of the tutorials out there are about running Cocos2D on iOS devices, but as of the last release, it now runs on the Mac too. In fact if your game does not have any UIKit views, porting it from iOS to the Mac becomes really simple. If you have been thinking about getting a Cocos2D game into the Mac AppStore, these series of blog posts should help you get there. With a simple 4 steps you will have a template that you should be able to start adding your game code to.</p>
<p><strong>Step 1 &#8211; Getting the latest Cocos2D develop branch</strong><br />
Assuming you have Git installed on your Mac (if not, follow the steps <a title="Installing Git on Your Mac" href="http://cocos2dbook.com/cocos2d/installing-git-on-your-mac/" target="_blank">here</a>), in a folder of your choice run:</p>
<pre class="brush:bash">git clone git://github.com/cocos2d/cocos2d-iphone.git
git checkout develop
</pre>
<p>The last line is critical, you will want the develop branch with the latest changes to the Mac Xcode Template.</p>
<p><strong>Step 2 &#8211; Installing the (new) Cocos2D Templates into Xcode</strong><br />
In the folder you just cloned the develop branch of Cocos2D, run:</p>
<pre class="brush:bash">sudo ./install-templates.sh</pre>
<p>You are half way there, if you restart Xcode you should see the Cocos2D 1.0.0 templates.</p>
<p><strong>Step 3 &#8211; Time to create the game shell and add Mr. Penguino</strong><br />
Select New Project in Xcode and choose the cocos2d-Application Mac template.</p>

<div class="ngg-galleryoverview" id="ngg-gallery-7-244">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-8" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://cocos2dbook.com/wp-content/gallery/cocos2dmactemplates/cocos2dtemplates.png" title=" " class="shutterset_set_7"  rel="lightbox[244]">
								<img title="cocos2dtemplates" alt="cocos2dtemplates" src="http://cocos2dbook.com/wp-content/gallery/cocos2dmactemplates/thumbs/thumbs_cocos2dtemplates.png" width="400" height="300" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>


<p>Give your Project a name, and set the Active Executable to your Project (and not the Cocos2D Libraries).</p>

<div class="ngg-galleryoverview" id="ngg-gallery-8-244">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-9" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://cocos2dbook.com/wp-content/gallery/activetargetandexecmac/activetargetandactiveexec.png" title=" " class="shutterset_set_8"  rel="lightbox[244]">
								<img title="activetargetandactiveexec" alt="activetargetandactiveexec" src="http://cocos2dbook.com/wp-content/gallery/activetargetandexecmac/thumbs/thumbs_activetargetandactiveexec.png" width="400" height="300" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>


<p>If you select your project under the Target Executable and click Build and Run you should see the Cocos2D HelloWorld on your Mac.</p>

<div class="ngg-galleryoverview" id="ngg-gallery-9-244">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-10" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://cocos2dbook.com/wp-content/gallery/machelloworld/machelloworld.png" title=" " class="shutterset_set_9"  rel="lightbox[244]">
								<img title="machelloworld" alt="machelloworld" src="http://cocos2dbook.com/wp-content/gallery/machelloworld/thumbs/thumbs_machelloworld.png" width="400" height="300" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>


<p>HelloWorld is always a good sign. This means you have Cocos2D working and running inside your Mac game. Lets add the Penguino, open up the HelloWorldScene.m class and in the init method add the lines:</p>
<pre class="brush:objc">// Add the Penguino
penguino = [CCSprite spriteWithFile:@"penguino1.png"];
[penguino setPosition:ccp(size.width/2,size.height/2)];
[self addChild:penguino];</pre>
<p>Note that</p>
<pre class="brush:objc">CCSprite *penguino;</pre>
<p>should be added as an instance variable in the HelloWordScene.h header file. You should also grab the Penguino1.png image from the Project link at the bottom of the post. This code does nothing more then add a standard Sprite on the middle of the screen.</p>
<p><strong>Step 4 &#8211; Implementing Player Controls</strong></p>
<p>Now you just need to implement the touch controls, or accelerometer, oh wait, we are on the Mac and not iOS. Lets go old school and move Penguino around using nothing more then the arrow keys.</p>
<p>Here once more Cocos2D makes it easy to respond to keyboard events.<br />
Two sub-steps to respond to keyboard events.<br />
First, in your layer init, declare that you want to receive the keyboard events, by using:</p>
<pre class="brush:objc">self.isKeyboardEnabled = YES;</pre>
<p>Next you need to add either ccKeyDown, ccKeyUp, or both depending if you care to know when the user releases a particular key.</p>
<p>Lets add two methods above init, one to respond to the keyboard key down events, and another to move our penguin within the screen.</p>
<pre class="brush:objc">-(void)movePenguin:(CGPoint)directionOffset {
   CGSize size = [[CCDirector sharedDirector] winSize];
   CGPoint penguinPosition = [penguino position];
   float newXPosition = penguinPosition.x + directionOffset.x;
   float newYPosition = penguinPosition.y + directionOffset.y;

   if ((newXPosition &lt; 0.0f) || (newYPosition &lt; 0.0f)) {
     return; // Do not move
   }
   if ((newXPosition &gt; size.width) || (newYPosition &gt; size.height)) {
     return; // Do not move
   }

   [penguino setPosition:ccp(newXPosition,newYPosition)];
}
</pre>
<p>and the ccKeyDown method:</p>
<pre class="brush:objc">-(BOOL) ccKeyDown:(NSEvent *)event
{
   //NSLog(@"key down: %@", [event characters] );
   if ([event modifierFlags] &amp; NSNumericPadKeyMask) { // arrow keys have this mask
      NSString *theArrow = [event charactersIgnoringModifiers];
      unichar keyChar = 0;
      if ( [theArrow length] == 0 )
         return YES;            // reject dead keys
      if ( [theArrow length] == 1 ) {
         keyChar = [theArrow characterAtIndex:0];
         if ( keyChar == NSLeftArrowFunctionKey ) {
            CCLOG(@"Left Arrow pressed");
            CGPoint movePosition = ccp(-1,0);
            [self movePenguin:movePosition];
            return YES;
         }
         if ( keyChar == NSRightArrowFunctionKey ) {
            CCLOG(@"Right Arrow pressed");
            CGPoint movePosition = ccp(1,0);
            [self movePenguin:movePosition];
            return YES;
         }
         if ( keyChar == NSUpArrowFunctionKey ) {
            CCLOG(@"Up Arrow Pressed");
            CGPoint movePosition = ccp(0,1);
            [self movePenguin:movePosition];
            return YES;
         }
         if ( keyChar == NSDownArrowFunctionKey ) {
            CGPoint movePosition = ccp(0,-1);
            [self movePenguin:movePosition];
            CCLOG(@"Down Arrow Pressed");
            return YES;
         }
      }
  }
  return NO;
}
</pre>
<p>The ccKeyDown method has a couple of interesting lines:</p>
<p>First we pull out the event string and ignore any of the modifiers like the Option key. Change this if you care to know if those keys are pressed.</p>
<pre class="brush:objc">NSString *theArrow = [event charactersIgnoringModifiers];
</pre>
<p>The second thing to note is we are ignoring every key except the arrow keys. You may want to allow for more keys then just the arrows, so adjust accordingly. Take a look at the EventsTest Target included with Cocos2D-Mac project (that you cloned in Step 1)</p>
<p>If you click build and run you should have Penguino on the center of the screen, and will be able to move him around with the arrow keys.</p>

<div class="ngg-galleryoverview" id="ngg-gallery-10-244">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-11" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://cocos2dbook.com/wp-content/gallery/penguinomacpart1/penguinoonmac.png" title=" " class="shutterset_set_10"  rel="lightbox[244]">
								<img title="penguinoonmac" alt="penguinoonmac" src="http://cocos2dbook.com/wp-content/gallery/penguinomacpart1/thumbs/thumbs_penguinoonmac.png" width="400" height="300" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>


<p>That’s it for this short Part 1 of getting your Cocos2D game on the Mac. You now have a shell of the game, with a moving Penguin based on the arrow keys. Next week, Box2D physics on the Mac, or if you have other topics/suggestions, let me know in the comments.</p>
<p><a title="Cocos2D on the Mac Project" href="http://cocos2dbook.com/projects/Cocos2DMacGame.zip" target="_blank">Cocos2DMacGame Source</a></p>
<p>Thanks for reading,<br />
Rod</p>
<p>This post is part of <a title="idevblogaday.com" href="http://idevblogaday.com" target="_blank">iDevBlogADay</a>, a group of indie iOS development blogs featuring at least two posts per day. You can keep up with your favorite developers through the <a title="idevblogaday.com" href="http://idevblogaday.com" target="_blank">iDevBlogADay web site</a>, <a title="iDevBlogaDay RSS Feed" href="http://feeds.feedburner.com/idevblogaday" target="_blank">RSS feed</a>, or <a title="iDevBlogaDay on Twitter" href="http://twitter.com/#search?q=%23idevblogaday" target="_blank">Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cocos2dbook.com/cocos2d/cocos2d-on-the-mac-part1/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

