Apple Game Frameworks and Technologies
Build 2D Games with SpriteKit & Swift
by Tammy Coron
Design and develop sophisticated 2D games that are as much fun to make
as they are to play. From particle effects and pathfinding to social
integration and monetization, this complete tour of Apple’s powerful
suite of game technologies covers it all. Familiar with Swift but new to
game development? No problem. Start with the basics and then layer in
the complexity as you work your way through three exciting—and fully
playable—games. In the end, you’ll know everything you need to go off
and create your own video game masterpiece for any Apple platform.
Printed in full color.
Discover the power of Apple Game Frameworks, Xcode, and Swift by
building three exciting games: Gloop Drop—a new twist on a classic
arcade game, Val’s Revenge—a roguelike dungeon crawler, and Hog—a
social player vs. player mobile dice game. With Apple Game Frameworks,
you can create high-performance, power-efficient games that work across
all Apple platforms, including iOS, macOS, tvOS, and watchOS.
In this book, you’ll discover how to…
Design and develop rich 2D gaming experiences using Apple’s built-in
game frameworks. Harness the power of SpriteKit using Xcode and Swift to
create engaging player experiences. Use the visual Scene Editor to build
complete scenes. Unleash the power of the Particle Editor to create
amazing effects. Use GameplayKit to add advanced features to your games
like pathfinding, artificial intelligence, and complex rule systems.
Build larger, more complex worlds with tile maps and Xcode’s visual Tile
Map editor. Bring people together using GameKit and Game Center, Apple’s
social gaming network. Increase revenue with third-party banner ads and
rewarded ads using Google AdMob™. Monetize your games with StoreKit and
in-app purchases.
So, grab your gear and get your game on—it’s time to level up your
skills.
What You Need
To follow along with the examples in this book, readers will need:
- macOS Mojave 10.14.6 or newer
- Xcode 11.3 or newer
- Basic knowledge of Swift 5.1.4 or newer
Resources
Releases:
- P1.0 2021/04/21
- B10.0 2021/03/21
- B9.0 2021/01/12
- B8.0 2020/12/02
Preface
- Build Your First Game with SpriteKit
- Creating Scenes with Sprites and Nodes
- Create the Project
- Explore the Default Template
- Clean Up the Default Template
- Set the Supported Device Orientation
- Create Your First SpriteKit Scene
- Create Your First Sprite Node
- Set Position, Coordinates, and Anchor Points
- Add the Foreground
- Next Steps
- Adding Animation and Movement with Actions
- Animation in SpriteKit
- Add the Images Resources for the Player
- Create the Player Class
- Load the Textures
excerpt
- Control Render Order with Z-Position
- Animate the Player with Actions
- Use the Animation Extension
- Move the Player with Actions
- Use Constraints to Limit Movement
- Set the Player’s Direction Using Scales
- Keep the Player’s Speed Consistent
- Next Steps
- Chaining Actions and Using Iterative Design
- Add Your First Collectible Item
- Improve Code with Iterative and Incremental Development
- Chain Actions Together to Create a Sequence
- Use Actions to Run Code Blocks
- Use Level Data to Add Challenging Gameplay
- Use Iterative Design to Adjust the Player’s Movement
- Next Steps
- Working with Physics and Collision Detection
excerpt
- Run a Playground Physics Simulation
- A Closer Look at Physics Bodies
- Use Physics Bodies for Collision Detection
- Configure Physics Categories
- Handle Contact Between Physics Bodies
- Next Steps
- Adding Labels and Working with the Game Loop
- Add Labels to Show Current Level and Score
- Use Variables to Monitor Game States
- Use the Game Loop to Apply Game Logic
- Use Attributed Strings with Labels
- Next Steps
- Juicing Your Games with Sound and Effects
- Add Sound Effects
- Add Background Music
- Build More Robust Sound Systems
- Create an Endless Scrolling Background
excerpt
- Juice Your Game with Particles
- Handle Hit-Testing and Touch Events
- Squeeze Out a Little More Juice
- Challenge Project
- Next Steps
- Use the Scene Editor to Build Games
- Building Scenes with the Scene Editor
- Create the Project
- Clean Up the Default Template
- Add the Assets
- Add Nodes Using the Object Library
- Configure the View and Load the Scene
- Next Steps
- Using the Scene Editor to Add Physics
- Write Code to Interface with the Scene
- Add Physics to the Player
- Move the Player Using Physics
- Connect the Attack Button
- Next Steps
- Operating the Camera and Using References Nodes
- Add a Camera to Track the Player
- Use Reference Nodes in Your Scene
- Add Support for All Devices and Orientations
- Resize the Player Node on Device Rotation
- Lock the Location of the On-Screen Controls
- Refactor the Code and Clean Up the Project
- Next Steps
- Extending Your Game World with Tile Maps
- Create a Bigger World with Tile Map Nodes
- Create a Tile Map Node
- Use the Tile Map Editor
- Add a Dungeon Tile Map
- Animating Tiles
- Configure Physics Bodies Using User Data
- Next Steps
- Scale Your Games with GameplayKit
- Building Games with Entities and Components
- Organize the Project
- Add the Resources
- Create Your First Component
- Create Your First Entity
- Build a Monster Generator
- Animate the Monsters
- Next Steps
- Using States and State Machines
- Create the Player States
- Set Up the Player State Machine
- Add a New Collectible Component
- Configure the Physics Bodies
- Add a Physics Contact Extension
- Place Collectibles and Doors
- Add Code to Destroy Collectibles
- Next Steps
- Planning Routes and Creating Believable AI
- Modify the Monster Generator
- Use Agents, Goals, and Behaviors
- Add Agents to Monsters
- Add an Agent to the Player
- Use Multiple Goals
- Add the Player Agent to the Component System
- Add the Monster Entities to the Scene’s Entities Array
- Update Physics for Monsters and Projectiles
- Build a Better Health Component
- Add Pathfinding to Your Game
- Next Steps
- Enhance the Player’s Experience
- Using the Action Editor and Enhancing Gameplay
- Use the Action Editor to Add Actions
- Add the Player’s Heads-Up Display
- Build Better On-Screen Controls
- Next Steps
- Adding More Scenes and Saving the Game
- Add New Scenes
- Present the Title Scene
- Load the First Game Scene
- Present the Game Over Scene
- Save and Load Game Data
- Exit the Map and Load the Next Scene
- Create Additional Game Scenes
- Support 3D Spatial Audio Effects
- Next Steps
- Build Social Games with GameKit
- Adding Leaderboards and Achievements
- Add Game Center Capability Using Xcode
- Use App Store Connect to Add a New App
- Add a Leaderboard
- Add an Achievement
- Create the Game Center Helper
- Show the Game Center Dashboard
- Report Score to Leaderboard
- Report Achievement
- Next Steps
- Creating Multiplayer Games with GameKit
- Request a Turn-Based Match
- Manage Multiplayer Matches
- Process Player Turns Using an Event Listener
- Use Custom Match Data in Multiplayer Games
- Update the Game Scene to Send the Match Data
- Use Multiple Devices or Simulators for Testing
- Next Steps
- Bonus Content: Monetize Your Games
- Using Ads to Increase Revenue
- Sign up for AdMob and Register Your App
- Create Ad Units
- Download and Integrate the Google Mobile Ads SDK
- Add the AdMob Helper File
- Use the AdMob Helper for Banner Ads
- Add the Continue Game Feature (Player Reward)
- Use the AdMob Helper for Rewarded Ads
- Create Custom Notifications
- Save and Load the Number of Continues
- Next Steps
- Monetizing Your Games with In-App Purchases
- Add In-App Purchase Capability Using Xcode
- Use App Store Connect to Add a New App
- Add In-App Purchase Support to the Project
- Configure Products in Xcode
- Modify the GameData Class to Store Purchases
- Modify the AdMob Helper to Disable Ads
- Modify the GameScene Class to Handle Paid Continues
- Configure the Shop Scene
- Add the Shop Scene to the Main Game Scene
- Interface with StoreKit Using the Store Manager
- Test In-App Purchases
- Next Steps
Author
Tammy Coron is an independent creative professional and the maker
behind the AdventureGameKit, a custom SpriteKit framework for building
point and click adventure games. As an author, editor, illustrator, and
indie game developer, Tammy spends her time creating content and
teaching others. For more information about Tammy, visit her website at
tammycoron.com.