2D Ios and Tvos Games by
Total Page:16
File Type:pdf, Size:1020Kb
2D iOS & tvOS Games by Tutorials Bonus Chapters 2D iOS & tvOS Games by Tutorials Table of Contents: Overview Chapter 25: Game Center Achievements..................... 6 Chapter 26: Game Center Leaderboards................. 32 Chapter 27: ReplayKit ................................................... 49 Chapter 28: iAd .............................................................. 73 Chapter 29: 2D Art for Programmers......................... 88 raywenderlich.com 3 2D iOS & tvOS Games by Tutorials Table of Contents: Extended Chapter 25: Game Center Achievements ............................. 6 Getting started..................................................................................................................... 6 Introduction to Game Center ............................................................................................. 7 Configuring your app to use Game Center ................................................................. 10 Authenticating local players ............................................................................................ 17 Adding achievements........................................................................................................ 21 Initializing the built-in user interface.............................................................................. 26 Challenges........................................................................................................................... 31 Chapter 26: Game Center Leaderboards ......................... 32 Supporting leaderboards ................................................................................................ 33 Leaderboard sets .............................................................................................................. 42 Security in Game Center.................................................................................................. 46 Challenges........................................................................................................................... 48 Chapter 27: ReplayKit............................................................ 49 ReplayKit architecture ...................................................................................................... 49 Integrating ReplayKit........................................................................................................ 51 Challenges........................................................................................................................... 72 Chapter 28: iAd....................................................................... 73 Introduction to iAd ............................................................................................................. 73 How does iAd work? ......................................................................................................... 74 Ad formats .......................................................................................................................... 76 Integrating iAd................................................................................................................... 78 Joining the iAd network.................................................................................................... 78 Integrating the iAd framework ....................................................................................... 80 Displaying banner ads ..................................................................................................... 82 Displaying interstitial ads................................................................................................. 84 iAd best practices.............................................................................................................. 86 Challenges........................................................................................................................... 87 Chapter 29: 2D Art for Programmers ................................. 88 Choose your path: Hire or DIY? ...................................................................................... 89 How to find and hire an artist......................................................................................... 90 Paying your artist............................................................................................................... 92 raywenderlich.com 4 2D iOS & tvOS Games by Tutorials Getting started .................................................................................................................. 94 Begin with a sketch............................................................................................................ 95 Getting the sketch into Illustrator ................................................................................. 100 Tracing the sketch with vector lines .............................................................................. 104 Custom stroke widths....................................................................................................... 108 Coloring your artwork.................................................................................................... 111 A bit about shadow and light....................................................................................... 123 Exporting PNG files........................................................................................................ 130 Challenges........................................................................................................................ 133 raywenderlich.com 5 Chapter 25: Game Center Achievements 25By Ali Hafizji So far, all of the minigames you’ve created for this book have been single-player. Personally, I prefer a little friendly competition! Luckily, this is easy to do in iOS thanks to Apple’s Game Center app and APIs. Over the next two chapters, you'll learn all about Game Center and how to integrate it into a Sprite Kit game. Specifically: • In this chapter, you’ll learn about Game Center and take a quick tour of its features. Along the way, you’ll learn how to authenticate the local player, enable achievements and add support for them to your game. • In the next chapter, you’ll continue your exploration of Game Center by adding support for leaderboards. Let the competition begin! Getting started In the next two chapers, you will integrate Game Center into a car racing came called Circuit Racer. CircuitRacer is an exciting game, but it's also quite simple. The player has to complete laps around a track within a fixed period of time. For a little extra fun, the player has the option of choosing a vehicle type and a track with a difficulty level of either easy, medium or hard. raywenderlich.com 6 2D iOS & tvOS Games by Tutorials Chapter 25: Game Center Achievements By this point in the book, you've already learned enough about Sprite Kit to make this game on your own, so to save you some time we've built a starter project for you with the gameplay implemented. This way, you can stay focused on the main theme of this chapter - Game Center. This starter project is a great review of what you've learned so far in this book. Before you begin, you should open the project in the starter folder and take a tour of the existing code. A good place to start would be Main.storyboard in the CircuitRacer group. This will give you an understanding of how the game is structured and what view controllers are present in the game. Since the game also supports tvOS a similar storyboard is present for the tvOS target. Now select the CircuitRacer target, build and run the game and get behind the wheel for a few laps. You can race to beat the clock, but that's about it. It's your job to turn on Game Center, integrate it into the app and add specific achievements that the player can unlock, like completing the hardest level. If you're ready to learn how to add a new level of interactivity to your game, then buckle up, pull on your racing gloves and rev up your coding engine! It's time to begin. Introduction to Game Center If you’re an iOS gamer, you’ve no doubt come across Game Center already. On the user side, Game Center consists of an app that acts as a central hub to browse your friends, leaderboards, achievements and challenges: raywenderlich.com 7 2D iOS & tvOS Games by Tutorials Chapter 25: Game Center Achievements On the developer side, Game Center provides a set of APIs you can integrate into your game to support achievements, leaderboards, challenges, turn-based gaming, real-time multiplayer gaming and more. Why should you add Game Center support to your game? Well, not only can it significantly up your game’s fun quotient—it can also increase your downloads. If your game supports Game Center, you'll benefit from a number of extra ways players can discover your app: • Listed on profile. Each player’s game list, leaderboards and achievements will include your app. When someone views a friend’s profile, your game might be there! raywenderlich.com 8 2D iOS & tvOS Games by Tutorials Chapter 25: Game Center Achievements • Friend challenges and requests. Players can challenge their friends to beat their high scores or—if your game has multiplayer support—invite them to play. In either case, Game Center will present the new player with the option to download or buy your app, providing a viral growth mechanism. • More ratings. Game Center makes it easier for players to rate your game, or like it on Facebook, by presenting those options on the selection screen. Anything raywenderlich.com 9 2D iOS & tvOS