Book Image

Game Development with Swift

By : Stephen Haney
Book Image

Game Development with Swift

By: Stephen Haney

Overview of this book

Table of Contents (18 chapters)
Game Development with Swift
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 very 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 world, then slowly pushing the backgrounds to the right as the world moves left. As the world moves to the left (bringing the backgrounds with it), we will move the background's x position to the right so that the total movement is less than for the normal game objects. 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 3000 points wide, but will jump forward at precise intervals to loop seamlessly, in a similar way to the...