iOS Swift Game Development Cookbook Development CookbookDevelopment Game Swift iOS Ready to make amazing games for the iPhone, iPad, and iPod touch? With “From design principles Apple’s Swift programming language, it’s never been easier. This updated for game engines to cookbook provides detailed recipes for managing a wide range of common iOS game development issues, ranging from 2D and 3D math to Sprite Kit the practical details of and OpenGL to performance—all revised for Swift. working with iOS, this You get simple, direct solutions to common problems found in iOS game book is an invaluable programming. Need to figure out how to give objects physical motion, or resource for any want a refresher on gaming-related math problems? This book provides developer who wants to sample projects and straightforward answers. All you need to get started is some familiarity with iOS development, Swift, and Objective-C. make outstanding iOS games.” ■ Design the architecture and code layout of your game —Jonathan Adamczewski engine programmer, Insomniac Games ■ Build and customize menus with UIKit ■ Detect and respond to user input ■ Use techniques to play sound effects and music ■ Learn different ways to store information for later use ■ Create 2D graphics with Sprite Kit ■ Create 3D graphics with Scene Kit ■ Add two-dimensional physics simulation ■ Learn beginning, intermediate, and advanced 3D graphics with OpenGL iOS Swift Game ■ Create challenges with artificial intelligence ■ Take advantage of game controllers and external displays Buttfield-Addison Jonathon Manning is a game designer and programmer who’s worked on projects Development ranging from iPad games for children to instant messaging clients. Paris Buttfield-Addison is a mobile app engineer, game designer, and researcher with a passion for making technology simpler and as engaging as possible. Manning & Jonathon Manning and Paris Buttfield-Addison are cofounders of Secret Lab, C o o k b o o k an independent game development studio based in Tasmania, Australia. SIMPLE SOLUTIONS FOR GAME DEVELOPMENT PROBLEMS GAMES/IOS Twitter: @oreillymedia facebook.com/oreilly US $49.99 CAN $57.99 ISBN: 978-1-491-92080-0 Jonathon Manning & Paris Buttfield-Addison www.allitebooks.com iOS Swift Game Development Cookbook Development CookbookDevelopment Game Swift iOS Ready to make amazing games for the iPhone, iPad, and iPod touch? With “From design principles Apple’s Swift programming language, it’s never been easier. This updated for game engines to cookbook provides detailed recipes for managing a wide range of common iOS game development issues, ranging from 2D and 3D math to Sprite Kit the practical details of and OpenGL to performance—all revised for Swift. working with iOS, this You get simple, direct solutions to common problems found in iOS game book is an invaluable programming. Need to figure out how to give objects physical motion, or resource for any want a refresher on gaming-related math problems? This book provides developer who wants to sample projects and straightforward answers. All you need to get started is some familiarity with iOS development, Swift, and Objective-C. make outstanding iOS games.” ■ Design the architecture and code layout of your game —Jonathan Adamczewski engine programmer, Insomniac Games ■ Build and customize menus with UIKit ■ Detect and respond to user input ■ Use techniques to play sound effects and music ■ Learn different ways to store information for later use ■ Create 2D graphics with Sprite Kit ■ Create 3D graphics with Scene Kit ■ Add two-dimensional physics simulation ■ Learn beginning, intermediate, and advanced 3D graphics with OpenGL iOS Swift Game ■ Create challenges with artificial intelligence ■ Take advantage of game controllers and external displays Buttfield-Addison Jonathon Manning is a game designer and programmer who’s worked on projects Development ranging from iPad games for children to instant messaging clients. Paris Buttfield-Addison is a mobile app engineer, game designer, and researcher with a passion for making technology simpler and as engaging as possible. Manning & Jonathon Manning and Paris Buttfield-Addison are cofounders of Secret Lab, C o o k b o o k an independent game development studio based in Tasmania, Australia. SIMPLE SOLUTIONS FOR GAME DEVELOPMENT PROBLEMS GAMES/IOS Twitter: @oreillymedia facebook.com/oreilly US $49.99 CAN $57.99 ISBN: 978-1-491-92080-0 Jonathon Manning & Paris Buttfield-Addison www.allitebooks.com SECOND EDITION iOS Swift Game Development Cookbook Jonathon Manning and Paris Buttfield-Addison www.allitebooks.com iOS Swift Game Development Cookbook, Second Edition by Jonathon Manning and Paris Buttfield-Addison Copyright © 2015 Secret Lab. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or [email protected]. Editor: Rachel Roumeliotis Indexer: WordCo Indexing Services, Inc. Production Editor: Matthew Hacker Cover Designer: Karen Montgomery Copyeditor: Kim Cofer Interior Designer: David Futato Proofreader: Rachel Monaghan Illustrator: Rebecca Demarest April 2014: First Edition May 2015: Second Edition Revision History for the Second Edition: 2015-05-07: First release See http://oreilly.com/catalog/errata.csp?isbn=9781491920800 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. iOS Swift Game Development Cook‐ book, the cover image of a queen triggerfish, and related trade dress are trademarks of O’Reilly Media, Inc. While the publisher and the authors have used good faith efforts to ensure that the information and in‐ structions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. ISBN: 978-1-491-92080-0 [LSI] www.allitebooks.com Table of Contents Preface. ix 1. Laying Out a Game. 1 1.1. Laying Out Your Engine 1 1.2. Creating an Inheritance-Based Game Layout 2 1.3. Creating a Component-Based Game Layout 4 1.4. Calculating Delta Times 7 1.5. Detecting When the User Enters and Exits Your Game 9 1.6. Updating Based on a Timer 11 1.7. Updating Based on When the Screen Updates 11 1.8. Pausing a Game 13 1.9. Calculating Time Elapsed Since the Game Start 14 1.10. Working with Closures 15 1.11. Writing a Method That Calls a Closure 17 1.12. Working with Operation Queues 18 1.13. Performing a Task in the Future 19 1.14. Making Operations Depend on Each Other 21 1.15. Filtering an Array with Closures 22 1.16. Loading New Assets During Gameplay 22 1.17. Adding Unit Tests to Your Game 24 1.18. 2D Grids 26 2. Views and Menus. 31 2.1. Working with Storyboards 32 2.2. Creating View Controllers 38 2.3. Using Segues to Move Between Screens 45 2.4. Using Constraints to Lay Out Views 49 2.5. Adding Images to Your Project 51 2.6. Slicing Images for Use in Buttons 53 iii www.allitebooks.com 2.7. Using UI Dynamics to Make Animated Views 55 2.8. Moving an Image with Core Animation 56 2.9. Rotating an Image 58 2.10. Animating a Popping Effect on a View 60 2.11. Theming UI Elements with UIAppearance 62 2.12. Rotating a UIView in 3D 63 2.13. Overlaying Menus on Top of Game Content 65 2.14. Designing Effective Game Menus 66 3. Input. 67 3.1. Detecting When a View Is Touched 68 3.2. Responding to Tap Gestures 69 3.3. Dragging an Image Around the Screen 70 3.4. Detecting Rotation Gestures 72 3.5. Detecting Pinching Gestures 75 3.6. Creating Custom Gestures 76 3.7. Receiving Touches in Custom Areas of a View 80 3.8. Detecting Shakes 81 3.9. Detecting Device Tilt 83 3.10. Getting the Compass Heading 85 3.11. Accessing the User’s Location 87 3.12. Calculating the User’s Speed 90 3.13. Pinpointing the User’s Proximity to Landmarks 91 3.14. Receiving Notifications When the User Changes Location 92 3.15. Looking Up GPS Coordinates for a Street Address 95 3.16. Looking Up Street Addresses from the User’s Location 97 3.17. Using the Device as a Steering Wheel 98 3.18. Detecting Magnets 99 3.19. Utilizing Inputs to Improve Game Design 101 4. Sound. 103 4.1. Playing Sound with AVAudioPlayer 103 4.2. Recording Sound with AVAudioRecorder 106 4.3. Working with Multiple Audio Players 108 4.4. Cross-Fading Between Tracks 109 4.5. Synthesizing Speech 111 4.6. Getting Information About What the Music App Is Playing 113 4.7. Detecting When the Currently Playing Track Changes 114 4.8. Controlling Music Playback 116 4.9. Allowing the User to Select Music 117 4.10. Cooperating with Other Applications’ Audio 119 4.11. Determining How to Best Use Sound in Your Game Design 121 iv | Table of Contents www.allitebooks.com 5. Data Storage. 123 5.1. Saving the State of Your Game 123 5.2. Storing High Scores Locally 126 5.3. Using iCloud to Save Games 128 5.4. Using the iCloud Key-Value Store 132 5.5. Loading Structured Information 134 5.6.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages405 Page
-
File Size-