我们都知道在cocos2dx中关于字符串有很多处理方法,那么就cocos2dx如何拼接字符串你又知道多少呢?现在我们就来学习cocos2dx如何拼接字符串
  1. for(int i=1;i<5;i++){
  2. char str[3];
  3. sprintf(str,"%d",i);
  4. char totalFilename[30];
  5. strcpy(totalFilename, "game_loading") ;
  6. const char* suffix = ".png";
  7. strcat(totalFilename, str);
  8. strcat(totalFilename, suffix);
  9. log(totalFilename);
  10. animation->setDelayPerUnit(0.2f);
  11. log("%d",sizeof(str[0]));
  12. char t = 'q';
  13. log("char %d",sizeof(t));
  14. float a = 10.30;
  15. log("t %d",sizeof(&a));
  16. animation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(totalFilename));
  17. }

读取XML
  1. Dictionary* dic = Dictionary::createWithContentsOfFile("chineseString.xml");
  2. String* strchinese   =   (String*)dic->objectForKey("startGame");
  3. <?xml version="1.0" encoding="utf-8"?>
  4. <plist version="1.0">
  5. <dict>
  6. <key>startGame</key>
  7. <string>从XML里面读取的东东</string>
  8. <key>japanese</key>
  9. <string>地方</string>
  10. </dict>
  11. </plist>

创建动画Animation
  1. Animation* HelloWorld::getAnimation(const char* stts[],int l,float delay){
  2. Animation* ac = Animation::create();
  3. ac->setDelayPerUnit(delay);
  4. for(int i=0;i<l;i++){
  5. ac->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(stts[i]));
  6. }
  7. return ac;
  8. }
  9. Animation* HelloWorld::getAnimation(const std::string stts[],int l,float delay){
  10. Animation* ac = Animation::create();
  11. ac->setDelayPerUnit(delay);
  12. for(int i=0;i<l;i++){
  13. ac->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(stts[i]));
  14. }
  15. return ac;
  16. }