123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- /****************************************************************************
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
- http://www.cocos2d-x.org
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
- /**
- * <p>cc.LoaderScene is a scene that you can load it when you loading files</p>
- * <p>cc.LoaderScene can present thedownload progress </p>
- * @class
- * @extends cc.Scene
- * @example
- * var lc = new cc.LoaderScene();
- */
- cc.LoaderScene = cc.Scene.extend({
- _interval : null,
- _label : null,
- _className:"LoaderScene",
- /**
- * Contructor of cc.LoaderScene
- * @returns {boolean}
- */
- init : function(){
- var self = this;
- //logo
- var logoWidth = 160;
- var logoHeight = 200;
- // bg
- var bgLayer = self._bgLayer = new cc.LayerColor(cc.color(32, 32, 32, 255));
- bgLayer.setPosition(cc.visibleRect.bottomLeft);
- self.addChild(bgLayer, 0);
- //image move to CCSceneFile.js
- var fontSize = 24, lblHeight = -logoHeight / 2 + 100;
- /*
- if(cc._loaderImage){
- //loading logo
- cc.loader.loadImg(cc._loaderImage, {isCrossOrigin : false }, function(err, img){
- logoWidth = img.width;
- logoHeight = img.height;
- self._initStage(img, cc.visibleRect.center);
- });
- fontSize = 14;
- lblHeight = -logoHeight / 2 - 10;
- }*/
- //loading percent
- var label = self._label = cc.LabelTTF.create("Loading... 0%", "Arial", fontSize);
- label.setPosition(cc.pAdd(cc.visibleRect.center, cc.p(0, lblHeight)));
- label.setColor(cc.color(180, 180, 180));
- bgLayer.addChild(this._label, 10);
- return true;
- },
- _initStage: function (img, centerPos) {
- var self = this;
- var texture2d = self._texture2d = new cc.Texture2D();
- texture2d.initWithElement(img);
- texture2d.handleLoadedTexture();
- var logo = self._logo = cc.Sprite.create(texture2d);
- logo.setScale(cc.contentScaleFactor());
- logo.x = centerPos.x;
- logo.y = centerPos.y;
- self._bgLayer.addChild(logo, 10);
- },
- /**
- * custom onEnter
- */
- onEnter: function () {
- var self = this;
- cc.Node.prototype.onEnter.call(self);
- self.schedule(self._startLoading, 0.3);
- },
- /**
- * custom onExit
- */
- onExit: function () {
- cc.Node.prototype.onExit.call(this);
- var tmpStr = "Loading... 0%";
- this._label.setString(tmpStr);
- },
- /**
- * init with resources
- * @param {Array} resources
- * @param {Function|String} cb
- */
- initWithResources: function (resources, cb) {
- if(typeof resources == "string") resources = [resources];
- this.resources = resources || [];
- this.cb = cb;
- },
- _startLoading: function () {
- var self = this;
- self.unschedule(self._startLoading);
- var res = self.resources;
- cc.loader.load(res,
- function (result, count, loadedCount) {
- var percent = (loadedCount / count * 100) | 0;
- percent = Math.min(percent, 100);
- self._label.setString("Loading... " + percent + "%");
- }, function () {
- if (self.cb)
- self.cb();
- });
- }
- });
- /**
- * <p>cc.LoaderScene.preload can present a loaderScene with download progress.</p>
- * <p>when all the resource are downloaded it will invoke call function</p>
- * @param resources
- * @param cb
- * @returns {cc.LoaderScene|*}
- * @example
- * //Example
- * cc.LoaderScene.preload(g_resources, function () {
- cc.director.runScene(new HelloWorldScene());
- }, this);
- */
- cc.LoaderScene.preload = function(resources, cb){
- var _cc = cc;
- if(!_cc.loaderScene) {
- _cc.loaderScene = new cc.LoaderScene();
- _cc.loaderScene.init();
- }
- _cc.loaderScene.initWithResources(resources, cb);
- cc.director.runScene(_cc.loaderScene);
- return _cc.loaderScene;
- };
|