Book Image

Swift Game Development - Third Edition

By : Siddharth Shekar, Stephen Haney
Book Image

Swift Game Development - Third Edition

By: Siddharth Shekar, Stephen Haney

Overview of this book

Swift is the perfect choice for game development. Developers are intrigued by Swift and want to make use of new features to develop their best games yet. Packed with best practices and easy-to-use examples, this book leads you step by step through the development of your first Swift game. The book starts by introducing Swift's best features – including its new ones for game development. Using SpriteKit, you will learn how to animate sprites and textures. Along the way, you will master physics, animations, and collision effects and how to build the UI aspects of a game. You will then work on creating a 3D game using the SceneKit framework. Further, we will look at how to add monetization and integrate Game Center. With iOS 12, we see the introduction of ARKit 2.0. This new version allows us to integrate shared experiences such as multiplayer augmented reality and persistent AR that is tied to a specific location so that the same information can be replicated on all connected devices. In the next section, we will dive into creating Augmented Reality games using SpriteKit and SceneKit. Then, finally, we will see how to create a Multipeer AR project to connect two devices, and send and receive data back and forth between those devices in real time. By the end of this book, you will be able to create your own iOS games using Swift and publish them on the iOS App Store.
Table of Contents (22 chapters)
Swift Game Development Third Edition
Contributors
Preface
Other Books You May Enjoy
Index

What you will learn in this book


By the end of this book, you will be capable of creating and publishing your own iOS games. You will know how to combine the techniques we will learn to create your own style of game and you will be well prepared to dive into more advanced topics with a solid foundation in 2D, 3D, and AR game design.

Embracing SpriteKit

SpriteKit is Apple's 2D game development framework and your main tool for iOS, macOS, tvOS, and watchOS game design. SpriteKit will handle the mechanics of our graphics rendering, physics, and sound playback. As far as game development frameworks go, SpriteKit is a terrific choice. It is built and supported by Apple and thus integrates perfectly with Xcode and iOS. You will learn to be highly proficient with SpriteKit as we will be using it exclusively in our demo game.

We will learn how to use SpriteKit to power the mechanics of our game in the following ways:

  • Animating our player, enemies, and power-ups

  • Painting and moving side-scrolling environments

  • Playing sounds and music

  • Applying physics such as gravity and impulses for movement

  • Handling collisions between game objects

Similar to SpriteKit, we will also look at SceneKit. In SceneKit, instead of importing images, we will be loading 3D models, placing them in the scene and creating a game around them. We will also see how to add player movement, animation, physics, controls, collision, and scoring.

In ARKit, with 2D and 3D game demos, we will see how to take existing games and make augmented reality games out of them.

Reacting to player input

The control schemes in mobile games must be inventive. Mobile hardware forces us to simulate traditional controller inputs, such as directional pads and multiple buttons, on the screen. This takes up valuable visible area and provides less precision and feedback than with physical devices. Many games operate with only a single input method: a single tap anywhere on the screen. We will learn how to make the best of mobile input and explore new forms of control by sensing device motion and tilt.

Structuring your game code

It is important to write well-structured code that is easy to reuse and modify as your game design inevitably changes. You will often find mechanical improvements as you develop and test your games, and you will thank yourself for a clean working environment. Though there are many ways to approach this topic, we will explore some best practices to build an organized system with classes, protocols, inheritance, and composition.

Building UI/menus/levels

We will learn how to switch between scenes in our game with a menu screen. We will cover the basics of user experience design and menu layout as we build our demo game.

Integrating with Game Center

Game Center is Apple's built-in social gaming network. Your game can tie into Game Center to store and share high scores and achievements. We will learn how to register for Game Center, tie it into our code, and create a fun achievement system.

Maximizing fun

If you are like me, you will have dozens of ideas for games floating around your head. Ideas come easily, but designing fun gameplay is difficult! It is common to find that your ideas need gameplay enhancements once you see your design in action. We will look at how to avoid dead ends and see your project through to the finish line. Plus, I will share my tips and tricks to ensure your game will bring joy to your players.

Crossing the finish line

Creating a game is an experience you will treasure. Sharing your hard work will only sweeten the satisfaction. Once our game is polished and ready for public consumption, we will navigate the App Store submission process together. You will end up feeling confident in your ability to create games with Swift and bring them to the market in the App Store.

Monetizing your work

Game development is a fun and rewarding process, even without compensation, but the potential exists to start a career, or side job, selling games on the App Store. Successfully promoting and marketing your game is an important task. I will outline your options and start you down the path to monetization.