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.
I added my game name and company name (make one up). I added my Apple account by clicking on Add account…
Select where to save your project. I enabled Git source control – this will keep track of source code versions.
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.
Select macOS and Game as below.
I named it Star Invaders MacOS
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 will show you the iPhone view. If you press on the screen, you get some coloured rectangles:
Your App will display below if you press the home button of the phone
Select Star Invaders MacOS and then press the Play button and select the MacOS. You will see it as below.
Apple iOS and MacOS App code
Documentation of the SpriteKit is here.
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.