学习札记之cocos2d-x2.1.1实现读取.plist文件(使用数组CCArray)





[html]​view plain​ ​​​copy​​​​print​​​​?​​​
​​


  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
  3. <plist version="1.0">  
  4. <dict>  
  5.         <key>picture</key>  
  6.         <array>  
  7.             <string>1.png</string>  
  8.             <string>2.png</string>  
  9.             <string>3.png</string>        
  10.         </array>  
  11.         <key>point</key>  
  12.         <array>  
  13.             <string>{200,300}</string>  
  14.             <string>{500,300}</string>  
  15.             <string>{800,300}</string>  
  16.         </array>  
  17. </dict>  
  18. </plist>  




[cpp]​view plain​ ​​​copy​​​​print​​​​?​


​​


  1. //////////////////////////////////////////////////////////////////////////  
  2. //SmallTools2  
  3.        CCDictionary* plistDic = CCDictionary::createWithContentsOfFile("SmallTools2.plist");  
  4. CCArray* picture_array = (CCArray*)plistDic->objectForKey("picture");  
  5. CCArray* point_array = (CCArray*)plistDic->objectForKey("point");  
  6. for (int i=0;i<picture_array->count();i++)  
  7. {  
  8.     CCString* pi_string = (CCString*)picture_array->objectAtIndex(i);  
  9.     CCSprite* sprite = CCSprite::create(pi_string->getCString());  
  10.     CCString* point_string = (CCString*)point_array->objectAtIndex(i);  
  11.     CCPoint point = CCPointFromString(point_string->getCString());  
  12.     sprite->setPosition(ccp(point.x,point.y));  
  13.     this->addChild(sprite,1,++TagCount);  
  14. }     
  15. //////////////////////////////////////////////////////////////////////////