Cocos2d-x 2.1.4 里面已经为我们提供了HttpRequest ,HttpClient,CCHttpResponse用于处理网络相关操作
下面简单利用这些封装好的类,来读取网络图片并创建精灵
1.在工程里面导入HttpRequest.h,HttpClient.h
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
#include "HttpRequest.h"
#include "HttpClient.h"
USING_NS_CC;
USING_NS_CC_EXT;
using namespace std;
CCScene* HelloWorld::scene()
{
CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",