Book Image

Cocos2d Game Development Blueprints

By : Jorge Jordán
Book Image

Cocos2d Game Development Blueprints

By: Jorge Jordán

Overview of this book

Table of Contents (15 chapters)
Cocos2d Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Loading data from external files


When loading the new scene, we are going to create the level using the information stored in an external file, in order to make our game independent.

The files used for this purpose are .plist files (also known as property list files) and they are commonly used to contain information to configure applications and games. Its contents have an XML structure and the root node is a dictionary where the children nodes are formed by a key-value sequence.

If we want to store custom objects in our .plist files, we just need to implement encodeWithCoder and initWithCoder, as we did in Chapter 3, Your First Online Game, to serialize the match data.

Xcode offers an easy way to create a new .plist file, which we are going to take advantage of to contain the information of our game.

Follow the next steps:

  1. Right-click on the Resources group in the project navigator and select New File….

  2. Click on iOS | Resource | Property List and click on Next.

  3. Call it levelsInfo.plist and click...