varMyLoaderScene=cc.Scene.extend({
_interval:null,
_length:0,
_count:0,
_label:null,
_className:
"MyLoaderScene"
init:function(){
varself=
;
//bg
varbgLayer=self._bgLayer=cc.LayerColor.create(cc.color(32,32,255));
bgLayer.setPosition(cc.visibleRect.bottomLeft);
self.addChild(bgLayer,0);
//loadingpercent
varlabel=self._label=cc.LabelTTF.create(
"玩命加载中...0%"
"Arial"
label.setPosition(cc.pAdd(cc.visibleRect.center,cc.p(0,0)));
label.setColor(cc.color(180,180,180));
bgLayer.addChild(
._label,10);
return
true
;
_initStage:function(img,centerPos){
;
vartexture2d=self._texture2d=
cc.Texture2D();
texture2d.initWithElement(img);
texture2d.handleLoadedTexture();
varlogo=self._logo=cc.Sprite.create(texture2d);
logo.setScale(cc.contentScaleFactor());
logo.x=centerPos.x;
logo.y=centerPos.y;
self._bgLayer.addChild(logo,10);
onEnter:function(){
;
cc.Node.prototype.onEnter.call(self);
self.schedule(self._startLoading,0.3);
onExit:function(){
cc.Node.prototype.onExit.call(
);
vartmpStr=
;
._label.setString(tmpStr);
/**
*initwithresources
*@param{Array}resources
*@param{Function|String}cb
*/
initWithResources:function(resources,cb){
(typeofresources==
"string"
)resources=[resources];
.resources=resources||[];
.cb=cb;
_startLoading:function(){
;
self.unschedule(self._startLoading);
varres=self.resources;
self._length=res.length;
self._count=0;
cc.loader.load(res,function(result,count){self._count=count;},function(){
(self.cb)
self.cb();
});
self.schedule(self._updatePercent);
_updatePercent:function(){
;
varcount=self._count;
varlength=self._length;
varpercent=(count/length*100)|0;
percent=Math.min(percent,100);
self._label.setString(
"玩命加载中..."
+percent+
"%"
);
(count>=length)self.unschedule(self._updatePercent);
}
});
MyLoaderScene.preload=function(resources,cb){
var_myLoaderScene=null;
(!_myLoaderScene){
_myLoaderScene=
MyLoaderScene();
_myLoaderScene.init();
}
_myLoaderScene.initWithResources(resources,cb);
cc.director.runScene(_myLoaderScene);
_myLoaderScene;
};
|