iPhone Port pt 1 - project setup

The Cocoa port is done - can we make this work on the iPhone? Absolutely. Instead of Quartz, I'll use GameKit and the OpenGL template. There is no reason why I can't use Quartz, but using GameKit and the graphics hardware will give me the following advantages:

I'm using Xcode 7.2 and targeting iOS 9. The steps are correct as of this writing. The templates and dialogs seem to change with every version of Xcode, so if they aren't correct for your version of Xcode, good luck! Just try to modify the steps using common sense.

When you use the templates in Xcode, they make a complete running application, and the developer has to modify the template. So the setup for this project will go fast.

Setting up the Xcode project

  1. Launch Xcode and start a new project with File -> New Project.

  2. Select iOS and Application, then choose the Game from the pane on the right.

  3. In the options sheet, select Devices: iPhone, Language Objective-C, and Game Technology OpenGL ES. Give it a name (I'm calling mine PhoneInvaders), and click the Next button.

  4. Choose a save location.

Now if you run the project at this point (cmd-R or from the menu, choose Product->Run), you will see a fully working OpenGL ES application. As of this writing, the code in the template displays a couple of rotating cubes with lighting. The GameViewController.m file will have to be modified to replace drawing the cubes with the drawing of our game. A lot of this file will go away, but not all of it.

Machine

I'll go ahead and make the machine object. Create a new NSObject object to represent the Space Invaders machine.

  1. File->New File...

  2. In the iOS section, select iOS, then choose Cocoa Touch Class and click Next.

  3. In the options sheet, name the class - I called mine "SpaceInvadersMachine". In the Subclass of field, put NSObject. For Language, Objective-C. Click Next.

  4. Choose a save location.

Other Files

I'll have to put the ROM files and the sounds in the project. I dragged in the Invaders.[e-h] ROM files and [0-9].wav sound files. When I drag them in, make sure that "Add to Project" is not selected in the sheet. If they are automatically added, the naming of the invaders ROM files makes Xcode think they are source files.

  1. In Finder, select the invaders.e, .f, .g, and .h ROM files and the 10 sound wav files into the project

  2. Drag them into the Xcode project making sure to put them in the "Supporting Files" folder

  3. In the sheet that drops down, check "Copy items if needed", and make sure "Add to Targets" is not selected.

  4. Click on the PhoneInvaders project in the project browser

  5. Click on the PhoneInvaders target

  6. Click on Build Phases

  7. Disclose Copy Bundle Resources

  8. Add all the invaders rom and sound files to the Copy phase

iOS Add Resources

Test your build again

Choose Product->Run to try it out one more time in the iPhone simulator. You should still see the rotating cube animation.

iOS Setup

That was super easy because the Xcode template is very close to what I need. In the next section, I'll add in the CPU emulator and the machine code.

← Prev: cocoa-port-pt-7---threading   Next: iphone-port-pt-2---machine-object →