大佬教程收集整理的这篇文章主要介绍了Cocos2d-JS开发中的一些小技巧,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
1、获取URL中的请求参数的值----此方法接收参数名
2、底图上添加文字---适用于按钮Sprite
3、远程图片加载
loadImgFromUrl:function(target,imgUrl,p,tag){
(!imgUrl)
;
varself=target;
varloadCb=function(err,img){
cc.textureCache.addImage(imgUrl);
vartexture2d=
cc.Texture2D();
texture2d.handleLoadedTexture();
varsp=
cc.Sprite();
sp.initWithTexture(texture2d);
self.addChild(sp);
sp.x=p.x;
sp.y=p.y;
sp.tag=tag;
};
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
|
varsendrequest=function(url,params,isPost,callBACk,errorcallBACk){
(url==null||url==
''
)
;
(isPost){
xhr.open(
"POST"
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,url);
"GET"
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,url);
}
(xhr.readyState==4&&xhr.status==200){
varresponse=xhr.responseText;
(callBACk)
varresponse=xhr.responseText;
(errorcallBACk)
}
};
xhr.send();
xhr.send(params);
}
5、JSON解析以及上述第4条的回调方法 |