diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 82e040dcd4..1c42eaa9df 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -809,7 +809,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ if (error) { error = 'Failed to load scene: ' + error; cc.error(error); - if (CC_EDITOR) { + if (CC_DEV) { console.assert(false, error); } } @@ -817,12 +817,6 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ if (sceneAsset instanceof cc.SceneAsset) { scene = sceneAsset.scene; scene._id = sceneAsset._uuid; - } - else { - // hack for preview - scene = sceneAsset; - } - if (scene instanceof cc.Scene) { scene._name = sceneAsset._name; self.runSceneImmediate(scene, onUnloaded, onLaunched); } diff --git a/cocos2d/core/CCScene.js b/cocos2d/core/CCScene.js index 2889c9b6e1..d717379369 100644 --- a/cocos2d/core/CCScene.js +++ b/cocos2d/core/CCScene.js @@ -38,6 +38,16 @@ cc.Scene = cc.Class({ name: 'cc.Scene', extends: require('./utils/base-node'), + //properties: { + // /** + // * !#en Indicates the raw assets of this scene can be load after scene launched. + // * !#zh 指示该场景依赖的资源可否在场景切换后再延迟加载。 + // * @property {Boolean} _asyncLoadAssets + // * @default false + // */ + // _asyncLoadAssets: false + //}, + ctor: function () { var sgNode = this._sgNode = new _ccsg.Scene(); if (CC_JSB) { @@ -103,7 +113,7 @@ cc.Scene = cc.Class({ module.exports = cc.Scene; -if (CC_EDITOR) { +if (CC_DEV) { var ERR = '"%s" is not defined in the Scene, it is only defined in child nodes.'; Object.defineProperties(cc.Scene.prototype, { active: { diff --git a/cocos2d/core/assets/CCAsset.js b/cocos2d/core/assets/CCAsset.js index 49cda55eba..b99f7c9cd0 100644 --- a/cocos2d/core/assets/CCAsset.js +++ b/cocos2d/core/assets/CCAsset.js @@ -124,7 +124,17 @@ cc.Asset = cc.Class({ */ deserialize: function (data) { return cc.deserialize(data); - } + }, + + /** + * !#en Indicates whether its dependent raw assets can support deferred load if the owner scene is marked as `asyncLoadAssets`. + * !#zh 当场景被标记为 `asyncLoadAssets`,禁止延迟加载该资源所依赖的其它 RawAsset。 + * + * @property {Boolean} preventDeferredLoadDependents + * @default false + * @static + */ + preventDeferredLoadDependents: false }, /** diff --git a/cocos2d/core/assets/CCSceneAsset.js b/cocos2d/core/assets/CCSceneAsset.js index 46a0ab81a1..d27b61a3c3 100644 --- a/cocos2d/core/assets/CCSceneAsset.js +++ b/cocos2d/core/assets/CCSceneAsset.js @@ -35,7 +35,14 @@ var Scene = cc.Class({ extends: cc.Asset, properties: { - scene: null + scene: null, + /** + * !#en Indicates the raw assets of this scene can be load after scene launched. + * !#zh 指示该场景依赖的资源可否在场景切换后再延迟加载。 + * @property {Boolean} asyncLoadAssets + * @default undefined + */ + asyncLoadAssets: undefined }, }); diff --git a/cocos2d/core/components/CCButton.js b/cocos2d/core/components/CCButton.js index f18a763a0a..e1a7522a97 100644 --- a/cocos2d/core/components/CCButton.js +++ b/cocos2d/core/components/CCButton.js @@ -327,6 +327,20 @@ var Button = cc.Class({ }, onEnable: function () { + // check sprite frames + if (this.normalSprite) { + this.normalSprite.ensureLoadTexture(); + } + if (this.hoverSprite) { + this.hoverSprite.ensureLoadTexture(); + } + if (this.pressedSprite) { + this.pressedSprite.ensureLoadTexture(); + } + if (this.disabledSprite) { + this.disabledSprite.ensureLoadTexture(); + } + // if (!CC_EDITOR) { this._registerEvent(); } else { diff --git a/cocos2d/core/components/CCComponent.js b/cocos2d/core/components/CCComponent.js index a820cf22ca..6b26bb6bd5 100644 --- a/cocos2d/core/components/CCComponent.js +++ b/cocos2d/core/components/CCComponent.js @@ -308,24 +308,24 @@ var Component = cc.Class({ __scriptAsset: CC_EDITOR && { get: function () {}, - set: function (value) { - if (this.__scriptUuid !== value) { - if (value && Editor.UuidUtils.isUuid(value._uuid)) { - var classId = Editor.UuidUtils.compressUuid(value._uuid); - var NewComp = cc.js._getClassById(classId); - if (cc.isChildClassOf(NewComp, cc.Component)) { - cc.warn('Sorry, replacing component script is not yet implemented.'); - //Editor.Ipc.sendToWins('reload:window-scripts', Editor._Sandbox.compiled); - } - else { - cc.error('Can not find a component in the script which uuid is "%s".', value._uuid); - } - } - else { - cc.error('Invalid Script'); - } - } - }, + //set: function (value) { + // if (this.__scriptUuid !== value) { + // if (value && Editor.UuidUtils.isUuid(value._uuid)) { + // var classId = Editor.UuidUtils.compressUuid(value._uuid); + // var NewComp = cc.js._getClassById(classId); + // if (cc.isChildClassOf(NewComp, cc.Component)) { + // cc.warn('Sorry, replacing component script is not yet implemented.'); + // //Editor.Ipc.sendToWins('reload:window-scripts', Editor._Sandbox.compiled); + // } + // else { + // cc.error('Can not find a component in the script which uuid is "%s".', value._uuid); + // } + // } + // else { + // cc.error('Invalid Script'); + // } + // } + //}, displayName: 'Script', type: cc._Script, tooltip: 'i18n:INSPECTOR.component.script' @@ -445,8 +445,8 @@ var Component = cc.Class({ onLoad: null, /** - * !#en Called before all scripts' update if the Component is enabled. - * !#zh 如果该组件启用,则在所有组件的 update 之前调用。 + * !#en Called before all scripts' update if the Component is enabled the first time. + * !#zh 如果该组件第一次启用,则在所有组件的 update 之前调用。 * @method start */ start: null, diff --git a/cocos2d/core/components/CCEditBox.js b/cocos2d/core/components/CCEditBox.js index 17c4baa9f8..7436496342 100644 --- a/cocos2d/core/components/CCEditBox.js +++ b/cocos2d/core/components/CCEditBox.js @@ -407,7 +407,7 @@ var EditBox = cc.Class({ var bgSprite = new cc.Scale9Sprite(); bgSprite.setRenderingType(cc.Scale9Sprite.RenderingType.SLICED); if (this.backgroundImage) { - + this.backgroundImage.ensureLoadTexture(); bgSprite.setSpriteFrame(this.backgroundImage); this._applyCapInset(bgSprite); } diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index ba4760c176..9674d32ed8 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -563,12 +563,14 @@ var Sprite = cc.Class({ oldFrame.off('load', this._onSpriteFrameLoaded, this); } - if (this._spriteFrame) { - if (this._spriteFrame.textureLoaded()) { + var spriteFrame = this._spriteFrame; + if (spriteFrame) { + if (spriteFrame.textureLoaded()) { this._onSpriteFrameLoaded(null); } else { - this._spriteFrame.once('load', this._onSpriteFrameLoaded, this); + spriteFrame.once('load', this._onSpriteFrameLoaded, this); + spriteFrame.ensureLoadTexture(); } } else { @@ -577,7 +579,7 @@ var Sprite = cc.Class({ if (CC_EDITOR) { // Set atlas - this._applyAtlas(this._spriteFrame); + this._applyAtlas(spriteFrame); } }, diff --git a/cocos2d/core/load-pipeline/uuid-loader.js b/cocos2d/core/load-pipeline/uuid-loader.js index 0649dc3a15..a074f4e931 100644 --- a/cocos2d/core/load-pipeline/uuid-loader.js +++ b/cocos2d/core/load-pipeline/uuid-loader.js @@ -39,25 +39,55 @@ function isSceneObj (json) { ); } -function loadDepends (pipeline, item, asset, tdInfo, callback) { - var uuid = item.id; - var uuidList = tdInfo.uuidList; - var ownerList = JS.array.copy(tdInfo.uuidObjList); - var propList = JS.array.copy(tdInfo.uuidPropList); - - var depends = new Array(uuidList.length); - // load depends assets - for (var i = 0; i < uuidList.length; i++) { - var dependUuid = uuidList[i]; - depends[i] = { - id: dependUuid, - type: 'uuid', - uuid: dependUuid - }; +function loadDepends (pipeline, item, asset, tdInfo, deferredLoadRawAssetsInRuntime, callback) { + var uuid = item.id, uuidList = tdInfo.uuidList; + var objList, propList, depends; + var i, dependUuid; + if (deferredLoadRawAssetsInRuntime) { + objList = []; + propList = []; + depends = []; + // parse depends assets + for (i = 0; i < uuidList.length; i++) { + dependUuid = uuidList[i]; + var obj = tdInfo.uuidObjList[i]; + var prop = tdInfo.uuidPropList[i]; + var info = cc.AssetLibrary._getAssetInfoInRuntime(dependUuid); + if (info.raw) { + // skip preloading raw assets + var url = info.url; + obj[prop] = url; + } + else { + objList.push(obj); + propList.push(prop); + // declare depends assets + depends.push({ + id: dependUuid, + type: 'uuid', + uuid: dependUuid, + deferredLoadRaw: true, + }); + } + } } - // load raw + else { + objList = JS.array.copy(tdInfo.uuidObjList); + propList = JS.array.copy(tdInfo.uuidPropList); + depends = new Array(uuidList.length); + // declare depends assets + for (i = 0; i < uuidList.length; i++) { + dependUuid = uuidList[i]; + depends[i] = { + id: dependUuid, + type: 'uuid', + uuid: dependUuid + }; + } + } + // declare raw if (tdInfo.rawProp) { - ownerList.push(asset); + objList.push(asset); propList.push(tdInfo.rawProp); depends.push(item.url); } @@ -77,13 +107,13 @@ function loadDepends (pipeline, item, asset, tdInfo, callback) { } for (var i = 0; i < depends.length; i++) { var dependSrc = depends[i].uuid; - var obj = ownerList[i]; + var dependObj = objList[i]; var dependProp = propList[i]; item = items[dependSrc]; if (item) { if (item.complete) { var value = item.isRawAsset ? item.url : item.content; - obj[dependProp] = value; + dependObj[dependProp] = value; } else { // item was removed from cache, but ready in pipeline actually @@ -92,7 +122,7 @@ function loadDepends (pipeline, item, asset, tdInfo, callback) { this.obj[this.prop] = value; }; var target = { - obj: obj, + obj: dependObj, prop: dependProp }; // Hack to get a better behavior @@ -114,6 +144,32 @@ function loadDepends (pipeline, item, asset, tdInfo, callback) { }); } +// can deferred load raw assets in runtime +function canDeferredLoad (asset, item, isScene) { + if (CC_EDITOR) { + return false; + } + var res = item.deferredLoadRaw; + if (res) { + // check if asset support deferred + if (asset instanceof cc.Asset && asset.constructor.preventDeferredLoadDependents) { + res = false; + } + } + else if (isScene) { + if (asset instanceof cc.SceneAsset) { + res = asset.asyncLoadAssets; + if (res) { + cc.log('deferred load raw assets for ' + item.id); + } + } + //else if (asset instanceof cc.Scene) { + // deferredLoadRawAssetsInRuntime = asset._asyncLoadAssets; + //} + } + return res; +} + function loadUuid (item, callback) { var json; if (typeof item.content === 'string') { @@ -133,7 +189,8 @@ function loadUuid (item, callback) { return; } - var classFinder = isSceneObj(json) ? cc._MissingScript.safeFindClass : function (id) { + var isScene = isSceneObj(json); + var classFinder = isScene ? cc._MissingScript.safeFindClass : function (id) { var cls = JS._getClassById(id); if (cls) { return cls; @@ -148,7 +205,8 @@ function loadUuid (item, callback) { try { asset = cc.deserialize(json, tdInfo, { classFinder: classFinder, - target: item.existingAsset + target: item.existingAsset, + customEnv: item }); } catch (e) { @@ -156,7 +214,8 @@ function loadUuid (item, callback) { return; } - loadDepends(this.pipeline, item, asset, tdInfo, callback); + var deferredLoad = canDeferredLoad(asset, item, isScene); + loadDepends(this.pipeline, item, asset, tdInfo, deferredLoad, callback); // tdInfo 是用来重用的临时对象,每次使用后都要重设,这样才对 GC 友好。 tdInfo.reset(); diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index 9db61df58c..e9dc5416f0 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -1031,6 +1031,7 @@ function parseAttributes (attrs, className, propName) { parseSimpleAttr('rawType', 'string', Attr.RawType); parseSimpleAttr('editorOnly', 'boolean', Attr.EditorOnly); + //parseSimpleAttr('preventDeferredLoad', 'boolean'); if (CC_DEV) { parseSimpleAttr('displayName', 'string'); parseSimpleAttr('multiline', 'boolean', {multiline: true}); diff --git a/cocos2d/core/platform/deserialize.js b/cocos2d/core/platform/deserialize.js index 909c238f00..73e85a625a 100644 --- a/cocos2d/core/platform/deserialize.js +++ b/cocos2d/core/platform/deserialize.js @@ -161,7 +161,7 @@ var _Deserializer = (function () { ///** // * @param {Boolean} isEditor - if false, "editorOnly" properties will be discarded // */ - function _Deserializer(jsonObj, result, target, classFinder) { + function _Deserializer(jsonObj, result, target, classFinder, customEnv) { this._classFinder = classFinder; if (ENABLE_TARGET) { this._target = target; @@ -170,6 +170,7 @@ var _Deserializer = (function () { this._idObjList = []; this._idPropList = []; this.result = result || new Details(); + this.customEnv = customEnv; if (Array.isArray(jsonObj)) { var jsonArray = jsonObj; @@ -517,6 +518,7 @@ cc.deserialize = function (data, result, options) { // 启用 createAssetRefs 后,如果有 url 属性则会被统一强制设置为 { uuid: 'xxx' },必须后面再特殊处理 var createAssetRefs = (options && options.createAssetRefs) || cc.sys.platform === cc.sys.EDITOR_CORE; var target = ENABLE_TARGET && (options && options.target); + var customEnv = (options && options.customEnv); if (CC_EDITOR && Buffer.isBuffer(data)) { data = data.toString(); @@ -532,7 +534,7 @@ cc.deserialize = function (data, result, options) { result = new Details(); } cc.game._isCloning = true; - var deserializer = new _Deserializer(data, result, target, classFinder); + var deserializer = new _Deserializer(data, result, target, classFinder, customEnv); cc.game._isCloning = false; if (createAssetRefs) { diff --git a/cocos2d/core/sprites/CCSpriteFrame.js b/cocos2d/core/sprites/CCSpriteFrame.js index f4503c8187..b3e4fe5d7a 100644 --- a/cocos2d/core/sprites/CCSpriteFrame.js +++ b/cocos2d/core/sprites/CCSpriteFrame.js @@ -81,9 +81,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ // just packing return; } - - var texture = cc.textureCache.addImage(url); - this._refreshTexture(texture); + this._loadTexture(); } } } @@ -373,7 +371,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ /* * Initializes SpriteFrame with Texture, rect, rotated, offset and originalSize in pixels.
* Please pass parameters to the constructor to initialize the sprite, do not call this function yourself. - * @method initWithTexture + * @method setTexture * @param {String|Texture2D} texture * @param {Rect} [rect=null] * @param {Boolean} [rotated=false] @@ -381,27 +379,25 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ * @param {Size} [originalSize=rect.size] * @return {Boolean} */ - initWithTexture: function (textureOrTextureFile, rect, rotated, offset, originalSize) { - this.setTexture(textureOrTextureFile, rect, rotated, offset, originalSize); - }, - setTexture: function (textureOrTextureFile, rect, rotated, offset, originalSize) { - if (rect) { this.setRect(rect); - } else { + } + else { this._rect = null; } if (offset) { this.setOffset(offset); - } else { + } + else { this._offset = null; } if (originalSize) { this.setOriginalSize(originalSize); - } else { + } + else { this._originalSize = null; } @@ -411,17 +407,49 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ var texture = textureOrTextureFile; if (cc.js.isString(texture)) { this._textureFilename = texture; - texture = cc.textureCache.addImage(texture); + this._loadTexture(); } - if (texture instanceof cc.Texture2D) { + else if (texture instanceof cc.Texture2D) { this._refreshTexture(texture); - } else { + } + else { //todo log error } return true; }, + _loadTexture: function () { + if (this._textureFilename) { + var texture = cc.textureCache.addImage(this._textureFilename); + this._refreshTexture(texture); + } + }, + + /** + * !#en If a loading scene is marked as `asyncLoadAssets`, all the textures of the SpriteFrame which + * associated by user's custom Components in the scene, will not preload automatically. + * These textures will be load when Sprite component is going to render the SpriteFrames. + * You can call this method if you want to load the texture early. + * !#zh 当加载中的场景被标记为 `asyncLoadAssets` 时,用户在场景中由自定义组件关联到的所有 SpriteFrame 的贴图都不会被提前加载。 + * 只有当 Sprite 组件要渲染这些 SpriteFrame 时,才会检查贴图是否加载。如果你希望加载过程提前,你可以手工调用这个方法。 + * + * @method ensureLoadTexture + * @example + * if (spriteFrame.textureLoaded()) { + * this._onSpriteFrameLoaded(); + * } + * else { + * spriteFrame.once('load', this._onSpriteFrameLoaded, this); + * spriteFrame.ensureLoadTexture(); + * } + */ + ensureLoadTexture: function () { + if (!this._texture) { + this._loadTexture(); + } + }, + _checkRect: function (texture) { var rect = this._rect; var maxX = rect.x, maxY = rect.y; @@ -503,24 +531,15 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ // load texture via _textureFilenameSetter var textureUuid = data.texture; if (textureUuid) { - handle.result.push(this, '_textureFilenameSetter', textureUuid); + var dontLoadTexture = (handle.customEnv && handle.customEnv.deferredLoadRaw); + var receiver = dontLoadTexture ? '_textureFilename' : '_textureFilenameSetter'; + handle.result.push(this, receiver, textureUuid); } } }); var proto = cc.SpriteFrame.prototype; -/* - * Copy the sprite frame - * @method copyWithZone - * @return {SpriteFrame} - */ proto.copyWithZone = proto.clone; - -/* - * Copy the sprite frame - * @method copy - * @returns {SpriteFrame} - */ proto.copy = proto.clone; - +proto.initWithTexture = proto.setTexture; diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 4db2211606..c82c33fec2 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -934,24 +934,24 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * !#en Sets the scale factor of the node. 1.0 is the default scale factor. This function can modify the X and Y scale at the same time. * !#zh 设置节点的缩放比例,默认值为 1.0。这个函数可以在同一时间修改 X 和 Y 缩放。 * @method setScale - * @param {Number|Vec2} scale - scaleX or scale + * @param {Number|Vec2} scaleX - scaleX or scale * @param {Number} [scaleY=scale] * @example * node.setScale(cc.v2(1, 1)); * node.setScale(1, 1); */ - setScale: function (scale, scaleY) { - if (scale instanceof cc.Vec2) { - scaleY = scale.y; - scale = scale.x + setScale: function (scaleX, scaleY) { + if (typeof scaleX === 'object') { + scaleY = scaleX.y; + scaleX = scaleX.x } else { - scaleY = (scaleY || scaleY === 0) ? scaleY : scale; + scaleY = (scaleY || scaleY === 0) ? scaleY : scaleX; } - if (this._scaleX !== scale || this._scaleY !== scaleY) { - this._scaleX = scale; + if (this._scaleX !== scaleX || this._scaleY !== scaleY) { + this._scaleX = scaleX; this._scaleY = scaleY; - this._sgNode.setScale(scale, scaleY); + this._sgNode.setScale(scaleX, scaleY); } }, diff --git a/cocos2d/tilemap/CCTiledMapAsset.js b/cocos2d/tilemap/CCTiledMapAsset.js index c8d956950c..02dc5ab2c6 100644 --- a/cocos2d/tilemap/CCTiledMapAsset.js +++ b/cocos2d/tilemap/CCTiledMapAsset.js @@ -53,6 +53,10 @@ var TiledMapAsset = cc.Class({ } }, + statics: { + preventDeferredLoadDependents: true + }, + createNode: CC_EDITOR && function (callback) { var node = new cc.Node(this.name); var tiledMap = node.addComponent(cc.TiledMap); diff --git a/extensions/spine/SkeletonData.js b/extensions/spine/SkeletonData.js index 8c610e03a4..191de16798 100644 --- a/extensions/spine/SkeletonData.js +++ b/extensions/spine/SkeletonData.js @@ -150,6 +150,10 @@ var SkeletonData = cc.Class({ scale: 1 }, + statics: { + preventDeferredLoadDependents: true + }, + // PUBLIC createNode: function (callback) { diff --git a/jsb/jsb-director.js b/jsb/jsb-director.js index e6d9be881b..77d379627b 100644 --- a/jsb/jsb-director.js +++ b/jsb/jsb-director.js @@ -331,15 +331,16 @@ cc.js.mixin(cc.director, { if (error) { error = 'Failed to load scene: ' + error; cc.error(error); - if (CC_EDITOR) { + if (CC_DEV) { console.assert(false, error); } } else { - scene = sceneAsset.scene; - if (scene instanceof cc.Scene) { + if (sceneAsset instanceof cc.SceneAsset) { + scene = sceneAsset.scene; scene._id = sceneAsset._uuid; - self.runScene(scene, onUnloaded, onLaunched); + scene._name = sceneAsset._name; + self.runSceneImmediate(scene, onUnloaded, onLaunched); } else { error = 'The asset ' + uuid + ' is not a scene'; diff --git a/jsb/jsb-tex-sprite-frame.js b/jsb/jsb-tex-sprite-frame.js index 8a3d2adfce..e12017b99a 100644 --- a/jsb/jsb-tex-sprite-frame.js +++ b/jsb/jsb-tex-sprite-frame.js @@ -79,21 +79,13 @@ prototype._ctor = function (filename, rect, rotated, offset, originalSize) { } }; -prototype._initWithTexture = prototype.initWithTexture; -prototype.initWithTexture = function (texture, rect, rotated, offset, originalSize) { - this.setTexture(texture, rect, rotated, offset, originalSize); -}; - prototype.setTexture = function (textureOrTextureFile, rect, rotated, offset, originalSize) { - if (rect) { this.setRect(rect); } - if (offset) { this.setOffset(offset); } - if (originalSize) { this.setOriginalSize(originalSize); } @@ -103,10 +95,9 @@ prototype.setTexture = function (textureOrTextureFile, rect, rotated, offset, or var texture = textureOrTextureFile; if (cc.js.isString(textureOrTextureFile)) { this._textureFilename = textureOrTextureFile; - texture = cc.textureCache.addImage(textureOrTextureFile); + this._loadTexture(); } - - if (texture instanceof cc.Texture2D) { + else if (texture instanceof cc.Texture2D) { this._refreshTexture(texture); } else { @@ -116,6 +107,22 @@ prototype.setTexture = function (textureOrTextureFile, rect, rotated, offset, or return true; }; +prototype._loadTexture = function () { + if (this._textureFilename) { + var texture = cc.textureCache.addImage(this._textureFilename); + this._refreshTexture(texture); + } +}; + +prototype.ensureLoadTexture = function () { + if (!this._texture) { + this._loadTexture(); + } +}; + +prototype._initWithTexture = prototype.initWithTexture; +prototype.initWithTexture = prototype.setTexture; + prototype._refreshTexture = function (texture) { if (this.getTexture() !== texture) { @@ -178,7 +185,9 @@ prototype._deserialize = function (data, handle) { // load texture via _textureFilenameSetter var textureUuid = data.texture; if (textureUuid) { - handle.result.push(this, '_textureFilenameSetter', textureUuid); + var dontLoadTexture = (handle.customEnv && handle.customEnv.deferredLoadRaw); + var receiver = dontLoadTexture ? '_textureFilename' : '_textureFilenameSetter'; + handle.result.push(this, receiver, textureUuid); } }; prototype._checkRect = function (texture) { @@ -210,8 +219,7 @@ prototype.getTexture = function () { cc.js.set(prototype, '_textureFilenameSetter', function (url) { this._textureFilename = url; if (url) { - var texture = cc.textureCache.addImage(url); - this._refreshTexture(texture); + this._loadTexture(); } });