How can I load a .tmx file that is on Internet or in documents folder instead of resources

Our level designer wants to be able to update the level without needing to recompile everytime.

So i’ve been asked to put the .tmx file in the documents folder on the appStore, so she can update the level and test the changes immediately.

Is there a way to do this?

Another ideal way would be to load it from an url…?

Thanks.

It would be nice to load the file via url. I can read from file using curl and store the file in a char* buffer.

Is there a way to init the CCTMXTiledMap with file data?

I know you can do it with a sprite:
initWithImageData((void*)readBuffer.c_str(), readBuffer.length(),CCImage::kFmtPng));

Woohoo got it to work

I managed to load the file from an url. Had to rename it to .txt instead of .tmx though.

Here’s how I got it to work if someone else is interested:

CURL *curl = NULL;
    CURLcode res;    
    std::string readBuffer;

    //Init curl
    curl = curl_easy_init();

    if(curl)
    {
        curl_easy_setopt(curl, CURLOPT_URL, "http://www.marcrenaud.com/_content/docs/docks3.txt");
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }

    //Get the size of the buffer
    int numCharacters = readBuffer.size();

    //Create an char array to hold the file contents
    char buffer[numCharacters];

    //Convert the string into an char array
    for (int i = 0; i <= numCharacters; i++)
    {
        buffer[i]=readBuffer[i];        
    }

    //Show file contents in log
    CCLog("%s", buffer);    

    //Load the CCTMXTiledmap via information from the internet
    CCTMXTiledMap* tiledMap = CCTMXTiledMap::createWithXML(buffer, "");
    this->addChild(tiledMap);

I got the WriteCallback function from another thread. It’s defined as such:

static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
    {
        ((std::string*)userp)->append((char*)contents, size * nmemb);
        return size * nmemb;
    }