Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17070

Reading xml / plist file coco2d-x 3.9

$
0
0

@Dobby90 wrote:

i have a plist file with level data in it for for game objects i am able to read in the file as a value my problem is i cant seem to be able to figure out how to read the different keys to get the value i want for the different objects.

this is my plist file. as you can see i have a key for "Blocks" and its values and "Enemies" and their values

<?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">  
<array>
<dict>
	<key>blocks</key>
	<array>
		<dict>
			<key>x</key>
			<real>100</real>
			<key>y</key>
			<real>600</real>
		</dict>
		<dict>
			<key>x</key>
			<real>300</real>
			<key>y</key>
			<real>20</real>
		</dict>
		<dict>
			<key>x</key>
			<real>0</real>
			<key>y</key>
			<real>1</real>
		</dict>
	</array>
	<key>enemies</key>
	<array>
		<dict>
			<key>lane</key>
			<real>0</real>
			<key>speed</key>
			<real>4</real>
		</dict>
		<dict>
			<key>lane</key>
			<real>1</real>
			<key>speed</key>
			<real>1</real>
		</dict>
		<dict>
			<key>lane</key>
			<real>2</real>
			<key>speed</key>
			<real>9</real>
		</dict>
		<dict>
			<key>lane</key>
			<real>0</real>
			<key>speed</key>
			<real>2</real>
		</dict>
	</array>
</dict>
 </array>
</plist>

and to read this in i am using

std::string levelsFile = FileUtils::getInstance()->fullPathForFilename("../../Resources/levels.plist");

ValueVector m_levels = FileUtils::getInstance()->getValueVectorFromFile(levelsFile);

for (auto levelData : m_levels){
    auto data = levelData.asValueMap();

    log("The description of the string value : %s", levelData.getDescription().c_str());


    block.at(i)->create(Vec2(
        ladderdata["x"].asInt(),
	ladderdata["y"].asInt()
	), this);
}

Thanks in advance to any one that helps

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 17070

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>