cocococococos 2 d-読み取り・plistファイルを実現する(配列CCArayを使用する)

1655 ワード


ノートのcocococococos 2 d-x 2.1.1を学んで.plistファイルを読み取ることを実現します(配列CCArayを使います).
<?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>picture</key>
		<array>
			<string>1.png</string>
			<string>2.png</string>
			<string>3.png</string>		
		</array>
		<key>point</key>
		<array>
			<string>{200,300}</string>
			<string>{500,300}</string>
			<string>{800,300}</string>
		</array>
</dict>
</plist>
		//////////////////////////////////////////////////////////////////////////
		//SmallTools2
	        CCDictionary* plistDic = CCDictionary::createWithContentsOfFile("SmallTools2.plist");
		CCArray* picture_array = (CCArray*)plistDic->objectForKey("picture");
		CCArray* point_array = (CCArray*)plistDic->objectForKey("point");
		for (int i=0;i<picture_array->count();i++)
		{
			CCString* pi_string = (CCString*)picture_array->objectAtIndex(i);
			CCSprite* sprite = CCSprite::create(pi_string->getCString());
			CCString* point_string = (CCString*)point_array->objectAtIndex(i);
			CCPoint point = CCPointFromString(point_string->getCString());
			sprite->setPosition(ccp(point.x,point.y));
			this->addChild(sprite,1,++TagCount);
		}	
		//////////////////////////////////////////////////////////////////////////