1
2
3
4
5
6
|
functiongetQueryString(name){
varreg=
new
RegExp(
"(^|&)"
+name+
"=([^&]*)(&|$)"
,
"i"
);
varr=window.location.search.substr(1).match(reg);
if
(r!=null)
return
decodeURIComponent(r[2]);
null;
};
|
2、底图上添加文字---适用于按钮Sprite
varMyButtonsprite=cc.Sprite.extend({
ctor:function(fileName,title,fontName,fontSize){
this
._super(fileName);
vartitleLabel=
cc.LabelTTF(title,fontSize);
.addChild(titleLabel);
titleLabel.x=
.getContentSize().width/2;
titleLabel.y=
.getContentSize().height/2;
}
});
|
3、远程图片加载
loadImgFromUrl:function(target,imgurl,p,tag){
(!imgurl)
;
varself=target;
varloadCb=function(err,img){
cc.textureCache.addImage(imgurl);
vartexture2d=
cc.Texture2D();
texture2d.initWithElement(img);
texture2d.handleLoadedTexture();
varsp=
cc.Sprite();
sp.initWithTexture(texture2d);
self.addChild(sp);
sp.x=p.x;
sp.y=p.y;
sp.tag=tag;
};
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height: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,
|
4、XMLHttpRequest
varsendRequest=function(url,params,isPost,callback,errorcallback){
(url==null||url==
''
)
;
varxhr=cc.loader.getXMLHttpRequest();
(isPost){
xhr.open(
"POST"
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height: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);
}
else
{
"GET"
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height: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.setRequestHeader(
"Content-Type"
"application/x-www-form-urlencoded"
);
xhr.onreadystatechange=function(){
(xhr.readyState==4&&xhr.status==200){
varresponse=xhr.responseText;
(callback)
callback(response);
else
(xhr.readyState==4&&xhr.status!=200){
varresponse=xhr.responseText;
(errorcallback)
errorcallback(response);
}
};
xhr.send();
{
xhr.send(params);
}
5、JSON解析以及上述第4条的回调方法 |