title: Getting Image From URL , Using curl in Cocos2dx C++
body: <p>I am using curl in C++ to get an Image from a URL for a Cocos2dx Game. 
  The Code is Working Fine. And using <code>CCImage</code> And <code>cocos2d::CCTexture2D</code> I create a <code>Sprite</code> and Add it on my Layer. </p>
  
  <p>The Sprite is definitely getting added on the Layer, (I Know it because if i try to Add the Same Sprite It is getting crashed Stating <code>Child already Added</code> But its is no where to be found on Layer. I tried changing the BG Color, ZIndex of Sprite But the sprite is not visible.</p>
  
  <p>here is the code:</p>
  
  <pre><code>void HelloWorld::getImageFromURL(const char* url)
  {
      CURL *curl;       // CURL objects
      CURLcode res;
      MemoryStruct buffer; // memory buffer
  
      curl = curl_easy_init(); // init CURL library object/structure
  
      if(curl) {
  
          // set up the write to memory buffer
          // (buffer starts off empty)
  
          buffer.memory = NULL;
          buffer.size = 0;
  
          stringstream urlString;
          urlString&lt;&lt;url;
          // (N.B. check this URL still works in browser in case image has moved)
  
          CCLog("%s", urlString.str().c_str());
  
          curl_easy_setopt(curl, CURLOPT_URL, urlString.str().c_str());
          curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); // tell us what is happening
  
          // tell libcurl where to write the image (to a dynamic memory buffer)
  
          curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION, Utility::WriteMemoryCallback);
          curl_easy_setopt(curl,CURLOPT_WRITEDATA, (void *) &amp;buffer);
  
          // get the image from the specified URL
  
          res = curl_easy_perform(curl);
          CCLog("Curl code: %i", res);
  
          CCImage* img = new CCImage();
          img-&gt;initWithImageData((void*)buffer.memory, (long)buffer.size, CCImage::kFmtPng);
          cocos2d::CCTexture2D* texture = new cocos2d::CCTexture2D(); //TODO:: leak
          texture-&gt;initWithImage(img);
  
  
          CCSprite* sprite = CCSprite::createWithTexture(texture, CCRectMake(0, 0, 256, 256));
          sprite-&gt;setPosition(CENTRE_OF_SCREEN);
          sprite-&gt;setContentSize(CCSize(256,256));
          sprite-&gt;setAnchorPoint(ccp(0, 0));
          this-&gt;addChild(sprite,1000,1000);
  
          curl_easy_cleanup(curl);
          free(buffer.memory);
  
  
      }
  
  }
  </code></pre>
  
  <p>Any Help will be Greatly Appreciated.</p>
  
  <p>Thanks a ton
  W</p>