HTTP网络
http是短协议,登录注册用,socket是长连接战斗时用
https(更安全)加密传输,身份认证
get 与 post 的差异:
void HelloWorld::HttpGetTest(){
HttpRequest * request = new HttpRequest ();
request->setUrl("http://42.96.151.161:83/service/getHero?user_name=Teacher_wei");
request->setRequestType(HttpRequest::Type::GET);
request->setTag("get");
request->setResponseCallback(CC_CALLBACK_2(HelloWorld::httpResponse_call, this));
HttpClient::getInstance()->send(request);
request->release();
}
void HelloWorld::HttpPostTest(){
char str[100];
sprintf(str, "user_name=Teacher_wei");
// 创建一个请求对象
HttpRequest * request = new HttpRequest();
// 设置请求的服务器地址
request->setUrl("http://42.96.151.161:83/service/getHero?");
// 设置请求方式
request->setRequestType(HttpRequest::Type::POST);
// 设置请求的数据
request->setRequestData(str, 100);
// 设置响应的回调函数
request->setResponseCallback(CC_CALLBACK_2(HelloWorld::httpResponse_call, this));
// 发送请求
HttpClient::getInstance()->send(request);
// 释放自己穿件的请求对象
request->release();
}
// 响应的回调函数
void HelloWorld::httpResponse_call(HttpClient* client, HttpResponse* response){
// 是否有响应
if(!response){
log("无响应");
return;
}
// 输出响应码 200:响应成功 -1:响应失败
log("响应码:%ld",response->getResponseCode());
// 获取响应的报文,督导缓冲区中
std::vector<char> * buffer = response->getResponseData();
// 输出报文内容
for(unsigned int i=0;i<buffer->size();i++){
printf("%c",(*buffer)[i]);
}
}
粒子系统
//添加粒子特效(自己制作生成plist文件)
ParticleSystemQuad * m = ParticleSystemQuad::create("example.plist");
addChild(m);
//引擎封装好的粒子
auto my = ParticleExplosion::create();
my->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
addChild(my);