Beginning iOS Social Games

所需积分/C币:10 2014-03-21 22:12:20 6.53MB PDF
6
收藏 收藏
举报

November 26, 2013 Beginning iOS Social Games is your concise introduction to iOS social and other networked gaming app development using iOS Game Center, Game Kit, Store Kit, AirPlay, iOS 7 Game Controllers, iTunes App Store and integrating with social networks/media like Facebook and Twitter. Aut
Contents at a Glance About the author About the technical reviewers ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ XV Acknowledgments XIX Foreword: better with friends xxi Introduction… XXII Chapter 1: Getting Started with Social Gaming Chapter 2: Game Center Setting up and getting started mmmm 19 Chapter 3: Leaderboards ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 35 Chapter 4: Achievements ■■■■■■■ 67 Chapter 5: Matchmaking and Invitations am mmmmmmmmma 103 Chapter 6: The Peer Picker u127 Chapter 7: Network Design overview 141 Chapter 8: Exchanging data 153 Chapter 9: turned-Based Gaming with Game Center ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 179 Chapter10: Voice chat,…,,,,,,,,,,,,,,…,,197 Contents at a glance Chapter 11: In-App Purchase with Storekit ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 209 Chapter12: Twitter,,,,,,,,,,,,,,,,,,,,,235 Chapter 13: Facebook 245 Chapter 14: AirPlaymanan a259 Chapter 15: Game Controllers mm ammammmaamanaanaam 267 Indexu277 Introduction Mobile games are social and becoming more integrated into our social lives every day. Game Center and Game Kit are apple' s answers to integrating social aspects into ios games, making it easier than it has ever been before to add items like leaderboards achievements, multiplayer and voice chat. Social network integration exists on everything from cars to refrigerators, and adding Twitter and Facebook support to an ios game has become just about a requirement. airplay and game controllers may be the next great leap forward in mobile gaming, if history has taught us anything; those that are a step ahead of the future are positioned for success Prerequisites This book assumes that you have the basic skills and understanding required to create an iOS app It also assumes that you have the background necessary to work with Xcode 5.0. There will be no primer on how to define methods and variables, install and launch Xcode, or create and work with new classes. There are many excellent books on those topics. When you feel ready to begin working with some of the more advanced Cocoa technologies such as Game Center and Game Kit, be sure that you have the basics mastered to a degree that allows you to move through this book without consulting other texts for help In addition to the basic requirements, Game Center and the other frameworks covered also heavil leverage blocks, which are a fairly new programming concept to Objective-C. If you haven't yet worked with blocks, we recommend that you read Apple's guide to them, which you can find by searchingforblocksathttp://developer.apple.comYoushouldalsofeelcomfortableworkingwith all the features that were introduced with the objective-C 2.0 release How This book Is organized As you begin working through this book, you will notice that its chapters are essentially standalone Every effort has been made so that each chapter can be read independently of the others. If you have no experience with Game Center or Game Kit yet, it is highly recommended that you read the first two chapters before skipping around, as they will provide you with the basic information on aIlI oxiv ntroduction how to get Game Center and game Kit up and running in your development environment. The final four chapters are built on top of the sample code from Chapter 3 and do not continually build on the existing product Each chapter follows along with a simple sample ios game that is introduced in Chapter 1. Following along with the book from start to finish will walk you through the process of creating a fully functional Game Center and Game Kit-leveraged ios game. In addition, each chapter will build onto a game Center Manager class that is designed to be reusable across all of your projects. Chapters 12 and 13 will introduce you to Social Framework and adding Twitter and Facebook support to the sample game. Chapters 14 and 15 cover Airplay and Game Controllers you already have a background in general ios development or Game Center and are looking fo help on a specific technology, each chapter is designed to walk you through its covered technology, as well as provide samples showing how to apply the technology to your software Source code Thesourcecodefortheprojectsfoundinthisbookisavailableatwww.apress.com/source-code/ Source code is made available in both ARc (Automatic Reference Counting)and non-ARC formats The code examples used in the text of this book are non-ARC; this is done because it is easier to add ARC support then to remove it. While arc is quickly becoming the standard there are developers, managers, and projects, which for one reason or another are not arc ready yet Required Software, Materials, and equipment To develop ios software-and more specifically, Game Center and Game Kit-based ios software-you will first need an Intel-based Mac computer running OSX 10.8 Mountain Lion)or newer. While you can develop on 10.6, it will not support the most up-to-date release of Xcode. You will also need a copy ofXcode,whichyoucandownloadfreefromtheMacAppStoreorathttp://developer.apple.com This book has been targeted to work with ioS 7; since it is being released at the time when users will be migrating from ios 6 to ioS 7, it is also written to support ios 6. Unless otherwise noted within the text, all code is ios 6-compatible In addition to the software and hardware requirements, you will also need an ios developer account provided by Apple. This account lets you build and test software on devices, as well as ship your finished product to the App Store. The software developer account is available for $99 USd a year andyoucanpurchaseyoursathttp://developer.applecom/iphone Chapter Getting started with Socia Gaming 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 Apple's 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 features-the 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(APls). 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 Center-specific functionality by its proper name. CHAPTER 1: Getting Started with Social Gaming 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 Chapter 11, Twitter and Facebook sharing in Chapters 12 and 13, Airplay mirroring in Chapter 14, and ioS 7 Game Controllers in chapter 15 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 haven't 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 aPl 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 Vi-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 Chapter 5 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 Chapter 5 Game Center technologies, such as leaderboards and achievements,are covered in Chapters 3 and 4 CHAPTER 1: Getting Started with Social Gaming 3 Note The term Game Center, as used in various print and reference documentation sometimes refers to the lective set of Game Center APls 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 Chapter 10 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 Kit-specific information We start by playing the game, then looking at the source code NoteThesourcecodeforallthechaptersaswellasthesampleprojectisavailableatwww.apress.com The sample code is provided in two formats: one that supports automatic Reference Counting(aRc) nvironments, a feature added in iOS 5, and one using the manual memory management system. other than support for ARC, these projects are identical It is important to note that the sample code that appears in print is the non-ARc version If you are using ARC, you will need to make adjustments. For more information, see the apple article on transitioning toArcathttp://developer.applecom/library/ios/releasenotes/objectivec/ RN-TransitioningtoArc/Introduction/Introduction. html CHAPTER 1: Getting Started with Social Gaming UFOs: Understanding the Game The first thing you need to do is open the base project that you downloaded from apress. com Figure 1-1 shows the file structure for the project. We'l quickly run the game to see what it's like P口AA5ts Today, 2: 57 PM build Today, 2: 57 PM Classes Today, 2: 56 PM main. m Today, 2: 56 PM Mainwindow Today, 2: 58 PM h UFOs_ Prefix. pch Today, 2: 56 PM 回UFOs-nfop|st Today, 2: 59 PM △ UFOS. xcodeproj Tod ay, 2: 59 PM Figure 1-1. The file structure for the UFO sample project, as seen by the Finder To play the game, select Build and Run from Build menu bar. The game will launch to a generic screen with one button labeled"Play. " Go ahead and select the Play button. You will be taken to the game screen, as seen in Figure 1-2 SCORE 00000 Figure 1-2. A look at the gameplay view from the UFOs sample project The objective of the game is typical; tilt the device up/down or left/right to move your ship around the screen. Once you are positioned over a coW, tap anywhere on the screen and hold until the cow has been abducted. You are awarded one point for every cow you abduct. There is no ending to the game. Every time you abduct a cow, a new one will be created and placed on the grass Now that you understand how the game is played, you can take a look at the source code that powers the game engine

...展开详情
试读 127P Beginning iOS Social Games
立即下载 身份认证后 购VIP低至7折
一个资源只可评论一次,评论内容不能少于5个字
您会向同学/朋友/同事推荐我们的CSDN下载吗?
谢谢参与!您的真实评价是我们改进的动力~
  • 分享王者

关注 私信
上传资源赚钱or赚积分
最新推荐
Beginning iOS Social Games 10积分/C币 立即下载
1/127
Beginning iOS Social Games第1页
Beginning iOS Social Games第2页
Beginning iOS Social Games第3页
Beginning iOS Social Games第4页
Beginning iOS Social Games第5页
Beginning iOS Social Games第6页
Beginning iOS Social Games第7页
Beginning iOS Social Games第8页
Beginning iOS Social Games第9页
Beginning iOS Social Games第10页
Beginning iOS Social Games第11页
Beginning iOS Social Games第12页
Beginning iOS Social Games第13页
Beginning iOS Social Games第14页
Beginning iOS Social Games第15页
Beginning iOS Social Games第16页
Beginning iOS Social Games第17页
Beginning iOS Social Games第18页
Beginning iOS Social Games第19页
Beginning iOS Social Games第20页

试读结束, 可继续阅读

10积分/C币 立即下载