Time for action – retrieving data from the .plist file
The level data is loaded in GameLayer
.
- Inside the
GameLayer
constructor, we load the data like this:_levels = FileUtils::getInstance()- >getValueVectorFromFile("levels.plist");
Cocos2d-x will take care of mapping
FileUtils
to the correct target. There isFileUtils
for each platform that is supported by the framework and they all can be made to work with the.plist
format. Sweet! If the data in the.plist
file is an Array, you must convert it toValueVector
; if it's Dictionary, you must convert it to aValueMap
. We'll do that next when we load the data for a specific level.Note
If we divide the levels into multiple
.plist
files, then we would need logic to refresh the_levels
array each time a new.plist
file is loaded. - Inside the
loadLevel
method, we load the data for the level like this:ValueMap levelData = _levels.at(_currentLevel).asValueMap();
Here, the data in the
.plist
file is Dictionary, so we must convert...