Book Image

Swift 3 Game Development - Second Edition

By : Stephen Haney
Book Image

Swift 3 Game Development - Second Edition

By: Stephen Haney

Overview of this book

Swift is the perfect choice for game development. Developers are intrigued by Swift 3.0 and want to make use of new features to develop their best games yet. Packed with best practices and easy-to-use examples, this book leads you step by step through the development of your first Swift game. This book starts by introducing SpriteKit and Swift's new features that can be used for game development. After setting up your first Swift project, you will build your first custom class, learn how to draw and animate your game, and add physics simulations. Then, you will add the player character, NPCs, and powerups. To make your game more fun and engaging, you will learn how to set up scenes and backgrounds, build fun menus, and integrate with Apple Game Center to add leaderboards and achievements. You will then make your game stand out by adding animations when game objects collide, and incorporate proven techniques such as the advanced particle system and graphics. Finally, you will explore the various options available to start down the path towards monetization and publish your finished games to the App Store. By the end of this book, you will be able to create your own iOS games using Swift and SpriteKit.
Table of Contents (20 chapters)
Swift 3 Game Development - Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Parallax background layers


Parallax adds the feeling of depth to your game by drawing separate background layers and moving them past the camera at varying speeds. Very slow backgrounds give the illusion of distance, while fast moving backgrounds appear to be close to the player. We can enhance the effect by painting faraway objects with increasingly desaturated colors.

In our game, we will achieve the parallax effect by attaching our backgrounds to the scene, then slowly pushing the backgrounds to the right as the camera pans right. As the camera moves to the right (making the children of the scene appear to move left), we will move the background's x position to the right, so that the total background node movement is less than for the other children of the scene. The result will be background layers that appear to move more slowly than the rest of our game, and thus appear farther away.

In addition, each background will only be 3,072 points wide, but will jump forward at precise intervals...