{"id":905,"date":"2011-04-26T17:17:09","date_gmt":"2011-04-26T23:17:09","guid":{"rendered":"http:\/\/www.philhassey.com\/blog\/?p=905"},"modified":"2011-04-29T10:34:51","modified_gmt":"2011-04-29T16:34:51","slug":"transitioning-to-xcode-4-0-x","status":"publish","type":"post","link":"https:\/\/www.philhassey.com\/blog\/2011\/04\/26\/transitioning-to-xcode-4-0-x\/","title":{"rendered":"Transitioning to Xcode 4.0.x"},"content":{"rendered":"<p>I&#8217;m working on a new game project that I&#8217;m hoping to release sometime in the next month or so!  I&#8217;m taking a break from Dynamite to do something a bit more wacky \ud83d\ude42  For these posts I&#8217;m going to be referring to my project as &#8220;mygame&#8221; since I&#8217;m not ready to announce the name of this super-amazing project yet.<\/p>\n<p>Anyway, I downloaded Xcode 4.0.2 the other day so I could get going with the latest iOS tools.  I&#8217;m going to be using more iOS features in this game than ever before, so I want to be sure I&#8217;m up to date with how things are supposed to be done.  Xcode, however, has quite a few changes, so here&#8217;s the documentation of some of the common things I do as an Xcode user that changed.<\/p>\n<p><strong>1. Adding CFLAGS to my project &#8220;-DMYGAME_IOS_BUILD, etc&#8221;<\/strong><\/p>\n<p>&#8211; Click on &#8220;mygame&#8221; at the top left of the project tree hierarchy.<br \/>\n&#8211; Click on the &#8220;Build Settings&#8221; tab in the main frame.<br \/>\n&#8211; Click on the &#8220;All&#8221; button to reveal all settings.<\/p>\n<p>From there you can find the &#8220;Other C Flags&#8221; setting.  Apparently Xcode 4 has &#8220;Schemes&#8221; (the name of your project) as well as &#8220;Builds&#8221; (Debug \/ Release) as well as &#8220;Destinations&#8221; (iPhone \/ iPad \/ Simulator).<\/p>\n<p><strong>2. Adding more Frameworks to the project<\/strong><\/p>\n<p>I always have a handful of frameworks I need to add.  In Xcode 3, you could right-click and click on &#8220;Add Existing Frameworks&#8221; to pick from a list.  This is no longer the case.  But doing the same is pretty easy:<\/p>\n<p>&#8211; Expand the &#8220;Frameworks&#8221; from the project tree.<br \/>\n&#8211; Right-click on one of the frameworks.<br \/>\n&#8211; Select &#8220;Show in Finder&#8221;<br \/>\n&#8211; Finder will open, and will show the folder where all the frameworks are.<br \/>\n&#8211; Drag and drop a framework from Finder to the Frameworks in your project<\/p>\n<p><strong>3. Working with the new OpenGLES iOS template<\/strong><\/p>\n<p>Every few releases of Xcode, Apple changes up the OpenGLES template.  I do wonder if I should just copy over it with my own stuff?  Maybe, but I figure Apple knows best or whatever, and I always adapt to the latest template for new projects.  This one has me a bit more confused than usual since it seems to use more Interface Builder type stuff and has a mygameViewController object in it as well (and corresponding .m and .h files.)<\/p>\n<p>&#8211; At this point I knew since I was going to be using GameCenter and IAP in this game I might as well learn a bit more ObjectiveC.  I&#8217;ve thus far managed to NOT learn it in the 3 years of iOS coding I&#8217;ve been doing.  So, to kick things off I figured I&#8217;d check out what the <a href=\"https:\/\/developer.apple.com\/videos\/iphone\/\">iOS development videos<\/a> might have for me.  Unfortunately, the newest videos are from Apple&#8217;s 2009 tour.  Kind of sad, I mean, 2009 was back before iPads even existed.  So those videos are certainly not going to help me deal with the new fancy in Xcode 4 and building Universal apps.<\/p>\n<p>&#8211; Instead I found that the typed <a href=\"https:\/\/developer.apple.com\/library\/ios\/navigation\/index.html?section=Resource+Types&#038;topic=Getting+Started\">documentation<\/a> was much more helpful.  I clicked into &#8220;Tools for iOS Development&#8221; to see what they&#8217;d have to say about Xcode 4.<\/p>\n<p>&#8211; From perusing a few documents I got the feeling that to use GameCenter, etc, I was going to need a ViewController.  Since the new OpenGLES template includes one, I guess that is good.  If there are any iOS devs reading this who want to point me towards some helpful tutorials so I can understand what I&#8217;m doing better, that would be great.  As-is, I am sort of continuing in my usual blind-cut-and-paste-and-hope type stupor with this stuff.<\/p>\n<p>&#8211; I hacked out all the GLES2 code, I still write all my code using GLES1 .. the advantage that gives me is that my code will work simply on pretty much any platform.  And I finally after 3 years understand GLES1 pretty well.  I suppose I might get into ES2 eventually, but not yet \ud83d\ude42  I also like that GLES1 code can work on the desktop with almost no changes.  I hear shaders can add complication to my life on the desktop.  Again, if anyone wants to link me to useful commentary on that, I wouldn&#8217;t mind!<\/p>\n<p><strong>4. Hacking my game onto the iOS app<\/strong><\/p>\n<p>I always code my games in C\/C++.  What I&#8217;ve found is the easiest way to get it to work with iOS is to rename all the .m files to .mm so that they are C++ aware ObjectiveC.  Then I have a set of wrapper functions for my game that the ObjectiveC code can call.<\/p>\n<p>Okay, so this is really cool, Xcode 4 now detects if you type in an invalid function name, and suggests a replacement function name \ud83d\ude42  And it worked!<\/p>\n<p><strong>5. Making the game Universal<\/strong><\/p>\n<p>Xcode 4 seems to make this pretty easy.  I just went into the Summary tab and switched mygame over to Universal and it all seemed to work pretty well.  I only had to add these lines to the top of my drawFrame method in my ViewController:<\/p>\n<pre>\r\nCGRect screenFrame = [[UIScreen mainScreen] applicationFrame];\r\ngame_resize(screenFrame.size.width,screenFrame.size.height);\r\n<\/pre>\n<p>Here&#8217;s the <a href=\"http:\/\/www.streamingcolour.com\/blog\/2010\/11\/28\/universal-opengl-apps\/\">blog post<\/a> that helped me with that.<\/p>\n<p><strong>6. Making the game Retina enabled<\/strong><\/p>\n<p>I just used this code snippet at the end of my EAGLView initWithCoder (I believe I got it from the <a href=\"http:\/\/www.fargoal.com\/\">Fargoal folks<\/a>):<\/p>\n<pre>\r\n      float scale = 1;\r\n\r\n      if([[UIScreen mainScreen] respondsToSelector:\r\n              NSSelectorFromString(@\"scale\")])\r\n      {\r\n              if([self respondsToSelector:\r\n                      NSSelectorFromString(@\"contentScaleFactor\")])\r\n              {\r\n                      scale = [[UIScreen mainScreen] scale];\r\n                      self.contentScaleFactor = scale;\r\n              }\r\n      }\r\n<\/pre>\n<p>&#8230;<\/p>\n<p>Towards the end of the day I spent some time mucking with orientation stuff.  That always confuses me!  And that&#8217;s all for today!<\/p>\n<p>-Phil<\/p>\n<p>P.S. Changing where the builds are made:<\/p>\n<p>By default the builds are put in ~\/Library\/Developer\/Xcode\/DerivedData .. they used to be placed within my project which is what I prefer.  This can be changed by going into Xcode > Preferences > Locations > Build Location > Place build products in locations specified by targets<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m working on a new game project that I&#8217;m hoping to release sometime in the next month or so! I&#8217;m taking a break from Dynamite to do something a bit more wacky \ud83d\ude42 For these posts I&#8217;m going to be referring to my project as &#8220;mygame&#8221; since I&#8217;m not ready to announce the name of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"class_list":["post-905","post","type-post","status-publish","format-standard","hentry","category-iphone"],"_links":{"self":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/comments?post=905"}],"version-history":[{"count":9,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/905\/revisions"}],"predecessor-version":[{"id":919,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/905\/revisions\/919"}],"wp:attachment":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/media?parent=905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/categories?post=905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/tags?post=905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}