iOS Swift Game Development Cookbook, 3rd Edition

Book description

Ready to make amazing games for the iPhone and iPad? With Apple’s Swift programming language, it’s never been easier. This updated cookbook provides detailed recipes for managing a wide range of common iOS game-development issues, ranging from 2D and 3D math, SpriteKit, and OpenGL to augmented reality with ARKit.

You get simple, direct solutions to common problems found in iOS game programming. Need to figure out how to give objects physical motion, or want a refresher on gaming-related math problems? This book provides sample projects and straightforward answers. All you need to get started is some familiarity with iOS development in Swift.

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Audience
    2. Organization of This Book
    3. Additional Resources
    4. Conventions Used in This Book
    5. Using Code Examples
    6. O’Reilly Safari
    7. How to Contact Us
    8. Acknowledgments
  2. Laying Out a Game
    1. 1.1. Laying Out Your Engine
    2. 1.2. Creating an Inheritance-Based Game Layout
    3. 1.3. Creating a Component-Based Game Layout
    4. 1.4. Creating a Component-Based Game Layout Using GameplayKit
    5. 1.5. Calculating Delta Times
    6. 1.6. Detecting When the User Enters and Exits Your Game
    7. 1.7. Updating Based on a Timer
    8. 1.8. Updating Based on When the Screen Updates
    9. 1.9. Pausing a Game
    10. 1.10. Calculating Time Elapsed Since the Game Start
    11. 1.11. Working with Closures
    12. 1.12. Writing a Method That Calls a Closure
    13. 1.13. Working with Operation Queues
    14. 1.14. Performing a Task in the Future
    15. 1.15. Making Operations Depend on Each Other
    16. 1.16. Filtering an Array with Closures
    17. 1.17. Loading New Assets During Gameplay
    18. 1.18. Adding Unit Tests to Your Game
    19. 1.19. 2D Grids
    20. 1.20. Using Randomization
    21. 1.21. Building a State Machine
  3. Views and Menus
    1. 2.1. Working with Storyboards
    2. 2.2. Creating View Controllers
    3. 2.3. Using Segues to Move Between Screens
    4. 2.4. Using Constraints to Lay Out Views
    5. 2.5. Adding Images to Your Project
    6. 2.6. Slicing Images for Use in Buttons
    7. 2.7. Using UI Dynamics to Make Animated Views
    8. 2.8. Moving an Image with Core Animation
    9. 2.9. Rotating an Image View
    10. 2.10. Animating a Popping Effect on a View
    11. 2.11. Theming UI Elements with UIAppearance
    12. 2.12. Rotating a UIView in 3D
    13. 2.13. Overlaying Menus on Top of Game Content
    14. 2.14. Designing Effective Game Menus
  4. Input
    1. 3.1. Detecting When a View Is Touched
    2. 3.2. Responding to Tap Gestures
    3. 3.3. Dragging an Image Around the Screen
    4. 3.4. Detecting Rotation Gestures
    5. 3.5. Detecting Pinching Gestures
    6. 3.6. Creating Custom Gestures
    7. 3.7. Receiving Touches in Custom Areas of a View
    8. 3.8. Detecting Shakes
    9. 3.9. Detecting Device Tilt
    10. 3.10. Getting the Compass Heading
    11. 3.11. Accessing the User’s Location
    12. 3.12. Calculating the User’s Speed
    13. 3.13. Pinpointing the User’s Proximity to Landmarks
    14. 3.14. Receiving Notifications When the User Changes Location
    15. 3.15. Looking Up GPS Coordinates for a Street Address
    16. 3.16. Looking Up Street Addresses from the User’s Location
    17. 3.17. Using the Device as a Steering Wheel
    18. 3.18. Detecting Magnets
    19. 3.19. Utilizing Inputs to Improve Game Design
  5. Sound
    1. 4.1. Playing Sound with AVAudioPlayer
    2. 4.2. Recording Sound with AVAudioRecorder
    3. 4.3. Working with Multiple Audio Players
    4. 4.4. Cross-Fading Between Tracks
    5. 4.5. Synthesizing Speech
    6. 4.6. Getting Information About What the Music App Is Playing
    7. 4.7. Detecting When the Currently Playing Track Changes
    8. 4.8. Controlling Music Playback
    9. 4.9. Allowing the User to Select Music
    10. 4.10. Cooperating with Other Applications’ Audio
    11. 4.11. Determining How to Best Use Sound in Your Game Design
  6. Data Storage
    1. 5.1. Storing Structured Information
    2. 5.2. Storing Data Locally
    3. 5.3. Using iCloud to Save Games
    4. 5.4. Using the iCloud Key-Value Store
    5. 5.5. Deciding When to Use Files or a Database
    6. 5.6. Managing a Collection of Assets
    7. 5.7. Storing Information in UserDefaults
    8. 5.8. Implementing the Best Data Storage Strategy
    9. 5.9. In-Game Currency
    10. 5.10. Setting Up CloudKit
    11. 5.11. Adding Records to a CloudKit Database
    12. 5.12. Querying Records to a CloudKit Database
    13. 5.13. Deleting Records from a CloudKit Database
  7. 2D Graphics and SpriteKit
    1. 6.1. Getting Familiar with 2D Math
    2. 6.2. Creating a SpriteKit View
    3. 6.3. Creating a Scene
    4. 6.4. Adding a Sprite
    5. 6.5. Adding a Text Sprite
    6. 6.6. Determining Available Fonts
    7. 6.7. Including Custom Fonts
    8. 6.8. Transitioning Between Scenes
    9. 6.9. Moving Sprites and Labels Around
    10. 6.10. Adding a Texture Sprite
    11. 6.11. Creating Texture Atlases
    12. 6.12. Using Shape Nodes
    13. 6.13. Using Blending Modes
    14. 6.14. Using Image Effects to Change the Way That Sprites Are Drawn
    15. 6.15. Using Bézier Paths
    16. 6.16. Creating Smoke, Fire, and Other Particle Effects
    17. 6.17. Shaking the Screen
    18. 6.18. Animating a Sprite
    19. 6.19. Parallax Scrolling
    20. 6.20. Creating Images Using Noise
  8. Physics
    1. 7.1. Reviewing Physics Terms and Definitions
    2. 7.2. Adding Physics to Sprites
    3. 7.3. Creating Static and Dynamic Objects
    4. 7.4. Defining Collider Shapes
    5. 7.5. Setting Velocities
    6. 7.6. Working with Mass, Size, and Density
    7. 7.7. Creating Walls in Your Scene
    8. 7.8. Controlling Gravity
    9. 7.9. Keeping Objects from Falling Over
    10. 7.10. Controlling Time in Your Physics Simulation
    11. 7.11. Detecting Collisions
    12. 7.12. Finding Objects
    13. 7.13. Working with Joints
    14. 7.14. Working with Forces
    15. 7.15. Adding Thrusters to Objects
    16. 7.16. Creating Explosions
    17. 7.17. Using Device Orientation to Control Gravity
    18. 7.18. Dragging Objects Around
    19. 7.19. Creating a Car
  9. SceneKit
    1. 8.1. Setting Up for SceneKit
    2. 8.2. Creating a SceneKit Scene
    3. 8.3. Showing a 3D Object
    4. 8.4. Working with SceneKit Cameras
    5. 8.5. Creating Lights
    6. 8.6. Animating Objects
    7. 8.7. Working with Text Nodes
    8. 8.8. Customizing Materials
    9. 8.9. Texturing Objects
    10. 8.10. Normal Mapping
    11. 8.11. Constraining Objects
    12. 8.12. Loading COLLADA Files
    13. 8.13. Using 3D Physics
    14. 8.14. Adding Reflections
    15. 8.15. Hit-Testing the Scene
    16. 8.16. Loading a Scene File
    17. 8.17. Particle Systems
    18. 8.18. Using Metal
  10. Artificial Intelligence and Behavior
    1. 9.1. Making Vector Math Nicer in Swift
    2. 9.2. Making an Object Move Toward a Position
    3. 9.3. Making Things Follow a Path
    4. 9.4. Making an Object Intercept a Moving Target
    5. 9.5. Making an Object Flee When It’s in Trouble
    6. 9.6. Making an Object Decide on a Target
    7. 9.7. Making an Object Steer Toward a Point
    8. 9.8. Making an Object Know Where to Take Cover
    9. 9.9. Calculating a Path for an Object to Take
    10. 9.10. Pathfinding on a Grid
    11. 9.11. Finding the Next Best Move for a Puzzle Game
    12. 9.12. Determining If an Object Can See Another Object
    13. 9.13. Tagging Parts of Speech with NSLinguisticTagger
    14. 9.14. Using AVFoundation to Access the Camera
    15. 9.15. Importing a Core ML Model
    16. 9.16. Identifying Objects in Images
    17. 9.17. Using AI to Enhance Your Game Design
  11. Working with the Outside World
    1. 10.1. Detecting Controllers
    2. 10.2. Getting Input from a Game Controller
    3. 10.3. Showing Content via AirPlay
    4. 10.4. Using External Screens
    5. 10.5. Designing Effective Graphics for Different Screens
    6. 10.6. Dragging and Dropping
    7. 10.7. Providing Haptic Feedback with UIFeedbackGenerator
    8. 10.8. Recording the Screen with ReplayKit
    9. 10.9. Displaying Augmented Reality with ARKit
    10. 10.10. Hit-Testing the AR Scene
    11. 10.11. Using TestFlight to Test Your App
    12. 10.12. Using Fastlane to Build and Release Your App
  12. Performance and Debugging
    1. 11.1. Improving Your Frame Rate
    2. 11.2. Making Levels Load Quickly
    3. 11.3. Dealing with Low-Memory Issues
    4. 11.4. Tracking Down a Crash
    5. 11.5. Working with Compressed Textures
    6. 11.6. Working with Watchpoints
    7. 11.7. Logging Effectively
    8. 11.8. Creating Breakpoints That Use Speech
  13. Index

Product information

  • Title: iOS Swift Game Development Cookbook, 3rd Edition
  • Author(s): Jonathon Manning, Paris Buttfield-Addison
  • Release date: October 2018
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491999035