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;
/**
diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js
index 3467848d57..ec3b3249d6 100644
--- a/cocos2d/core/CCDirector.js
+++ b/cocos2d/core/CCDirector.js
@@ -365,7 +365,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.
@@ -454,7 +454,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.
@@ -672,6 +672,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;
@@ -698,7 +699,6 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
scene = null;
}
}
- self._loadingScene = '';
if (error && onLaunched) {
onLaunched(error);
}
diff --git a/cocos2d/core/components/CCEditBox.js b/cocos2d/core/components/CCEditBox.js
index 9386c53a8e..7f627df86c 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/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js
index c78d384f87..21e6c714a7 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,
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 3238e1be60..e329b050bf 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,32 @@ var RendererInSG = cc.Class({
this._plainNode.retain();
},
+ onLoad: function () {
+ this._initSgNode();
+ if (CC_EDITOR) {
+ var sgSize = this._sgNode.getContentSize();
+ // sgSize is not a Vec2 in JSB
+ if (sgSize.width !== 0 || sgSize.height !== 0) {
+ 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();
+ onDestroy: function () {
+ 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/components/CCSpriteDistortion.js b/cocos2d/core/components/CCSpriteDistortion.js
new file mode 100644
index 0000000000..d12a370de2
--- /dev/null
+++ b/cocos2d/core/components/CCSpriteDistortion.js
@@ -0,0 +1,111 @@
+/****************************************************************************
+ 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,
+ requireComponent: cc.Sprite,
+ },
+
+ ctor: function() {
+ 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);;
+ */
+ _distortionOffset: cc.v2(0.0,0.0),
+ offset: {
+ get: function() {
+ return this._distortionOffset;
+ },
+ set:function(value) {
+ this._distortionOffset.x = value.x;
+ this._distortionOffset.y = value.y;
+ }
+ },
+
+ /**
+ * !#en Change the UV scale for distortion rendering.
+ * !#zh 在渲染时改变UV的寻址系数
+ * @property tiling
+ * @type {Vec2}
+ * @example
+ * distortion.tiling = new cc.Vec2(0.5, 0.3);;
+ */
+ _distortionTiling: cc.v2(1.0,1.0),
+ tiling: {
+ get: function() {
+ return this._distortionTiling;
+ },
+ set:function(value) {
+ this._distortionTiling.x = value.x;
+ this._distortionTiling.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._distortionTiling = this._distortionTiling;
+ }
+ },
+
+ 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/label/CCSGLabelCanvasRenderCmd.js b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js
index 489527321a..fb00c7749d 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;
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 1c91c901c4..dae417acef 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 = '**/*';
-
/*
* !#en AssetTable is used to find asset's uuid by url.
* !#zh AssetTable 用于查找资源的 uuid 和 url。
@@ -48,9 +32,7 @@ var GLOB = '**/*';
function AssetTable () {
this._pathToUuid = {};
}
-AssetTable._hasWildcard = function (path) {
- return path.endsWith(GLOB);
-};
+
cc.js.mixin(AssetTable.prototype, {
///**
@@ -67,7 +49,7 @@ cc.js.mixin(AssetTable.prototype, {
//},
getUuid: function (path) {
- path = normalizePath(path);
+ path = cc.url.normalize(path);
if ( !path ) {
return '';
}
@@ -75,22 +57,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;
+ },
+
/**
* !#en Returns all asset paths in the table.
* !#zh 返回表中的所有资源路径。
@@ -100,81 +86,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;
- // }
- //},
/**
* !#en TODO
diff --git a/cocos2d/core/platform/url.js b/cocos2d/core/platform/url.js
index fa9a2f4975..794a23d945 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/cocos2d/core/sprites/CCScale9Sprite.js b/cocos2d/core/sprites/CCScale9Sprite.js
index 1fd624cb4f..255ccaa790 100644
--- a/cocos2d/core/sprites/CCScale9Sprite.js
+++ b/cocos2d/core/sprites/CCScale9Sprite.js
@@ -874,6 +874,8 @@ cc.Scale9Sprite = _ccsg.Node.extend({
//normalized filled start and range
_fillStart: 0,
_fillRange: Math.PI * 2,
+ _distortionOffset: null,
+ _distortionTiling: null,
ctor: function (textureOrSpriteFrame) {
_ccsg.Node.prototype.ctor.call(this);
@@ -1249,7 +1251,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 d68f6417cc..dea7127439 100644
--- a/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js
+++ b/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js
@@ -64,7 +64,16 @@ 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._distortionOffset,
+ this._node._distortionOffset.x, this._node._distortionOffset.y
+ );
+ this._shaderProgram.setUniformLocationWith2f(
+ cc.Scale9Sprite.WebGLRenderCmd._distortionTiling,
+ this._node._distortionTiling.x, this._node._distortionTiling.y
+ );
+ }
ccgl.blendFunc(node._blendFunc.src, node._blendFunc.dst);
//optimize performance for javascript
ccgl.bindTexture2DN(0, locTexture); // = cc.gl.bindTexture2D(locTexture);
@@ -147,6 +156,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());
}
};
@@ -178,4 +189,55 @@ 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._distortionOffset = shader.getUniformLocationForName('u_offset');
+ cc.Scale9Sprite.WebGLRenderCmd._distortionTiling = shader.getUniformLocationForName('u_offset_tiling');
+ 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"
+ + "uniform vec2 u_offset_tiling; \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 = uv * u_offset_tiling + u_offset;\n"
+ + "uv = fract(uv); \n"
+ + "gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, uv);\n"
+ + "}";
}
diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js
index 94a1cd093d..cf3357ad4d 100644
--- a/cocos2d/core/utils/base-node.js
+++ b/cocos2d/core/utils/base-node.js
@@ -2091,32 +2091,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 ccb04e9576..2d054546a6 100644
--- a/cocos2d/tilemap/CCTiledMap.js
+++ b/cocos2d/tilemap/CCTiledMap.js
@@ -476,6 +476,11 @@ var TiledMap = cc.Class({
this._applyFile();
},
+ _resetSgSize: function () {
+ this.node.setContentSize(this._sgNode.getContentSize());
+ this._sgNode.setContentSize(0, 0);
+ },
+
_onMapLoaded: function() {
this._refreshLayerEntities();
if (this._enabled) {
@@ -486,6 +491,8 @@ var TiledMap = cc.Class({
// enable / disable the TiledLayer component
this._setLayersEnabled(this._enabled);
+
+ this._resetSgSize();
},
_setLayersEnabled: function(enabled) {
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);
}
diff --git a/jsb/jsb-editbox.js b/jsb/jsb-editbox.js
index ce1db01988..553d06ceca 100644
--- a/jsb/jsb-editbox.js
+++ b/jsb/jsb-editbox.js
@@ -50,15 +50,4 @@ _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 () {};
-
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 2a47315162..643283f552 100644
--- a/jsb/jsb-tex-sprite-frame.js
+++ b/jsb/jsb-tex-sprite-frame.js
@@ -55,73 +55,103 @@ 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) {
- if (texture && texture.isLoaded()) {
- var _x, _y;
- if (rotated) {
- _x = rect.x + rect.height;
- _y = rect.y + rect.width;
- }
- else {
- _x = rect.x + rect.width;
- _y = rect.y + rect.height;
- }
- if (_x > texture.getPixelWidth()) {
- cc.error(cc._LogInfos.RectWidth, _uuid);
- }
- if (_y > texture.getPixelHeight()) {
- cc.error(cc._LogInfos.RectHeight, _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) {
+
+ if (rect) {
+ this.setRect(rect);
}
- 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;
+ if (offset) {
+ this.setOffset(offset);
}
- 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;
- }
+ if (originalSize) {
+ this.setOriginalSize(originalSize);
+ }
- this._textureFilename = info.url;
+ this.setRotated(rotated || false);
- locTexture = cc.textureCache.addImage(info.url);
- this._initWithTexture(locTexture, rect, rotated, offset, originalSize);
+ 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(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);
- }
+ //todo log error
}
- this.emit('load');
- check(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();
+
+ 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
+ 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) {
@@ -136,8 +166,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();
@@ -166,25 +194,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);
}
});
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-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');
});
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();
});