Book Image

Cocos2d-x Cookbook

By : Akihiro Matsuura
Book Image

Cocos2d-x Cookbook

By: Akihiro Matsuura

Overview of this book

Table of Contents (18 chapters)
Cocos2d-x Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using .plist files


PLIST used in OS X and iOS is a property list. The file extension is .plist, but in fact, the PLIST format is an XML format. We often use .plist files to store game settings and so on. Cocos2d-x has a class through which you can easily use .plist files.

Getting ready

Firstly, you need to create a .plist file and save it as test.plist to the Resources/res folder in your project. In this case, it has two keys, namely foo and bar. The foo key has an integer value of 1. The bar key has a string value of This is string. Refer to the following code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>foo</key>
  <integer>1</integer>
  <key>bar</key>
  <string>This is string</string>
</dict>
</plist>

How to do it...

You can parse a .plist file by using the FileUtils::getValueMapFromFile...