cocos2dx 字符串拼接

for(int i=1;i<5;i++){
        char str[3];
        sprintf(str,"%d",i);

        char totalFilename[30]; 
        strcpy(totalFilename, "game_loading") ;
        const char* suffix = ".png";
        strcat(totalFilename, str);
        strcat(totalFilename, suffix);
        log(totalFilename);
        animation->setDelayPerUnit(0.2f);
        log("%d",sizeof(str[0]));

        char t = 'q';
        log("char %d",sizeof(t));

        float a = 10.30;

        log("t %d",sizeof(&a));
        
        animation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(totalFilename));
    }

 

讀取XML動畫

Dictionary* dic = Dictionary::createWithContentsOfFile("chineseString.xml");  
String* strchinese   =   (String*)dic->objectForKey("startGame");  



<?xml version="1.0" encoding="utf-8"?>
<plist version="1.0">

  <dict>


    <key>startGame</key>

    <string>從XML裏面讀取的東東</string>


    <key>japanese</key>

    <string>地方</string>
  </dict>
</plist>

 

 建立動畫Animationspa

Animation* HelloWorld::getAnimation(const char* stts[],int l,float delay){
    Animation* ac = Animation::create();
    ac->setDelayPerUnit(delay);
    for(int i=0;i<l;i++){
        ac->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(stts[i]));
    }
    return ac;
}


Animation* HelloWorld::getAnimation(const std::string stts[],int l,float delay){
    Animation* ac = Animation::create();
    ac->setDelayPerUnit(delay);
    for(int i=0;i<l;i++){
        ac->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(stts[i]));
    }
    return ac;
}
相關文章
相關標籤/搜索