{"id":2062,"date":"2012-10-01T19:45:35","date_gmt":"2012-10-01T18:45:35","guid":{"rendered":"http:\/\/t-machine.org\/?p=2062"},"modified":"2012-10-01T19:49:06","modified_gmt":"2012-10-01T18:49:06","slug":"made-an-iphone-game-in-2hrs-15mins-native-code","status":"publish","type":"post","link":"http:\/\/new.t-machine.org\/index.php\/2012\/10\/01\/made-an-iphone-game-in-2hrs-15mins-native-code\/","title":{"rendered":"Made an iPhone game in 2hrs 15mins (native code)"},"content":{"rendered":"<p>How slow is making iPhone apps using native code?<\/p>\n<p>You have to write HTML5, right, if you want FAST app development on iPhone? Or Unity? Or cocos2d?<\/p>\n<p>Right?<\/p>\n<p>Or &#8230; write it in Objective-C &#8230; a beginner-friendly &#8220;native&#8221; language: <a href=\"http:\/\/www.youtube.com\/watch?v=dzW-C0RFjx0\">2 hrs and 15 mins to create the artwork, design the game, code it in native Objective-C, debug it, and push to iPhone devices<\/a><\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"http:\/\/www.youtube.com\/embed\/dzW-C0RFjx0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>NB: first half shows: &#8220;Collect the fish, avoid the dynamite, grow bigger!&#8221;<br \/>\nSecond half shows: &#8220;if you hit dynamite, you shrink; when you&#8217;re tiny, if you hit dynamite, you&#8217;re fishfood :(&#8221;<\/p>\n<h4>For the love of &#8230; WHY?<\/h4>\n<p>Because I entered <a href=\"http:\/\/dotbrightongamejam2012.eventbrite.co.uk\/\">a voluntary &#8220;48-hour game jam&#8221;<\/a> (you have one weekend to make a game), and last time I went to the Apple shop for a repair, they dislodged my network card. It fell out, internally, and it&#8217;s not user-fixable (believe me, I tried &#8211; even specialist screwdrivers aren&#8217;t enough :( ).<\/p>\n<p>So I did something else with my weekend. But a few hours before the competition deadline, I figured &#8220;what the heck; what could I do in a couple of hours?&#8221; &#8230; with some encouragement from <a href=\"http:\/\/twitter.com\/TheMightyGit\">The Mighty Git<\/a>.<\/p>\n<h4>The code?<\/h4>\n<p>222 lines of code, including comments, blank lines &#8211; and code that I commented out because I replaced it with other code.<\/p>\n<p>That&#8217;s all it takes for a working, playable, iPhone game.<\/p>\n<h4>&#8230;and the art?<\/h4>\n<p>You can&#8217;t see it from the video, but the art is resolution-independent &#8211; as your whale gets bigger, it re-renders, so that all the curves ALWAYS have razor-sharp edges. No effort required on my part.<\/p>\n<p>I did all the artwork in <a href=\"http:\/\/inkscape.org\/\">Inkscape<\/a> (free image editor for vector images), and saved as SVG (web-standard for vector images).<\/p>\n<p>Then, courtesy of the <a href=\"https:\/\/github.com\/SVGKit\/SVGKit\/\">open-source SVGKit project<\/a> (renders vector images on iOS, because Apple doesn&#8217;t add support to their libaries &#8211; shame), and the following few lines of code:<\/p>\n<pre lang=\"objc\">\r\n\tself.sivWhale = [[SVGKImageView alloc] initWithSVGKImage:[SVGKImage imageNamed:@\"whale-1.svg\"]];\r\n\tsivWhale.frame = CGRectMake( 0, 0, sivWhale.frame.size.width * sivWhale.scaleMultiplier.width, sivWhale.frame.size.height * sivWhale.scaleMultiplier.height );\r\n\tsivWhale.center = CGPointMake( self.view.frame.size.width\/2.0f, 0.75f * self.view.frame.size.height );\r\n\t[self.view addSubview:sivWhale];\r\n<\/pre>\n<p>If that looks rather like using a built-in UIImage and UIImageView &#8230; it&#8217;s because it&#8217;s intended to. SVGKit adds a new type of image &#8211; SVGKImage &#8211; that&#8217;s almost the same as an Apple UIImage, except it&#8217;s better (it&#8217;s resolution independent). And the SVGKImageView does for SVGKImage what UIImageView does for UIImage&#8230;<\/p>\n<h4>Want the code?<\/h4>\n<p>Sadly, the version of SVGKit I used here has some bugs in it &#8211; it&#8217;s live at: <a href=\"https:\/\/github.com\/adamgit\/SVGKit\/tree\/transforms\">https:\/\/github.com\/adamgit\/SVGKit\/tree\/transforms<\/a> &#8211; but until it&#8217;s been tested and fixed by the SVGKit maintainers, it won&#8217;t appear on the main SVGKit project page.<\/p>\n<p>So, feel free to use that link and play with it &#8211; but be warned: it&#8217;s NOT as stable as the main SVGKit. Yet.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How slow is making iPhone apps using native code? You have to write HTML5, right, if you want FAST app development on iPhone? Or Unity? Or cocos2d? Right? Or &#8230; write it in Objective-C &#8230; a beginner-friendly &#8220;native&#8221; language: 2 hrs and 15 mins to create the artwork, design the game, code it in native [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,28,9,51],"tags":[],"_links":{"self":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/2062"}],"collection":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/comments?post=2062"}],"version-history":[{"count":0,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/2062\/revisions"}],"wp:attachment":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/media?parent=2062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/categories?post=2062"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/tags?post=2062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}