2D Arcade Mac / iOS App

Apple iOS & MacOS/X

The following will make the 2D Arcade game for both iOS (phone / iPad) and Mac OS/X (Mac Desktop).

We can make the app for both desktop and mobile together as the code will be very similar for both. The difference will be the sizes of the images.

In Xcode, create a new project and select Game and iOS. This is the app for the iPhone and iPad. Later we will add the Mac OS desktop app as well to this project.

This image has an empty alt attribute; its file name is ios2darcade1-1024x726.png

I added my game name and company name (make one up). I added my Apple account by clicking on Add account…

This image has an empty alt attribute; its file name is ios2darcade2-1024x730.png

Select where to save your project. I enabled Git source control – this will keep track of source code versions.

This image has an empty alt attribute; its file name is 2darcademac3-1024x569.png

Click on the blue Star Invaders on the top left, then click on Targets, then click on the plus sign underneath to add another target. We will add the Mac OS app to this.

This image has an empty alt attribute; its file name is mactarget2darcade-649x1024.png

Select macOS and Game as below.

This image has an empty alt attribute; its file name is arcademac1-1024x727.png

I named it Star Invaders MacOS

This image has an empty alt attribute; its file name is 2darcademac4-1024x735.png

Press the Play button and select iPhone. This will build your project and create an iPhone simulator (this can be chosen to what you prefer) or you can build it directly to your phone or even iPad (you will need to give your app permission to run under General -> Settings -> Device Management -> Apple Development)

This image has an empty alt attribute; its file name is ios2darcade5.png


This will show you the iPhone view. If you press on the screen, you get some coloured rectangles:

This image has an empty alt attribute; its file name is ios2darcade7-576x1024.png

Your App will display below if you press the home button of the phone

This image has an empty alt attribute; its file name is ios2darcade8-576x1024.png

Select Star Invaders MacOS and then press the Play button and select the MacOS. You will see it as below.

This image has an empty alt attribute; its file name is arcademac2-1024x801.png

Apple iOS and MacOS App code

Documentation of the SpriteKit is here.

There is a good tutorial on starting SpriteKit here. You can add images in your app – instructions are here.

Documentation on setting up an app for iOS and MacOS is via the apple developer documentation. To develop for iOS, you use UIKit and for MacOS, you use AppKit

Some useful tutorials:

The initial template that is given via default when you create a new project from SpriteKit. It contains default code to display some text and display some coloured spinning rectangles.

The code in AppDelegate.swift contains application code to initialise your app, specifies what it does when the app runs in the background when inactive, and what happens when the user ends the app.

The code in GameViewController.swift (or ViewController.swift) loads the game scene.

The main game code is in GameScene.swift and this is where all the game code will be written. It has a class GameScene which is inherited from SKScene (Sprite Kit Scene). It contains the functionality of our game. You can override functions using the override func keywords.

It contains a function override func update(_ currentTime: TimeInterval) which updates once per frame – it also keeps track of time via a built in game timer to make the game run smoothly.

The next step is to alter the game code in GameScene.swift to build our game. We can pretty much use the same game code for both the iOS and MacOS game.

Note: Gamescene.sks and Actions.sks are files that you can use to build your game without much code. A tutorial on using this is here.