Book Image

Learning iOS 8 Game Development Using Swift

By : Siddharth Shekar
Book Image

Learning iOS 8 Game Development Using Swift

By: Siddharth Shekar

Overview of this book

<p>Game development has been simplified with Apple's new programming language—Swift. If you're looking to start learning iOS development then you'll get everything you need - from&nbsp;the absolute basics such as the Xcode interface and takes you all the way to Swift programming.</p> <p>You will take a walk through the creation of 2D and 3D games followed by an introduction to SpriteKit and SceneKit. The book also looks at how game objects are placed in 3D scenes, how to use the graphics pipeline, and how objects are displayed on mobile screens. You will also delve into essential game concepts such as collision detection, animation, particle systems, and scene transitions. Finally, you will learn how to publish and distribute games to the iTunes store.</p>
Table of Contents (18 chapters)
Learning iOS 8 Game Development Using Swift
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Saving the high score


For saving the high scores, we can use the NSUserDefaults property. Here we can use a key and assign a particular value to it which the device will store in its memory, so that we can retrieve later. The best thing about this is, we can retrieve and rewrite the value stored in it currently, to some other file. So, here we will store the high score in GamePlayScene and later the value stored in the key, in the MainMenuScene.

Since it is a dictionary, you can store integer, floats, and string. In this case, since the high score will always be an integer, we will get and store an integer for the key. The key here is a string and the value that is stored is an integer.

For retrieving the high score value, add the following code after we added menuBtn in the GameOver function:

var currentHighScore = NSUserDefaults.standardUserDefaults().integerForKey("tinyBazooka_highscore")

Since no value is stored currently in the key, it will return zero.

For congratulating the players on...