From 296f07f30ec1049d780e09bf1f7aaea038a88d13 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 11 Apr 2016 17:08:51 +0800 Subject: [PATCH 01/20] fix cascaded opacity issue of label --- cocos2d/core/label/CCSGLabelCanvasRenderCmd.js | 1 + cocos2d/core/label/CCSGLabelWebGLRenderCmd.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js index 363a5a8ef7..14dc3e600e 100644 --- a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js +++ b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js @@ -52,6 +52,7 @@ } }; + proto._syncStatus = function (parentCmd) { var flags = _ccsg.Node._dirtyFlags, locFlag = this._dirtyFlag; var parentNode = parentCmd ? parentCmd._node : null; diff --git a/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js b/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js index bf33adf4b9..2ec5be05b8 100644 --- a/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js +++ b/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js @@ -58,6 +58,11 @@ cc.js.mixin(proto, _ccsg.Label.TTFLabelBaker.prototype); proto.constructor = _ccsg.Label.WebGLRenderCmd; +proto._updateDisplayOpacity = function (parentOpacity) { + _ccsg.Node.WebGLRenderCmd.prototype._updateDisplayOpacity.call(this, parentOpacity); + this._rebuildLabelSkin(); +}; + proto.rendering = function (ctx) { var node = this._node; From c29f8b6b8ec99dd2a29784bee42f7a1a84a0610c Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 14 Apr 2016 09:46:37 +0800 Subject: [PATCH 02/20] Repair sprite-frame can not be displayed --- jsb/jsb-etc.js | 22 ---------- jsb/jsb-tex-sprite-frame.js | 82 +++++++++++++++---------------------- 2 files changed, 33 insertions(+), 71 deletions(-) diff --git a/jsb/jsb-etc.js b/jsb/jsb-etc.js index b8fb830233..b5ce394506 100644 --- a/jsb/jsb-etc.js +++ b/jsb/jsb-etc.js @@ -119,28 +119,6 @@ cc.TextureCache.prototype.addImage = function(url, cb, target) { } }; -// cc.SpriteFrame -cc.SpriteFrame.prototype._ctor = function (filename, rect, rotated, offset, originalSize) { - if (originalSize !== undefined) { - if(filename instanceof cc.Texture2D) { - this.initWithTexture(filename, rect, rotated, offset, originalSize); - } - else { - this.initWithTexture(filename, rect, rotated, offset, originalSize); - } - } else if (rect !== undefined) { - if(filename instanceof cc.Texture2D) { - this.initWithTexture(filename, rect); - } - else { - this.initWithTextureFilename(filename, rect); - } - } else if (filename instanceof cc.Texture2D) { - rect = cc.rect(0, 0, filename.getPixelWidth(), filename.getPixelHeight()); - this.initWithTexture(filename, rect); - } -}; - // setTimeout, setInterval, clearTimeout, clearInteval var _windowTimeIntervalId = 0; var _windowTimeFunHash = {}; diff --git a/jsb/jsb-tex-sprite-frame.js b/jsb/jsb-tex-sprite-frame.js index df25442a13..26d0563ede 100644 --- a/jsb/jsb-tex-sprite-frame.js +++ b/jsb/jsb-tex-sprite-frame.js @@ -55,67 +55,51 @@ cc.js.mixin(cc.SpriteFrame.prototype, cc.EventTarget.prototype); cc.SpriteFrame.prototype.textureLoaded = function () { return this.getTexture() !== null; }; + +// cc.SpriteFrame +cc.SpriteFrame.prototype._ctor = function (filename, rect, rotated, offset, originalSize) { + if (filename !== undefined) { + this.initWithTexture(filename, rect, rotated, offset, originalSize); + } else { + //todo log Error + } +}; + cc.SpriteFrame.prototype._initWithTexture = cc.SpriteFrame.prototype.initWithTexture; -cc.SpriteFrame.prototype.initWithTexture = function (texture, rect, rotated, offset, originalSize, _uuid) { - function check(texture) { +cc.SpriteFrame.prototype.initWithTexture = function (textureOrTextureFile, rect, rotated, offset, originalSize) { + this.setTexture(textureOrTextureFile, rect, rotated, offset, originalSize); +}; + +cc.SpriteFrame.prototype.setTexture = function (textureOrTextureFile, rect, rotated, offset, originalSize) { + var texture = textureOrTextureFile; + + if (cc.js.isString(texture)){ + this._textureFilename = texture; + texture = cc.textureCache.addImage(texture); + } + + if (texture instanceof cc.Texture2D) { if (texture && texture.isLoaded()) { - var _x, _y; - if (rotated) { - _x = rect.x + rect.height; - _y = rect.y + rect.width; + + if (rect) { + this._checkRect(texture); } else { - _x = rect.x + rect.width; - _y = rect.y + rect.height; + rect = cc.rect(0, 0, texture.width, texture.height); } - if (_x > texture.getPixelWidth()) { - cc.error(cc._LogInfos.RectWidth, _uuid); - } - if (_y > texture.getPixelHeight()) { - cc.error(cc._LogInfos.RectHeight, _uuid); - } - } - } - offset = offset || cc.p(0, 0); - originalSize = originalSize || rect; - rotated = rotated || false; + offset = offset || cc.p(0, 0); + originalSize = originalSize || rect; + rotated = rotated || false; - if (this.insetTop === undefined) { - this.insetTop = 0; - this.insetBottom = 0; - this.insetLeft = 0; - this.insetRight = 0; - } - - var locTexture; - if (!texture && _uuid) { - // deserialize texture from uuid - var info = cc.AssetLibrary._getAssetInfoInRuntime(_uuid); - if (!info) { - cc.error('SpriteFrame: Failed to load sprite texture "%s"', _uuid); - return; - } - - this._textureFilename = info.url; - - locTexture = cc.textureCache.addImage(info.url); - this._initWithTexture(locTexture, rect, rotated, offset, originalSize); - } - else { - if (cc.js.isString(texture)){ - this._textureFilename = texture; - locTexture = cc.textureCache.addImage(this._textureFilename); - this._initWithTexture(locTexture, rect, rotated, offset, originalSize); - } else if (texture instanceof cc.Texture2D) { - this._textureFilename = ''; this._initWithTexture(texture, rect, rotated, offset, originalSize); + + this.emit('load'); } } - this.emit('load'); - check(this.getTexture()); return true; }; + cc.SpriteFrame.prototype._deserialize = function (data, handle) { var rect = data.rect ? new cc.Rect(data.rect[0], data.rect[1], data.rect[2], data.rect[3]) : undefined; var offset = data.offset ? new cc.Vec2(data.offset[0], data.offset[1]) : undefined; From ba08f69a637919f42349a3bd37a834d37de6de0e Mon Sep 17 00:00:00 2001 From: zhangbin Date: Thu, 14 Apr 2016 17:30:13 +0800 Subject: [PATCH 03/20] Solve the error effect in web when using rotated tile in TiledMap. --- cocos2d/tilemap/CCSGTMXLayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/tilemap/CCSGTMXLayer.js b/cocos2d/tilemap/CCSGTMXLayer.js index 71f120092b..7a25435a3d 100644 --- a/cocos2d/tilemap/CCSGTMXLayer.js +++ b/cocos2d/tilemap/CCSGTMXLayer.js @@ -796,7 +796,7 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{ sprite.setFlippedY(false); // Rotation in tiled is achieved using 3 flipped states, flipping across the horizontal, vertical, and diagonal axes of the tiles. - if ((gid & cc.TiledMap.TileFlag.DIAGONAL_FLAG) >>> 0) { + if ((gid & cc.TiledMap.TileFlag.DIAGONAL) >>> 0) { // put the anchor in the middle for ease of rotation. sprite.anchorX = 0.5; sprite.anchorY = 0.5; From 3265e632e6cb624d79a5c260abcde6d3f1c2b941 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 20 Apr 2016 01:09:26 +0800 Subject: [PATCH 04/20] disallow ignoreAnchorPointForPosition in render tree to avoid rotation bug can not fixed in JSB --- cocos2d/core/components/CCMask.js | 17 +++---------- cocos2d/core/components/CCRendererInSG.js | 21 ++++++++++++---- cocos2d/core/components/CCRendererUnderSG.js | 15 ++++++++++- cocos2d/core/components/CCSGComponent.js | 19 +++++--------- cocos2d/core/utils/base-node.js | 26 -------------------- cocos2d/tilemap/CCTiledMap.js | 6 +++++ test/qunit/unit/test-deserialize.js | 8 +++--- 7 files changed, 49 insertions(+), 63 deletions(-) diff --git a/cocos2d/core/components/CCMask.js b/cocos2d/core/components/CCMask.js index 3e8acbeab8..8957573d8d 100644 --- a/cocos2d/core/components/CCMask.js +++ b/cocos2d/core/components/CCMask.js @@ -116,19 +116,8 @@ var Mask = cc.Class({ return new cc.ClippingNode(this._clippingStencil); }, - _initSgNode: function () { - var clippingNode = this._sgNode; - clippingNode.setContentSize(this.node.getContentSize(true)); - }, - - //onLoad: function () { - // this._super(); - // // ignore node size - // if (this.node._sizeProvider === this._sgNode) { - // this.node._sizeProvider = null; - // } - //}, - + _initSgNode: function () {}, + onEnable: function () { this._refreshStencil(); this._super(); @@ -177,7 +166,7 @@ var Mask = cc.Class({ var center = cc.v2(x + width /2, y+height/2); var radius = {x: width/2, y: height/2}; var segements = this._segements; - this._clippingStencil.drawPoly(this._calculateCircle(center,radius, segements), color, 0, color); + this._clippingStencil.drawPoly(this._calculateCircle(center, radius, segements), color, 0, color); } } }); diff --git a/cocos2d/core/components/CCRendererInSG.js b/cocos2d/core/components/CCRendererInSG.js index 9e37e363c4..4a10e44e9c 100644 --- a/cocos2d/core/components/CCRendererInSG.js +++ b/cocos2d/core/components/CCRendererInSG.js @@ -46,7 +46,7 @@ var RendererInSG = cc.Class({ // will be released in onDestroy this._sgNode.retain(); } - else { + else if (CC_EDITOR) { cc.error('Not support for asynchronous creating node in SG'); } @@ -55,17 +55,28 @@ var RendererInSG = cc.Class({ this._plainNode.retain(); }, + onLoad: function () { + this._initSgNode(); + if ( !this._sgNode.getContentSize().equals(cc.Size.ZERO) && CC_EDITOR ) { + cc.error('Renderer error: Size of the cc._RendererInSG._sgNode must be zero'); + } + }, + onEnable: function () { this._replaceSgNode(this._sgNode); - this.node._ignoreAnchor = true; + + // can not ignore anchor in render tree due to rotation bug which can't be fixed in JSB + // see https://github.com/cocos-creator/engine/pull/610 + //this.node._ignoreAnchor = true; }, + onDisable: function () { this._replaceSgNode(this._plainNode); - this.node._ignoreAnchor = false; + //this.node._ignoreAnchor = false; }, + onDestroy: function () { - this._super(); - + this._removeSgNode(); var releasedByNode = this.node._sgNode; if (this._plainNode !== releasedByNode) { this._plainNode.release(); diff --git a/cocos2d/core/components/CCRendererUnderSG.js b/cocos2d/core/components/CCRendererUnderSG.js index f28388d633..b7bed2a7c6 100644 --- a/cocos2d/core/components/CCRendererUnderSG.js +++ b/cocos2d/core/components/CCRendererUnderSG.js @@ -52,20 +52,33 @@ var RendererUnderSG = cc.Class({ // You should reimplement this function if your _sgNode maybe null. onLoad: function () { - this._super(); + this._initSgNode(); + var sgNode = this._sgNode; + if ( !this.node._sizeProvider ) { + this.node._sizeProvider = sgNode; + } this._appendSgNode(this._sgNode); }, + onEnable: function () { if (this._sgNode) { this._sgNode.setVisible(true); } }, + onDisable: function () { if (this._sgNode) { this._sgNode.setVisible(false); } }, + onDestroy: function () { + if ( this.node._sizeProvider === this._sgNode ) { + this.node._sizeProvider = null; + } + this._removeSgNode(); + }, + _appendSgNode: function (sgNode) { if ( !sgNode ) { return; diff --git a/cocos2d/core/components/CCSGComponent.js b/cocos2d/core/components/CCSGComponent.js index 594f23503b..986ab36173 100644 --- a/cocos2d/core/components/CCSGComponent.js +++ b/cocos2d/core/components/CCSGComponent.js @@ -51,19 +51,12 @@ var SGComponent = cc.Class({ } }, - onLoad: function () { - this._initSgNode(); - var sgNode = this._sgNode; - if ( !this.node._sizeProvider ) { - this.node._sizeProvider = sgNode; - } - }, - onDestroy: function () { - if ( this.node._sizeProvider === this._sgNode ) { - this.node._sizeProvider = null; - } - this._removeSgNode(); - }, + //onLoad: function () { + // this._initSgNode(); + //}, + //onDestroy: function () { + // this._removeSgNode(); + //}, /** * Create and returns your new scene graph node (SGNode) to add to scene graph. diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 397a04a6de..ac87c13730 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -2090,32 +2090,6 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * node.setLocalZOrder(1); */ -/* - * !#en - * Returns whether the anchor point will be ignored when you position this node.
- * When anchor point ignored, position will be calculated based on the origin point (0, 0) in parent's coordinates. - * !#zh - * 返回这个节点位置时,是否会忽略这个锚点。
- * 当锚点被忽略时,在父坐标系中的原点(0,0)计算位置。 - * @method isIgnoreAnchorPointForPosition - * @return {Boolean} true if the anchor point will be ignored when you position this node. - */ - -/* - * !#en - * Sets whether the anchor point will be ignored when you position this node.
- * When anchor point ignored, position will be calculated based on the origin point (0, 0) in parent's coordinates.
- * This is an internal method, only used by CCLayer and CCScene. Don't call it outside framework.
- * The default value is false, while in CCLayer and CCScene are true - * !#zh - * 设置抹点为(0,0)当你摆放这个节点的时候。 - * 这是一个内部方法,仅仅被 Layer 和 Scene 使用。不要在框架外调用。默认值是 false,但是在 Layer 和 Scene 中是 true. - * @method ignoreAnchorPointForPosition - * @param {Boolean} newValue - true if anchor point will be ignored when you position this node - * @example - * node.ignoreAnchorPointForPosition(true); - */ - /** * !#en Returns whether node's opacity value affect its child nodes. * !#zh 返回节点的不透明度值是否影响其子节点。 diff --git a/cocos2d/tilemap/CCTiledMap.js b/cocos2d/tilemap/CCTiledMap.js index f9c7610fec..c317d2fd01 100644 --- a/cocos2d/tilemap/CCTiledMap.js +++ b/cocos2d/tilemap/CCTiledMap.js @@ -569,6 +569,11 @@ var TiledMap = cc.Class({ }); }, + _resetSgSize: function () { + this.node.setContentSize(this._sgNode.getContentSize()); + this._sgNode.setContentSize(0, 0); + }, + _onMapLoaded: function(err) { this._isLoading = false; if ( !err ) { @@ -578,6 +583,7 @@ var TiledMap = cc.Class({ } else { this._moveLayersInSgNode(this._sgNode); } + this._resetSgSize(); } if (!CC_EDITOR) { diff --git a/test/qunit/unit/test-deserialize.js b/test/qunit/unit/test-deserialize.js index d7d8fe1b3d..4b8877dd63 100644 --- a/test/qunit/unit/test-deserialize.js +++ b/test/qunit/unit/test-deserialize.js @@ -83,7 +83,7 @@ if (TestEditorExtends) { var obj = { 'null': null, }; - var str = '{ "null": null }' + var str = '{ "null": null }'; deepEqual(cc.deserialize(str), obj, 'can deserialize null'); var MyAsset = cc.Class({ @@ -96,11 +96,11 @@ if (TestEditorExtends) { } }); - str = '{ "__type__": "MyAsset" }' + str = '{ "__type__": "MyAsset" }'; obj = new MyAsset(); deepEqual(cc.deserialize(str), obj, 'use default value'); - str = '{ "__type__": "MyAsset", "nil": null }' + str = '{ "__type__": "MyAsset", "nil": null }'; obj = new MyAsset(); obj.nil = null; deepEqual(cc.deserialize(str), obj, 'can override as null'); @@ -112,7 +112,7 @@ if (TestEditorExtends) { var obj = { 'null': null, }; - var str = '{ "null": null }' + var str = '{ "null": null }'; deepEqual(cc.deserialize(str, null, {target: null}), obj, 'can deserialize null'); }); From 56553d11dcc389c951baee26d8310fc16321de01 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 20 Apr 2016 14:07:23 +0800 Subject: [PATCH 05/20] working on loadResAll --- cocos2d/core/load-pipeline/CCLoader.js | 71 ++++++++++++- cocos2d/core/load-pipeline/asset-table.js | 123 +++------------------- cocos2d/core/platform/url.js | 6 +- test/qunit/assets/library/65/65341123490 | 16 --- test/qunit/unit/test-resources-loader.js | 24 ++++- 5 files changed, 110 insertions(+), 130 deletions(-) delete mode 100644 test/qunit/assets/library/65/65341123490 diff --git a/cocos2d/core/load-pipeline/CCLoader.js b/cocos2d/core/load-pipeline/CCLoader.js index 419f7e7109..c1a538702a 100644 --- a/cocos2d/core/load-pipeline/CCLoader.js +++ b/cocos2d/core/load-pipeline/CCLoader.js @@ -239,7 +239,6 @@ JS.mixin(cc.loader, { _resources: resources, _getResUuid: function (url) { - url = cc.url.normalize(url); var uuid = resources.getUuid(url); if ( !uuid ) { var extname = cc.path.extname(url); @@ -260,15 +259,15 @@ JS.mixin(cc.loader, { * * @method loadRes * @param {String} url - Url of the target resource. - * The url is relative to the "resources" folder, extensions must be omitted. + * The url is relative to the "resources" folder, extensions must be omitted. * @param {Function} completeCallback - Callback invoked when the resource loaded. * @param {Error} completeCallback.error - The error info or null if loaded successfully. * @param {Object} completeCallback.resource - The loaded resource if it can be found otherwise returns null. * * @example * - * // load the sprite frame (project/assets/resources/imgs/cocos.png/cocos) from resources folder with no extension - * cc.loader.loadRes('imgs/cocos/cocos', function (err, spriteFrame) { + * // load the sprite frame (project/assets/resources/imgs/cocos.png/cocos) from resources folder + * cc.loader.loadRes('imgs/cocos.png/cocos', function (err, spriteFrame) { * if (err) { * cc.error(err.message || err); * return; @@ -295,6 +294,70 @@ JS.mixin(cc.loader, { } }, + /** + * Load all assets in a folder inside the "assets/resources" folder of your project.
+ *
+ * Note: All asset urls in Creator use forward slashes, urls using backslashes will not work. + * + * @method loadResAll + * @param {String} url - Url of the target folder. + * The url is relative to the "resources" folder. + * @param {Function} completeCallback - A callback which is called when all assets have been loaded, or an error occurs. + * @param {Error} completeCallback.error - If one of the asset failed, the complete callback is immediately called with the error. If all assets are loaded successfully, error will be null. + * @param {Object[]} completeCallback.assets - An array of all loaded assets. If nothing to load, assets will be an empty array. If error occurs, assets will be null. + * + * @example + * + * // load the sprite frame (project/assets/resources/imgs/cocos.png/cocos) from resources folder + * cc.loader.loadResAll('imgs/cocos.png', function (err, assets) { + * if (err) { + * cc.error(err); + * return; + * } + * var texture = assets[0]; + * var spriteFrame = assets[1]; + * }); + */ + loadResAll: function (url, completeCallback) { + var uuids = resources.getUuidArray(url); + var remain = uuids.length; + if (remain > 0) { + var results = []; + var aborted = false; + function loaded (err, res) { + if (aborted) { + return; + } + if (err) { + aborted = true; + completeCallback(err, null); + return; + } + results.push(res); + --remain; + if (remain === 0) { + completeCallback(null, results); + } + } + for (var i = 0, len = remain; i < len; ++i) { + var uuid = uuids[i]; + this.load( + { + id: uuid, + type: 'uuid', + uuid: uuid + }, + loaded + ); + } + } + else { + callInNextTick(function () { + completeCallback.call(null, null, []); + }); + } + }, + /** * Get resource data by id.
* When you load resources with {{#crossLink "loader/load:method"}}{{/crossLink}} or {{#crossLink "loader/loadRes:method"}}{{/crossLink}}, diff --git a/cocos2d/core/load-pipeline/asset-table.js b/cocos2d/core/load-pipeline/asset-table.js index 499663d93d..00c3919be1 100644 --- a/cocos2d/core/load-pipeline/asset-table.js +++ b/cocos2d/core/load-pipeline/asset-table.js @@ -23,22 +23,6 @@ THE SOFTWARE. ****************************************************************************/ -var callInNextTick = require('./../platform/utils').callInNextTick; - -function normalizePath (path) { - if (path.charCodeAt(0) === 46 && path.charCodeAt(1) === 47) { - // strip './' - path = path.slice(2); - } - else if (path.charCodeAt(0) === 47) { - // strip '/' - path = path.slice(1); - } - return path; -} - -var GLOB = '**/*'; - /** * AssetTable is used to find asset's uuid by url * @class AssetTable @@ -47,9 +31,7 @@ var GLOB = '**/*'; function AssetTable () { this._pathToUuid = {}; } -AssetTable._hasWildcard = function (path) { - return path.endsWith(GLOB); -}; + cc.js.mixin(AssetTable.prototype, { ///** @@ -66,7 +48,7 @@ cc.js.mixin(AssetTable.prototype, { //}, getUuid: function (path) { - path = normalizePath(path); + path = cc.url.normalize(path); if ( !path ) { return ''; } @@ -74,22 +56,26 @@ cc.js.mixin(AssetTable.prototype, { if (uuid) { return uuid; } - else if (AssetTable._hasWildcard(path)) { - var uuids = []; - var pathNoWildcard = path.slice(0, - GLOB.length); - for (var p in this._pathToUuid) { - if (p.startsWith(pathNoWildcard)) { - var uuid = this._pathToUuid[p]; - uuids.push(uuid); - } - } - return uuids; - } else { return ''; } }, + getUuidArray: function (path) { + path = cc.url.normalize(path); + if ( !path ) { + return []; + } + var uuids = []; + var p2u = this._pathToUuid; + for (var p in p2u) { + if (p.startsWith(path)) { + uuids.push(p2u[p]); + } + } + return uuids; + }, + /** * Returns all asset paths in the table. * @method getAllPaths @@ -98,81 +84,6 @@ cc.js.mixin(AssetTable.prototype, { getAllPaths: function () { return Object.keys(this._pathToUuid); }, - - //_loadByWildcard: function (path, callback) { - // var results = []; - // var remain = 0; - // var aborted = false; - // function onLoad (err, asset) { - // if (aborted) { - // return; - // } - // if (asset) { - // results.push(asset); - // if (--remain <= 0) { - // callback(null, results); - // } - // } - // else { - // aborted = true; - // callback(err, results); - // callback = null; - // } - // } - // - // var pathNoWildcard = path.slice(0, - GLOB.length); - // for (var p in this._pathToUuid) { - // if (p.startsWith(pathNoWildcard)) { - // ++remain; - // var uuid = this._pathToUuid[p]; - // cc.AssetLibrary.loadAsset(uuid, onLoad); - // } - // } - // return remain > 0; - //}, - - ///** - // * Loads asset with path from the table asynchronously.
- // *
- // * wildcard:
- // * 如果路径以 **/* 作为结尾,则该路径下的所有资源都会被加载,含子文件夹。 - // * 此时 callback 的第二参数将返回数组,如果文件夹下没有资源,数组长度将会是 0。如果加载出错,数组内的元素将不全。 - // * - // * Note: All asset paths in Creator use forward slashes, paths using backslashes will not work. - // * - // * @method load - // * @param {string} path - // * @param {function} [callback] - // * @param {string} callback.param error - null or the error info - // * @param {object} callback.param data - the loaded object or null - // * @param {boolean} [quiet=false] - If true, the callback will not invoked even if asset is not found. - // * @return {boolean} start loading - // */ - //load: function (path, callback, quiet) { - // if ( !path ) { - // if ( !quiet ) { - // callInNextTick(callback, 'Argument must be non-nil', null); - // } - // return false; - // } - // path = normalizePath(path); - // var uuid = this._pathToUuid[path]; - // if (uuid) { - // AssetLibrary.loadAsset(uuid, callback); - // return true; - // } - // else if (AssetTable._hasWildcard(path)) { - // var loading = this._loadByWildcard(path, callback); - // if ( !loading && !quiet ) { - // callInNextTick(callback, null, []); - // } - // return loading; - // } - // else if (! quiet) { - // callInNextTick(callback, 'Path not exists', null); - // return false; - // } - //}, /** * @method add diff --git a/cocos2d/core/platform/url.js b/cocos2d/core/platform/url.js index b23432da8f..6614858134 100644 --- a/cocos2d/core/platform/url.js +++ b/cocos2d/core/platform/url.js @@ -49,10 +49,12 @@ cc.url = { _builtinRawAssets: '', normalize: function (url) { - if (url[0] === '.' && url[1] === '/') { + if (url.charCodeAt(0) === 46 && url.charCodeAt(1) === 47) { + // strip './' url = url.slice(2); } - else if (url[0] === '/') { + else if (url.charCodeAt(0) === 47) { + // strip '/' url = url.slice(1); } return url; diff --git a/test/qunit/assets/library/65/65341123490 b/test/qunit/assets/library/65/65341123490 deleted file mode 100644 index bd1d617d68..0000000000 --- a/test/qunit/assets/library/65/65341123490 +++ /dev/null @@ -1,16 +0,0 @@ -{ - "__type__": "TestSprite", - "rawTexture": null, - "texture": { - "__uuid__": "6545543" - }, - "rotated": false, - "trim": false, - "trimThreshold": 1, - "trimLeft": 10, - "trimTop": 20, - "width": 89, - "height": 44, - "x": 0, - "y": 49 -} \ No newline at end of file diff --git a/test/qunit/unit/test-resources-loader.js b/test/qunit/unit/test-resources-loader.js index 93e4aa0547..d9b92c73c6 100644 --- a/test/qunit/unit/test-resources-loader.js +++ b/test/qunit/unit/test-resources-loader.js @@ -8,7 +8,8 @@ rawAssetsBase: cc.path.dirname(cc.path._setEndWithSep(assetDir, false) + '.dummyExtForDirname') + '/', rawAssets: { assets: { - '748321': { url: 'resources/grossini.png', raw: true } + '748321': { url: 'resources/grossini.png', raw: true }, + '1232218': { url: 'resources/grossini.png/grossini', raw: false } } } }); @@ -18,7 +19,26 @@ asyncTest('load single', function () { cc.loader.releaseAll(); cc.loader.loadRes('grossini.png', function (err, texture) { - ok(texture instanceof cc.Texture2D, 'should be able to load texture without file extname'); + ok(texture instanceof cc.Texture2D, 'should be able to load texture with file extname'); + clearTimeout(timeoutId); + start(); + }); + + var timeoutId = setTimeout(function () { + ok(false, 'time out!'); + start(); + }, 5000); + }); + + asyncTest('load main asset and sub asset by loadAll', function () { + cc.loader.releaseAll(); + cc.loader.loadResAll('grossini.png', function (err, results) { + ok(Array.isArray(results), 'result should be an array'); + var texture = results[0] instanceof cc.Texture2D ? results[0] : results[1]; + var sprite = results[0] instanceof TestSprite ? results[0] : results[1]; + ok(texture instanceof cc.Texture2D, 'should be able to load texture'); + ok(sprite instanceof TestSprite, 'should be able to load test sprite'); + clearTimeout(timeoutId); start(); }); From 6b86b638ec49728b2ea5fd897ef45efa411a673b Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Fri, 22 Apr 2016 10:15:20 +0800 Subject: [PATCH 06/20] add distortion sprite --- cocos2d/core/components/CCSpriteDistortion.js | 91 +++++++++++++++++++ cocos2d/core/components/index.js | 1 + cocos2d/core/sprites/CCScale9Sprite.js | 5 +- .../sprites/CCScale9SpriteWebGLRenderCmd.js | 59 +++++++++++- 4 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 cocos2d/core/components/CCSpriteDistortion.js diff --git a/cocos2d/core/components/CCSpriteDistortion.js b/cocos2d/core/components/CCSpriteDistortion.js new file mode 100644 index 0000000000..4af490fef1 --- /dev/null +++ b/cocos2d/core/components/CCSpriteDistortion.js @@ -0,0 +1,91 @@ +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Chukong Aipu reserves all rights not expressly granted to you. + + 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. + ****************************************************************************/ + +/** + * !#en A distortion used to change the rendering of simple sprite.If will take effect after sprite component is added. + * !#zh 扭曲效果组件,用于改变SIMPLE类型sprite的渲染,只有当sprite组件已经添加后,才能起作用. + * @class SpriteDistortion + * @extends Component + * @example + * // Create a new node and add sprite components. + * var node = new cc.Node("New Sprite"); + * var sprite = node.addComponent(cc.Sprite); + * var spriteDistortion = node.addComponent(cc.SpriteDistortion); + * node.parent = this.node; + */ + +var SpriteDistortion = cc.Class({ + name: 'cc.SpriteDistortion', extends: require('./CCComponent'), + editor: CC_EDITOR && { + menu: 'i18n:MAIN_MENU.component.renderers/SpriteDistortion', + executeInEditMode: true, + }, + + ctor: function() { + this._distortionOffset = cc.v2(0.0,0.0); + this._spriteSGNode = null; + }, + + properties: { + /** + * !#en Change the UV offset for distortion rendering. + * !#zh 在渲染时改变UV的整体偏移. + * @property offset + * @type {Vec2} + * @example + * distortion.offset = new cc.Vec2(0.5, 0.3);; + */ + offset: { + get: function() { + return this._distortionOffset; + }, + set:function(value) { + this._distortionOffset.x = value.x; + this._distortionOffset.y = value.y; + } + }, + + }, + + onEnable: function () { + var sprite = this.node.getComponent('cc.Sprite'); + var sgNode = this._spriteSGNode = sprite && sprite._sgNode; + if(this._spriteSGNode) { + sgNode.setState(cc.Scale9Sprite.state.DISTORTION); + sgNode._distortionOffset = this._distortionOffset; + } + }, + + onDisable: function () { + if(this._spriteSGNode) { + this._spriteSGNode.setState(cc.Scale9Sprite.state.NORMAL); + } + + this._spriteSGNode = null; + }, + +}); + +cc.SpriteDistortion = module.exports = SpriteDistortion; diff --git a/cocos2d/core/components/index.js b/cocos2d/core/components/index.js index 027a97c615..e246995f45 100644 --- a/cocos2d/core/components/index.js +++ b/cocos2d/core/components/index.js @@ -43,4 +43,5 @@ module.exports = [ require('./CCScrollView'), require('./CCLayout'), require('./CCEditBox'), + require('./CCSpriteDistortion'), ]; diff --git a/cocos2d/core/sprites/CCScale9Sprite.js b/cocos2d/core/sprites/CCScale9Sprite.js index 1fd624cb4f..c50122d1d6 100644 --- a/cocos2d/core/sprites/CCScale9Sprite.js +++ b/cocos2d/core/sprites/CCScale9Sprite.js @@ -874,7 +874,8 @@ cc.Scale9Sprite = _ccsg.Node.extend({ //normalized filled start and range _fillStart: 0, _fillRange: Math.PI * 2, - + _distortionOffset: null, + ctor: function (textureOrSpriteFrame) { _ccsg.Node.prototype.ctor.call(this); this._renderCmd.setState(this._brightState); @@ -1249,7 +1250,7 @@ cc.defineGetterSetter(_p, "insetBottom", _p.getInsetBottom, _p.setInsetBottom); _p = null; -cc.Scale9Sprite.state = {NORMAL: 0, GRAY: 1}; +cc.Scale9Sprite.state = {NORMAL: 0, GRAY: 1, DISTORTION: 2}; /** * Enum for sprite type diff --git a/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js b/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js index 6d71fb7836..d7c482bb47 100644 --- a/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js +++ b/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js @@ -64,7 +64,10 @@ if (_ccsg.Node.WebGLRenderCmd) { { this._shaderProgram.use(); this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix); - + if(this._shaderProgram === cc.Scale9Sprite.WebGLRenderCmd._distortionProgram && this._node._distortionOffset) { + this._shaderProgram.setUniformLocationWith2f(cc.Scale9Sprite.WebGLRenderCmd._distortionLocation, + this._node._distortionOffset.x, this._node._distortionOffset.y); + } ccgl.blendFunc(node._blendFunc.src, node._blendFunc.dst); //optimize performance for javascript ccgl.bindTexture2DN(0, locTexture); // = cc.gl.bindTexture2D(locTexture); @@ -139,6 +142,8 @@ if (_ccsg.Node.WebGLRenderCmd) { node.setShaderProgram(cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR)); } else if (state === cc.Scale9Sprite.state.GRAY) { node.setShaderProgram(cc.Scale9Sprite.WebGLRenderCmd._getGrayShaderProgram()); + } else if (state === cc.Scale9Sprite.state.DISTORTION) { + node.setShaderProgram(cc.Scale9Sprite.WebGLRenderCmd._getDistortionProgram()); } }; @@ -170,4 +175,56 @@ if (_ccsg.Node.WebGLRenderCmd) { + " gl_FragColor.xyz = vec3(0.2126*c.r + 0.7152*c.g + 0.0722*c.b); \n" +" gl_FragColor.w = c.w ; \n" + "}"; + + cc.Scale9Sprite.WebGLRenderCmd._distortionProgram = null; + cc.Scale9Sprite.WebGLRenderCmd._getDistortionProgram = function(){ + var shader = cc.Scale9Sprite.WebGLRenderCmd._distortionProgram; + if(shader) + return shader; + + shader = new cc.GLProgram(); + shader.initWithVertexShaderByteArray(cc.PresetShaders.POSITION_TEXTURE_COLOR_VERT, distortionSpriteShader.fShader); + shader.addAttribute(cc.macro.ATTRIBUTE_NAME_POSITION, cc.macro.VERTEX_ATTRIB_POSITION); + shader.addAttribute(cc.macro.ATTRIBUTE_NAME_COLOR, cc.macro.VERTEX_ATTRIB_COLOR); + shader.addAttribute(cc.macro.ATTRIBUTE_NAME_TEX_COORD, cc.macro.VERTEX_ATTRIB_TEX_COORDS); + shader.link(); + shader.updateUniforms(); + + cc.Scale9Sprite.WebGLRenderCmd._distortionProgram = shader; + cc.Scale9Sprite.WebGLRenderCmd._distortionLocation = shader.getUniformLocationForName('u_offset'); + return shader; + }; + + var distortionSpriteShader = { + }; + distortionSpriteShader.shaderKey = 'cc.Sprite.Shader.Distortion'; + distortionSpriteShader.fShader = "precision lowp float;\n" + + "varying vec4 v_fragmentColor; \n" + + "varying vec2 v_texCoord; \n" + + "uniform vec2 u_offset; \n" + + "const float PI = 3.14159265359;\n" + + "void main() \n" + + "{ \n" + + "float halfPI = 0.5 * PI;\n" + + "float maxFactor = sin(halfPI);\n" + + "vec2 uv = v_texCoord;\n" + + "vec2 xy = 2.0 * uv.xy - 1.0;\n" + + "float d = length(xy);\n" + + "if (d < (2.0-maxFactor)) {\n" + + "d = length(xy * maxFactor);\n" + + "float z = sqrt(1.0 - d * d);\n" + + " float r = atan(d, z) / PI;\n" + + "float phi = atan(xy.y, xy.x);\n" + + "uv.x = r * cos(phi) + 0.5;\n" + + "uv.y = r * sin(phi) + 0.5;\n" + + "} else {\n" + + "discard;\n" + + "}\n" + + "uv.x /= 0.5;\n" + + "uv.y /= 0.5;\n" + + "uv.x += u_offset.x;\n" + + "uv.y += u_offset.y;\n" + + "uv = fract(uv); \n" + + "gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, uv);\n" + + "}"; } From 05eaea537ef4b258d39aa843e1d0363c6529380e Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Fri, 22 Apr 2016 10:48:13 +0800 Subject: [PATCH 07/20] add sprite dependency for sprite distortion --- cocos2d/core/components/CCSpriteDistortion.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos2d/core/components/CCSpriteDistortion.js b/cocos2d/core/components/CCSpriteDistortion.js index 4af490fef1..19b5344151 100644 --- a/cocos2d/core/components/CCSpriteDistortion.js +++ b/cocos2d/core/components/CCSpriteDistortion.js @@ -41,6 +41,7 @@ var SpriteDistortion = cc.Class({ editor: CC_EDITOR && { menu: 'i18n:MAIN_MENU.component.renderers/SpriteDistortion', executeInEditMode: true, + requireComponent: cc.Sprite, }, ctor: function() { From b746266448768cfa2f6510f188e5f164075fd38b Mon Sep 17 00:00:00 2001 From: Nan Wang Date: Fri, 22 Apr 2016 10:56:16 +0800 Subject: [PATCH 08/20] fix api typo --- cocos2d/core/components/CCLabel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index 7120f65815..7854430dfb 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -191,7 +191,7 @@ var Label = cc.Class({ /** * !#en Overflow of label. * !#zh 文字显示超出范围时的处理方式。 - * @property {Label.Overflow} overFlow + * @property {Label.Overflow} overflow */ overflow: { default: Overflow.NONE, From 9e61f7fe4e2bcfc944494c5843dd1c8fd9cdc7b8 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Fri, 22 Apr 2016 10:56:18 +0800 Subject: [PATCH 09/20] minor fix --- cocos2d/core/components/CCRendererInSG.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/components/CCRendererInSG.js b/cocos2d/core/components/CCRendererInSG.js index 4a10e44e9c..4777f05905 100644 --- a/cocos2d/core/components/CCRendererInSG.js +++ b/cocos2d/core/components/CCRendererInSG.js @@ -57,8 +57,12 @@ var RendererInSG = cc.Class({ onLoad: function () { this._initSgNode(); - if ( !this._sgNode.getContentSize().equals(cc.Size.ZERO) && CC_EDITOR ) { - cc.error('Renderer error: Size of the cc._RendererInSG._sgNode must be zero'); + if (CC_EDITOR) { + var sgSize = this._sgNode.getContentSize(); + // sgSize is not a Vec2 in JSB + if (sgSize.x !== 0 || sgSize.y !== 0) { + cc.error('Renderer error: Size of the cc._RendererInSG._sgNode must be zero'); + } } }, From 68ca51085f07cb6b9d26f384f02242d55a76c7a9 Mon Sep 17 00:00:00 2001 From: Johnny Wu Date: Mon, 25 Apr 2016 10:20:11 +0800 Subject: [PATCH 10/20] add distortion scale --- cocos2d/core/components/CCSpriteDistortion.js | 23 +++++++++++++++++++ cocos2d/core/sprites/CCScale9Sprite.js | 1 + .../sprites/CCScale9SpriteWebGLRenderCmd.js | 19 +++++++++------ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/cocos2d/core/components/CCSpriteDistortion.js b/cocos2d/core/components/CCSpriteDistortion.js index 19b5344151..7497d303c6 100644 --- a/cocos2d/core/components/CCSpriteDistortion.js +++ b/cocos2d/core/components/CCSpriteDistortion.js @@ -46,6 +46,7 @@ var SpriteDistortion = cc.Class({ ctor: function() { this._distortionOffset = cc.v2(0.0,0.0); + this._distortionScale = cc.v2(1.0,1.0); this._spriteSGNode = null; }, @@ -70,12 +71,34 @@ var SpriteDistortion = cc.Class({ }, + properties: { + /** + * !#en Change the UV offset for distortion rendering. + * !#zh 在渲染时改变UV的整体偏移. + * @property offset + * @type {Vec2} + * @example + * distortion.scale = new cc.Vec2(0.5, 0.3);; + */ + scale: { + get: function() { + return this._distortionScale; + }, + set:function(value) { + this._distortionScale.x = value.x; + this._distortionScale.y = value.y; + } + }, + + }, + onEnable: function () { var sprite = this.node.getComponent('cc.Sprite'); var sgNode = this._spriteSGNode = sprite && sprite._sgNode; if(this._spriteSGNode) { sgNode.setState(cc.Scale9Sprite.state.DISTORTION); sgNode._distortionOffset = this._distortionOffset; + sgNode._distortionScale = this._distortionScale; } }, diff --git a/cocos2d/core/sprites/CCScale9Sprite.js b/cocos2d/core/sprites/CCScale9Sprite.js index c50122d1d6..b007685c11 100644 --- a/cocos2d/core/sprites/CCScale9Sprite.js +++ b/cocos2d/core/sprites/CCScale9Sprite.js @@ -875,6 +875,7 @@ cc.Scale9Sprite = _ccsg.Node.extend({ _fillStart: 0, _fillRange: Math.PI * 2, _distortionOffset: null, + _distortionScale: null, ctor: function (textureOrSpriteFrame) { _ccsg.Node.prototype.ctor.call(this); diff --git a/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js b/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js index d7c482bb47..ba3a3af780 100644 --- a/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js +++ b/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js @@ -65,8 +65,14 @@ if (_ccsg.Node.WebGLRenderCmd) { this._shaderProgram.use(); this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix); if(this._shaderProgram === cc.Scale9Sprite.WebGLRenderCmd._distortionProgram && this._node._distortionOffset) { - this._shaderProgram.setUniformLocationWith2f(cc.Scale9Sprite.WebGLRenderCmd._distortionLocation, - this._node._distortionOffset.x, this._node._distortionOffset.y); + this._shaderProgram.setUniformLocationWith2f( + cc.Scale9Sprite.WebGLRenderCmd._distortionOffset, + this._node._distortionOffset.x, this._node._distortionOffset.y + ); + this._shaderProgram.setUniformLocationWith2f( + cc.Scale9Sprite.WebGLRenderCmd._distortionScale, + this._node._distortionScale.x, this._node._distortionScale.y + ); } ccgl.blendFunc(node._blendFunc.src, node._blendFunc.dst); //optimize performance for javascript @@ -191,7 +197,8 @@ if (_ccsg.Node.WebGLRenderCmd) { shader.updateUniforms(); cc.Scale9Sprite.WebGLRenderCmd._distortionProgram = shader; - cc.Scale9Sprite.WebGLRenderCmd._distortionLocation = shader.getUniformLocationForName('u_offset'); + cc.Scale9Sprite.WebGLRenderCmd._distortionOffset = shader.getUniformLocationForName('u_offset'); + cc.Scale9Sprite.WebGLRenderCmd._distortionScale = shader.getUniformLocationForName('u_offset_scale'); return shader; }; @@ -202,6 +209,7 @@ if (_ccsg.Node.WebGLRenderCmd) { + "varying vec4 v_fragmentColor; \n" + "varying vec2 v_texCoord; \n" + "uniform vec2 u_offset; \n" + + "uniform vec2 u_offset_scale; \n" + "const float PI = 3.14159265359;\n" + "void main() \n" + "{ \n" @@ -220,10 +228,7 @@ if (_ccsg.Node.WebGLRenderCmd) { + "} else {\n" + "discard;\n" + "}\n" - + "uv.x /= 0.5;\n" - + "uv.y /= 0.5;\n" - + "uv.x += u_offset.x;\n" - + "uv.y += u_offset.y;\n" + + "uv = uv * u_offset_scale + u_offset;\n" + "uv = fract(uv); \n" + "gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, uv);\n" + "}"; From 41ca344fe1b2cfa3463f191eaba98e650bcad3ab Mon Sep 17 00:00:00 2001 From: Johnny Wu Date: Mon, 25 Apr 2016 10:30:01 +0800 Subject: [PATCH 11/20] fix properties define syntax error --- cocos2d/core/components/CCSpriteDistortion.js | 24 ++++++++----------- cocos2d/core/sprites/CCScale9Sprite.js | 4 ++-- .../sprites/CCScale9SpriteWebGLRenderCmd.js | 10 ++++---- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/cocos2d/core/components/CCSpriteDistortion.js b/cocos2d/core/components/CCSpriteDistortion.js index 7497d303c6..3e81563f5d 100644 --- a/cocos2d/core/components/CCSpriteDistortion.js +++ b/cocos2d/core/components/CCSpriteDistortion.js @@ -46,7 +46,7 @@ var SpriteDistortion = cc.Class({ ctor: function() { this._distortionOffset = cc.v2(0.0,0.0); - this._distortionScale = cc.v2(1.0,1.0); + this._distortionTiling = cc.v2(1.0,1.0); this._spriteSGNode = null; }, @@ -69,27 +69,23 @@ var SpriteDistortion = cc.Class({ } }, - }, - - properties: { /** - * !#en Change the UV offset for distortion rendering. - * !#zh 在渲染时改变UV的整体偏移. - * @property offset + * !#en Change the UV scale for distortion rendering. + * !#zh 在渲染时改变UV的寻址系数 + * @property tiling * @type {Vec2} * @example - * distortion.scale = new cc.Vec2(0.5, 0.3);; + * distortion.tiling = new cc.Vec2(0.5, 0.3);; */ - scale: { + tiling: { get: function() { - return this._distortionScale; + return this._distortionTiling; }, set:function(value) { - this._distortionScale.x = value.x; - this._distortionScale.y = value.y; + this._distortionTiling.x = value.x; + this._distortionTiling.y = value.y; } }, - }, onEnable: function () { @@ -98,7 +94,7 @@ var SpriteDistortion = cc.Class({ if(this._spriteSGNode) { sgNode.setState(cc.Scale9Sprite.state.DISTORTION); sgNode._distortionOffset = this._distortionOffset; - sgNode._distortionScale = this._distortionScale; + sgNode._distortionTiling = this._distortionTiling; } }, diff --git a/cocos2d/core/sprites/CCScale9Sprite.js b/cocos2d/core/sprites/CCScale9Sprite.js index b007685c11..255ccaa790 100644 --- a/cocos2d/core/sprites/CCScale9Sprite.js +++ b/cocos2d/core/sprites/CCScale9Sprite.js @@ -875,8 +875,8 @@ cc.Scale9Sprite = _ccsg.Node.extend({ _fillStart: 0, _fillRange: Math.PI * 2, _distortionOffset: null, - _distortionScale: null, - + _distortionTiling: null, + ctor: function (textureOrSpriteFrame) { _ccsg.Node.prototype.ctor.call(this); this._renderCmd.setState(this._brightState); diff --git a/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js b/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js index ba3a3af780..6d63790753 100644 --- a/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js +++ b/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js @@ -70,8 +70,8 @@ if (_ccsg.Node.WebGLRenderCmd) { this._node._distortionOffset.x, this._node._distortionOffset.y ); this._shaderProgram.setUniformLocationWith2f( - cc.Scale9Sprite.WebGLRenderCmd._distortionScale, - this._node._distortionScale.x, this._node._distortionScale.y + cc.Scale9Sprite.WebGLRenderCmd._distortionTiling, + this._node._distortionTiling.x, this._node._distortionTiling.y ); } ccgl.blendFunc(node._blendFunc.src, node._blendFunc.dst); @@ -198,7 +198,7 @@ if (_ccsg.Node.WebGLRenderCmd) { cc.Scale9Sprite.WebGLRenderCmd._distortionProgram = shader; cc.Scale9Sprite.WebGLRenderCmd._distortionOffset = shader.getUniformLocationForName('u_offset'); - cc.Scale9Sprite.WebGLRenderCmd._distortionScale = shader.getUniformLocationForName('u_offset_scale'); + cc.Scale9Sprite.WebGLRenderCmd._distortionTiling = shader.getUniformLocationForName('u_offset_tiling'); return shader; }; @@ -209,7 +209,7 @@ if (_ccsg.Node.WebGLRenderCmd) { + "varying vec4 v_fragmentColor; \n" + "varying vec2 v_texCoord; \n" + "uniform vec2 u_offset; \n" - + "uniform vec2 u_offset_scale; \n" + + "uniform vec2 u_offset_tiling; \n" + "const float PI = 3.14159265359;\n" + "void main() \n" + "{ \n" @@ -228,7 +228,7 @@ if (_ccsg.Node.WebGLRenderCmd) { + "} else {\n" + "discard;\n" + "}\n" - + "uv = uv * u_offset_scale + u_offset;\n" + + "uv = uv * u_offset_tiling + u_offset;\n" + "uv = fract(uv); \n" + "gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, uv);\n" + "}"; From 481e5c3c605f54cf074f34a1d6cacb3b887ae469 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Mon, 25 Apr 2016 13:51:10 +0800 Subject: [PATCH 12/20] fix atlases sprite display bug --- jsb/jsb-tex-sprite-frame.js | 71 ++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/jsb/jsb-tex-sprite-frame.js b/jsb/jsb-tex-sprite-frame.js index 26d0563ede..7ad3821438 100644 --- a/jsb/jsb-tex-sprite-frame.js +++ b/jsb/jsb-tex-sprite-frame.js @@ -66,37 +66,58 @@ cc.SpriteFrame.prototype._ctor = function (filename, rect, rotated, offset, orig }; cc.SpriteFrame.prototype._initWithTexture = cc.SpriteFrame.prototype.initWithTexture; -cc.SpriteFrame.prototype.initWithTexture = function (textureOrTextureFile, rect, rotated, offset, originalSize) { - this.setTexture(textureOrTextureFile, rect, rotated, offset, originalSize); +cc.SpriteFrame.prototype.initWithTexture = function (texture, rect, rotated, offset, originalSize, _uuid) { + this.setTexture(texture, rect, rotated, offset, originalSize, _uuid); }; -cc.SpriteFrame.prototype.setTexture = function (textureOrTextureFile, rect, rotated, offset, originalSize) { - var texture = textureOrTextureFile; +cc.SpriteFrame.prototype.setTexture = function (textureOrTextureFile, rect, rotated, offset, originalSize, _uuid) { - if (cc.js.isString(texture)){ - this._textureFilename = texture; - texture = cc.textureCache.addImage(texture); + var localTexture; + if (!textureOrTextureFile && _uuid) { + // deserialize texture from uuid + var info = cc.AssetLibrary._getAssetInfoInRuntime(_uuid); + if (!info) { + cc.error('SpriteFrame: Failed to load sprite texture "%s"', _uuid); + return false; + } + + this._textureFilename = info.url; + + localTexture = cc.textureCache.addImage(info.url); } - - if (texture instanceof cc.Texture2D) { - if (texture && texture.isLoaded()) { - - if (rect) { - this._checkRect(texture); - } - else { - rect = cc.rect(0, 0, texture.width, texture.height); - } - - offset = offset || cc.p(0, 0); - originalSize = originalSize || rect; - rotated = rotated || false; - - this._initWithTexture(texture, rect, rotated, offset, originalSize); - - this.emit('load'); + else { + if (cc.js.isString(textureOrTextureFile)) { + this._textureFilename = textureOrTextureFile; + localTexture = cc.textureCache.addImage(textureOrTextureFile); + } + else if (textureOrTextureFile instanceof cc.Texture2D) { + this._textureFilename = ""; + localTexture = textureOrTextureFile; } } + + if (localTexture instanceof cc.Texture2D && localTexture.isLoaded()) { + + if (!rect) { + rect = cc.rect(0, 0, localTexture.getPixelWidth(), localTexture.getPixelHeight()); + } + + offset = offset || cc.p(0, 0); + originalSize = originalSize || rect; + rotated = rotated || false; + + if (this.insetTop === undefined) { + this.insetTop = 0; + this.insetBottom = 0; + this.insetLeft = 0; + this.insetRight = 0; + } + + this._initWithTexture(localTexture, rect, rotated, offset, originalSize); + } + + this.emit('load'); + this._checkRect(this.getTexture()); return true; }; From 02d5cbec0170057da6275dc5e163eb1a2ff86ca6 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Mon, 25 Apr 2016 16:21:42 +0800 Subject: [PATCH 13/20] Synchronization spriteFrame web and jsb code --- jsb/jsb-tex-sprite-frame.js | 137 ++++++++++++++++++------------------ 1 file changed, 68 insertions(+), 69 deletions(-) diff --git a/jsb/jsb-tex-sprite-frame.js b/jsb/jsb-tex-sprite-frame.js index 7ad3821438..e89281b379 100644 --- a/jsb/jsb-tex-sprite-frame.js +++ b/jsb/jsb-tex-sprite-frame.js @@ -66,67 +66,85 @@ cc.SpriteFrame.prototype._ctor = function (filename, rect, rotated, offset, orig }; cc.SpriteFrame.prototype._initWithTexture = cc.SpriteFrame.prototype.initWithTexture; -cc.SpriteFrame.prototype.initWithTexture = function (texture, rect, rotated, offset, originalSize, _uuid) { - this.setTexture(texture, rect, rotated, offset, originalSize, _uuid); +cc.SpriteFrame.prototype.initWithTexture = function (texture, rect, rotated, offset, originalSize) { + this.setTexture(texture, rect, rotated, offset, originalSize); }; -cc.SpriteFrame.prototype.setTexture = function (textureOrTextureFile, rect, rotated, offset, originalSize, _uuid) { +cc.SpriteFrame.prototype.setTexture = function (textureOrTextureFile, rect, rotated, offset, originalSize) { - var localTexture; - if (!textureOrTextureFile && _uuid) { - // deserialize texture from uuid - var info = cc.AssetLibrary._getAssetInfoInRuntime(_uuid); - if (!info) { - cc.error('SpriteFrame: Failed to load sprite texture "%s"', _uuid); - return false; - } + if (rect) { + this.setRect(rect); + } - this._textureFilename = info.url; + if (offset) { + this.setOffset(offset); + } - localTexture = cc.textureCache.addImage(info.url); + if (originalSize) { + this.setOriginalSize(originalSize); + } + + this.setRotated(rotated || false); + + var texture = textureOrTextureFile; + if (cc.js.isString(textureOrTextureFile)) { + this._textureFilename = textureOrTextureFile; + texture = cc.textureCache.addImage(textureOrTextureFile); + } + + if (texture instanceof cc.Texture2D) { + this._refreshTexture(texture); } else { - if (cc.js.isString(textureOrTextureFile)) { - this._textureFilename = textureOrTextureFile; - localTexture = cc.textureCache.addImage(textureOrTextureFile); - } - else if (textureOrTextureFile instanceof cc.Texture2D) { - this._textureFilename = ""; - localTexture = textureOrTextureFile; - } + //todo log error } - if (localTexture instanceof cc.Texture2D && localTexture.isLoaded()) { - - if (!rect) { - rect = cc.rect(0, 0, localTexture.getPixelWidth(), localTexture.getPixelHeight()); - } - - offset = offset || cc.p(0, 0); - originalSize = originalSize || rect; - rotated = rotated || false; - - if (this.insetTop === undefined) { - this.insetTop = 0; - this.insetBottom = 0; - this.insetLeft = 0; - this.insetRight = 0; - } - - this._initWithTexture(localTexture, rect, rotated, offset, originalSize); - } - - this.emit('load'); - this._checkRect(this.getTexture()); return true; }; +cc.SpriteFrame.prototype._refreshTexture = function (texture) { + + if (this.getTexture() !== texture) { + + var w = texture.width, h = texture.height; + + var rect = this.getRect(); + if (rect.width === 0 || rect.height === 0) { + rect = cc.rect(0, 0, w, h); + } + else { + this._checkRect(texture); + } + + var originalSize = this.getOriginalSize(); + if (originalSize.width === 0 || originalSize.height === 0) { + originalSize = cc.size(w, h); + } + + var offset = this.getOffset(); + var rotated = this.isRotated(); + + this._initWithTexture(texture, rect, rotated, offset, originalSize); + + //dispatch 'load' event of cc.SpriteFrame + this.emit("load"); + } +}; + cc.SpriteFrame.prototype._deserialize = function (data, handle) { - var rect = data.rect ? new cc.Rect(data.rect[0], data.rect[1], data.rect[2], data.rect[3]) : undefined; - var offset = data.offset ? new cc.Vec2(data.offset[0], data.offset[1]) : undefined; - var size = data.originalSize ? new cc.Size(data.originalSize[0], data.originalSize[1]) : undefined; - var rotated = data.rotated === 1; - // init properties not included in this._initWithTexture() + var rect = data.rect; + if (rect) { + this.setRect(new cc.Rect(rect[0], rect[1], rect[2], rect[3])); + } + if (data.offset) { + this.setOffset(new cc.Vec2(data.offset[0], data.offset[1])); + } + if (data.originalSize) { + this.setOriginalSize(new cc.Size(data.originalSize[0], data.originalSize[1])); + } + + this.setRotated(data.rotated === 1); + this._name = data.name; var capInsets = data.capInsets; if (capInsets) { @@ -141,8 +159,6 @@ cc.SpriteFrame.prototype._deserialize = function (data, handle) { if (textureUuid) { handle.result.push(this, '_textureFilenameSetter', textureUuid); } - - this.initWithTexture(null, rect, rotated, offset, size, textureUuid); }; cc.SpriteFrame.prototype._checkRect = function (texture) { var rect = this.getRect(); @@ -171,25 +187,8 @@ cc.SpriteFrame.prototype.getTexture = function () { cc.js.set(cc.SpriteFrame.prototype, '_textureFilenameSetter', function (url) { this._textureFilename = url; if (url) { - cc.textureCache.addImage(url, function (texture) { - if (this.getTexture() !== texture) { - this.setTexture(texture); - var w = texture.getPixelWidth(), h = texture.getPixelHeight(); - if (this.getRect().width === 0) { - this.setRect(cc.rect(0, 0, w, h)); - } - if (this.getOriginalSize().width === 0) { - this.setOriginalSize(cc.size(w, h)); - } - if (this.getOffset().width === 0) { - this.setOffset(cc.v2(0, 0)); - } - - this._texture = texture; - } - this._checkRect(texture); - this.emit('load'); - }, this); + var texture = cc.textureCache.addImage(url); + this._refreshTexture(texture); } }); From 4fceb870d740013474876c081a1b23fd81f34613 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 25 Apr 2016 17:02:34 +0800 Subject: [PATCH 14/20] hide pushScene in doc --- cocos2d/core/CCDirector.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index ef2a283ce2..8e246225f9 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -361,7 +361,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ this._paused = true; }, - /** + /* * Pops out a scene from the queue.
* This scene will replace the running one.
* The running scene will be deleted. If there are no more scenes in the stack the execution is terminated.
@@ -450,7 +450,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ this.startAnimation(); }, - /** + /* * Suspends the execution of the running scene, pushing it on the stack of suspended scenes.
* The new scene will be executed.
* Try to avoid big stacks of pushed scenes to reduce memory allocation.
From 823780ddf60bafe5e807493bdf89224cbdb94cb6 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 25 Apr 2016 17:38:36 +0800 Subject: [PATCH 15/20] minor fix --- cocos2d/core/components/CCRendererInSG.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCRendererInSG.js b/cocos2d/core/components/CCRendererInSG.js index 4777f05905..219742d50e 100644 --- a/cocos2d/core/components/CCRendererInSG.js +++ b/cocos2d/core/components/CCRendererInSG.js @@ -60,7 +60,7 @@ var RendererInSG = cc.Class({ if (CC_EDITOR) { var sgSize = this._sgNode.getContentSize(); // sgSize is not a Vec2 in JSB - if (sgSize.x !== 0 || sgSize.y !== 0) { + if (sgSize.width !== 0 || sgSize.height !== 0) { cc.error('Renderer error: Size of the cc._RendererInSG._sgNode must be zero'); } } From c7e4a2bd9b810a37e671be640f486a09229f3692 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 25 Apr 2016 17:53:32 +0800 Subject: [PATCH 16/20] scene loading flag should reset before callback --- cocos2d/core/CCDirector.js | 2 +- jsb/jsb-director.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 8e246225f9..329bb1e796 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -668,6 +668,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ //cc.AssetLibrary.unloadAsset(uuid); // force reload cc.AssetLibrary.loadAsset(uuid, function (error, sceneAsset) { var self = cc.director; + self._loadingScene = ''; var scene; if (error) { error = 'Failed to load scene: ' + error; @@ -694,7 +695,6 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ scene = null; } } - self._loadingScene = ''; if (error && onLaunched) { onLaunched(error); } diff --git a/jsb/jsb-director.js b/jsb/jsb-director.js index 7ea41db90b..7d073a49ea 100644 --- a/jsb/jsb-director.js +++ b/jsb/jsb-director.js @@ -252,6 +252,7 @@ cc.js.mixin(cc.director, { //cc.AssetLibrary.unloadAsset(uuid); // force reload cc.AssetLibrary.loadAsset(uuid, function (error, sceneAsset) { var self = cc.director; + self._loadingScene = ''; var scene; if (error) { error = 'Failed to load scene: ' + error; @@ -272,7 +273,6 @@ cc.js.mixin(cc.director, { scene = null; } } - self._loadingScene = ''; if (error && onLaunched) { onLaunched(error); } From e5fe29878bf9ed704461866914426b2fd8a81143 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 25 Apr 2016 17:01:43 +0800 Subject: [PATCH 17/20] fix editbox begin and end callback not called. --- cocos2d/core/components/CCEditBox.js | 16 ++++++++++++++-- jsb/jsb-editbox.js | 10 ---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cocos2d/core/components/CCEditBox.js b/cocos2d/core/components/CCEditBox.js index 2196c9a484..b0f0c7a5aa 100644 --- a/cocos2d/core/components/CCEditBox.js +++ b/cocos2d/core/components/CCEditBox.js @@ -465,8 +465,10 @@ var EditBox = cc.Class({ }, _registerEvent: function () { - this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchBegan, this); - this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this); + if(!CC_JSB) { + this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchBegan, this); + this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this); + } }, _onTouchBegan: function(event) { @@ -485,4 +487,14 @@ var EditBox = cc.Class({ }); +if(CC_JSB) { + EditBox.prototype.editBoxEditingDidBegin = function (sender) { + this.editBoxEditingDidBegan(sender); + } + + EditBox.prototype.editBoxEditingDidEnd = function (sender) { + this.editBoxEditingDidEnded(sender); + } +} + cc.EditBox = module.exports = EditBox; diff --git a/jsb/jsb-editbox.js b/jsb/jsb-editbox.js index fbf76d738f..bb9c6c6804 100644 --- a/jsb/jsb-editbox.js +++ b/jsb/jsb-editbox.js @@ -50,16 +50,6 @@ _p.setMaxLength = function(maxLength) { this._setMaxLength(maxLength); } -_p.editBoxEditingDidBegin = function (sender) { - this.editBoxEditingDidBegan(sender); -} -_p.editBoxEditingDidEnd = function (sender) { - this.editBoxEditingDidEnded(sender); -} - -_p._onTouchBegan = function() {} -_p._onTouchEnded = function() {} - _p.setLineHeight = function () {} _p = null; From b1f3e06a8261ca75922851c16b12bfda8274a7e3 Mon Sep 17 00:00:00 2001 From: Johnny Wu Date: Tue, 26 Apr 2016 09:58:51 +0800 Subject: [PATCH 18/20] make tiling and offset properties serializable --- cocos2d/core/components/CCSpriteDistortion.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/components/CCSpriteDistortion.js b/cocos2d/core/components/CCSpriteDistortion.js index 3e81563f5d..d12a370de2 100644 --- a/cocos2d/core/components/CCSpriteDistortion.js +++ b/cocos2d/core/components/CCSpriteDistortion.js @@ -45,8 +45,6 @@ var SpriteDistortion = cc.Class({ }, ctor: function() { - this._distortionOffset = cc.v2(0.0,0.0); - this._distortionTiling = cc.v2(1.0,1.0); this._spriteSGNode = null; }, @@ -59,6 +57,7 @@ var SpriteDistortion = cc.Class({ * @example * distortion.offset = new cc.Vec2(0.5, 0.3);; */ + _distortionOffset: cc.v2(0.0,0.0), offset: { get: function() { return this._distortionOffset; @@ -77,6 +76,7 @@ var SpriteDistortion = cc.Class({ * @example * distortion.tiling = new cc.Vec2(0.5, 0.3);; */ + _distortionTiling: cc.v2(1.0,1.0), tiling: { get: function() { return this._distortionTiling; From 985800b47e912987a61f03a42f331072828b5e30 Mon Sep 17 00:00:00 2001 From: Nan Wang Date: Tue, 26 Apr 2016 10:03:22 +0800 Subject: [PATCH 19/20] bump engine version --- CCBoot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CCBoot.js b/CCBoot.js index 87e0549293..73098957b3 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -58,7 +58,7 @@ _p = null; * @name cc.ENGINE_VERSION */ var engineVersion; -engineVersion = '1.0.1'; +engineVersion = '1.0.2'; window['CocosEngine'] = cc.ENGINE_VERSION = engineVersion; /** From 20b1f00710f7cadbded29040aa64a33c43c9b412 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 26 Apr 2016 13:57:00 +0800 Subject: [PATCH 20/20] fix spriteFrame.insetTop undefined error --- jsb/jsb-tex-sprite-frame.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/jsb/jsb-tex-sprite-frame.js b/jsb/jsb-tex-sprite-frame.js index e89281b379..cd0c8fc3ea 100644 --- a/jsb/jsb-tex-sprite-frame.js +++ b/jsb/jsb-tex-sprite-frame.js @@ -124,6 +124,13 @@ cc.SpriteFrame.prototype._refreshTexture = function (texture) { var offset = this.getOffset(); var rotated = this.isRotated(); + if (this.insetTop === undefined) { + this.insetTop = 0; + this.insetBottom = 0; + this.insetLeft = 0; + this.insetRight = 0; + } + this._initWithTexture(texture, rect, rotated, offset, originalSize); //dispatch 'load' event of cc.SpriteFrame