Indie Game Developer: Why I Chose Objective-C For My First Game
Michael Paynter is a Codementor user and an independent game developer working on his first iOS game. After more than a year and a half, he reflects on his time learning Objective-C as his first language, and why he believes it remains a viable option for anyone looking to get into indie development.
Weighing the Options
While looking for languages to learn, I was immediately drawn to Java and C++.
Java has a massive installed base, and is the language of choice for many programmers. It also has a reputation for being easy to pick up, and there are many resources to help you do so.
C++ (or possibly C#), on the other hand, aligned with my long-term goals of getting into console development. With the announcement that every Xbox One could turn into a dev kit, it almost seemed crazy enough to try.
When I started looking at Objective-C, however, I saw a real chance to succeed as a one-man studio, and I had to take it. The giant installed base is a huge draw, and even though total number of Android users is now more than iOS, iOS still generates substantially more revenue.
The trick is getting your hands on some of that revenue. When I started digging into Xcode, I found a cohesive environment that would allow me to create a high-quality app, even at the beginning of my programming career. It featured several powerful tools that I’m very grateful for, and would not have been able to get where I am without. If you’re looking to dive into game development, I highly recommend you look at the amazing tools Objective-C provides.
Cocoa and Cocoa Touch
If you’re diving into development for iOS or OS X, Xcode provides you with the Cocoa API (application programming interface) for Mac, or Cocoa Touch for the iPhone/iPad by default.
These additional libraries provide you with the majority of the tools you’ll be using for development, including touch and gesture controls for mobile. Luckily, if you believe you may want to publish to both platforms, these two API’s are very compatible with one another, making porting from one to another a much less painful process than, say, switching from one language to another.
Xib and Storyboard
Two of the most powerful features in Xcode are the xib (pronounced nib) and storyboard files. They are generated for you when you create your project and provide you with a visual interface to lay out your application. They represent a very literal interpretation of what the user will see, automatically adjusting resolution depending on the platform, and they may be a step up when approaching the design of your app.
If you are learning Objective-C as your first language, you may find this visual approach especially useful. Using these tools, you can have Xcode write small amounts of code for you by clicking and dragging, though they are nowhere near robust enough to create your entire app this way. Instead they are most helpful when laying out the visual elements you wish to be presented on the screen.
If you opt for the storyboard you can control the transitions of one scene to another – for example, the menu to your game – all within this visual interface. However, if this visual approach is not for you, it can be ignored entirely and you can continue making your apps programmatically.
Automatic Reference Counting
For those of you who have a hard time keeping track of things, ARC is a godsend. It removes the obligation of the programmer to keep track of the memory allocated to every object created and instead assigns that job to the compiler.
For those of you just starting out, this means that all the memory you claim in your program, such as space for images and sound files, are constantly being self-evaluated for deletion. If they are no longer being used, they are cleaned from memory to make room for other objects, programs, and the operating system itself.
This leads to a lot fewer memory leaks, and removes a lot of the tediousness of memory management, especially for beginners. What’s more, all of this is done at minimal cost to the CPU, so you don’t have to feel bad about letting the computer do a little of the work for you.
Gamecenter
If you have multiplayer on your mind, Objective-C has you covered. Whether it’s a turn-based game or it features live multiplayer, Game Center makes it easy to connect your players with a few simple lines of code. It features a maximum of 16 players connected in one game at a time, and has features to help your players keep track of their personal achievements, view their friends’ achievements, and keep track of their position on the Leaderboard.
Obj-C also gives you the option of initiating a built-in interface to handle these interactions, which run independently on pre-installed code. If you seek a higher sense of cohesion throughout your application, you can also incorporate these functions programmatically in your own custom code.
Additional API’s
So far, you’re running Cocoa on top of Objective-C, which is a superset of C. That should be enough functionality to get your started, right? Though Obj-C and Cocoa give you plenty of toys to play with, there may be others you wish to think about adding before sitting down to write code.
Cocos2D-x and Sprite Kit add even more baked-in functionality so you can spend more time debugging/optimizing and less time building complex physics or particle engines. Cocos2D-x is a community built, open source engine. It’s been around longer than Sprite Kit, but Sprite Kit has the advantage of being built into Xcode 5 and later, preventing the need for additional setup. Utilizing one of these two popular engines makes complex animations, physics, and particles practically a non-issue.
One thing to keep in mind when using these engines is that they do not utilize the xib file for visual aid. Instead they utilize Scenes which are launched from the ViewController (the main file of your app), but the advantages they provide can far outweigh this minor inconvenience.
Swift and Beyond
Finally, a very good reason to learn Objective-C is Swift and the future of the language. Swift was introduced at WWDC 2014, Apple’s annual developer conference, and is poised to replace Objective-C.
If you’ve already begun your Objective-C education, fear not! All your code will still work in Swift, as it still uses the Objective-C runtime. Also note that Swift is only replacing Objective-C itself, and not the overlaying Cocoa libraries. Swift is touted by Apple as “Objective-C without the C.” In other words, it is a modern reimagining of the language which aims to add even more stability and ease-of-use.
If you are a new to programming but want to start out with this new language, Xcode 6 is still in beta (as of the time of this writing), which means it may still have a few bugs floating around. From personal experience, there is nothing more frustrating for a new coder than to learn the bug you’ve been trying to figure out for weeks is actually a problem with Xcode, and not your code itself, so it may be less of a headache to go with Xcode 5 for now, and wait for the official release of Xcode 6 before diving into the future of iOS and OS X.