1. Getting Started with Social Gaming
Abstract
Welcome to Beginning iOS Social Games ! This book is designed to walk you through the process of adding Game Kit, Game Center, and other social functionality into your iOS apps and games. It is centered on a sample game called UFOs that you will be introduced to later in this chapter. However, if you have an existing app or game to which you want to add social functionality, you may use that project instead. This book is written as a reference and resource tool to aid you in the process of adding social functions into your iOS app. Although I recommend you read it from beginning to end to learn the most about the technologies covered, that is not a requirement. Every chapter stands on its own. You can freely skip ahead to the chapters that are relevant to your project needs and quickly implement that functionality into your app.
Welcome to Beginning iOS Social Games ! This book is designed to walk you through the process of adding Game Kit, Game Center, and other social functionality into your iOS apps and games. It is centered on a sample game called UFOs that you will be introduced to later in this chapter. However, if you have an existing app or game to which you want to add social functionality, you may use that project instead. This book is written as a reference and resource tool to aid you in the process of adding social functions into your iOS app. Although I recommend you read it from beginning to end to learn the most about the technologies covered, that is not a requirement. Every chapter stands on its own. You can freely skip ahead to the chapters that are relevant to your project needs and quickly implement that functionality into your app.
While this book covers a number of aspects of social gaming, its focus is Apples social gaming platform Game Kit, and by extension Game Center. When Apple announced Game Kit on March 17, 2009, it was presented as an answer to the difficulty of real-time networking on iOS devices, which until that point had been challenging. Game Kit added support for Bluetooth and LAN as well as voice chat services. Shortly after, Apple announced the Game Center addition to Game Kit as part of iOS 4.0. With the newly announced SDK version, Apple brought a wealth of new featuresthe Game Center being the most important to the scope of this book. With iOS 5, Game Center once again saw additions, most notably the addition of turn-based gaming to the framework. Apple continued the tradition of supporting Game Center in iOS 6 with the addition of Game Center Challenges. In addition to the Game Center changes, Apple added OS-level support for Twitter in iOS 5 and for Facebook in iOS 6. With the introduction of iOS 7 at WWDC 2013 Game Center saw a complete redesign from the ground up to match the flatter look and feel introduced with UIKit.
Commonly developers in the iOS community have a tendency to think of Game Center as a separate set of Application Programming Interfaces (APIs). This is a fallacy. Game Center is an integral part of Game Kit. The two complement one another and work hand in hand. You will see much evidence of this in the following pages. For the purpose of this book, we are going to address both of these technologies together as Game Kit; however, we may still refer to Game Centerspecific functionality by its proper name.
The first ten chapters of this book are dedicated to Game Kit functionality; the remaining chapters cover additional social elements such as Store Kit and In App Purchasing in .
Please note that despite their names, Game Kit and Game Center are not designed for just games. Although recently Apple has begun cracking down on Game Center technology being used in non-games. Some developers have received the following type of rejection email from Apple.
The intended use of Game Center is to complement game apps or game functionality within an app. However, we noticed that your app does not contain any game play or game features.
These rejections seem to apply mainly to the use of leaderboards and achievements in non-gaming apps. The argument can easily be made that adding a leaderboard or achievement system to your app adds a gameplay element. If you happen to receive this rejection you still have the option of appealing it, I have yet to hear from a developer who has not successfully appealed on these grounds. There havent been any instances of rejection for using Game Kit networking in any app that I have observed.
Game Kit: An Overview
Game Kit can be broken up into three individual sections: networking, Game Center, and voice chat. Although all of these services work together to create one seamless environment, it can be helpful to look at each individually. While there might be overlap, each section can be considered as a primary category. While the API itself does not differentiate these sections, it can be useful to keep them separate while learning and thinking about Game Kit development.
Networking
Networking in Game Kit allows you to send and receive data between one or more peers. Game Kit networking also provides a connection protocol to connect to local clients that are found on your Wi-Fi network, or locally using Bluetooth. Game Center also extends this functionality with WAN matchmaking.
Game Kit supports creating an ad-hoc Bluetooth or local wireless network between two iOS devices. With the introduction of iOS 4.0, Game Kit began supporting networking on the world area network supporting up to 16 players at once. Game Kit networking is covered in Chapters 6, 7, and 8. Game Center matchmaking is covered in .
Game Center
Game Center handles authentication, friends, leaderboards, achievements, challenges, and invitations. In a sense, Game Center is providing the developer with the server services that are related to social interaction. It can also be argued that Game Center contains its own networking system. While this is true, we will be grouping that topic in the preceding section on networking, which is covered extensively in .
Note
The term Game Center , as used in various print and reference documentation, sometimes refers to the collective set of Game Center APIs as well as to the Game Center app itself.
Voice Chat
Game Voice, as Apple refers to it, allows any app (not just games) to provide voice communication over a network connection. The APIs handle the capturing and playback of audio feeds for the user and provide services to handle connections, communications, errors, and disconnections. This technology is discussed in .
Sample Game: UFOs
In my experience, most developers are experience-type learners. This means that they learn best by doing, not by watching or listening. When I first started to learn how to program, I would copy source code out of code magazines line by line into a Commodore 64. The experience of physically typing in each line of code is what made the information stick. Listening to a lecture or watching someone else write code made it difficult to retain a good deal of the information. I cant imagine I would have stayed with this career path if lectures and demonstrations were my only ways of learning. This book is designed in the spirit of experience-type learners.
The first thing we need to cover, before moving into Game Kit itself, is working with the supplied sample game. The game, which we call UFOs, is designed not to be an award-winning, addictive game, but rather to be simple enough that it can be thought of as any generic project, and allow you to focus on the social gaming aspects. I have made every effort to reduce the amount of code to less than 300 lines. Although the game itself is simple, it is vital that all readers understand the code as if they wrote it themselves. Keeping the example simple will allow you, as the reader, to detach yourself from the project itself and focus on the Game Kitspecific information. We start by playing the game, then looking at the source code.