From 7929bb9c0927c96ad105530dff45813af9083245 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 28 Aug 2017 15:58:12 +0800 Subject: [PATCH 01/28] adjust uglifyjs for jsc --- gulp/util/utils.js | 108 ++++++++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 45 deletions(-) diff --git a/gulp/util/utils.js b/gulp/util/utils.js index a96c5c6d31..a41839f33d 100644 --- a/gulp/util/utils.js +++ b/gulp/util/utils.js @@ -21,56 +21,74 @@ exports.getMacros = function (platform, isJSB, isDebugBuild) { exports.getUglifyOptions = function (platform, isJSB, isDebugBuild) { var global_defs = exports.getMacros(platform, isJSB, isDebugBuild); - if (!global_defs['CC_DEBUG']) { + var releaseMode = !global_defs['CC_DEBUG']; + + var optimizeForJSC = releaseMode && isJSB; + if (optimizeForJSC) { return { + output: { + beautify: true, // really preserve_lines + indent_level: 0, // reduce jsc file size + }, compress: { global_defs: global_defs, - // keep_infinity: true + sequences: false, + keep_infinity: true, // reduce jsc file size + typeofs: false, } }; } - return { - mangle: false, - //preserveComments: 'all', - output: { - // http://lisperator.net/uglifyjs/codegen - beautify: true, - bracketize: true, - }, - compress: { - // https://github.com/mishoo/UglifyJS2#compressor-options - global_defs: global_defs, - sequences: false, // join consecutive statements with the “comma operator” - properties: false, // optimize property access: a["foo"] → a.foo - //dead_code: true, // discard unreachable code - drop_debugger: false, // discard “debugger” statements - unsafe: false, // some unsafe optimizations (see below) - //conditionals: false, // optimize if-s and conditional expressions - comparisons: false, // optimize comparisons - //evaluate: true, // evaluate constant expressions - booleans: false, // optimize boolean expressions - typeofs: false, // Transforms typeof foo == "undefined" into foo === void 0. Note: recommend to set this value to false for IE10 and earlier versions due to known issues. - loops: false, // optimize loops - unused: false, // drop unused variables/functions - hoist_funs: false, // hoist function declarations - hoist_vars: false, // hoist variable declarations - if_return: false, // optimize if-s followed by return/continue - inline: false, // embed simple functions - join_vars: false, // join var declarations - cascade: false, // try to cascade `right` into `left` in sequences - collapse_vars: false, // Collapse single-use non-constant variables - side effects permitting. - reduce_vars: false, // Improve optimization on variables assigned with and used as constant values. - //warnings: true, - negate_iife: false, - pure_getters: false, - pure_funcs: null, - drop_console: false, - // expression: false, // Pass true to preserve completion values from terminal statements without return, e.g. in bookmarklets. - keep_fargs: true, - keep_fnames: true, - // keep_infinity: false, // Pass true to prevent Infinity from being compressed into 1/0, which may cause performance issues on Chrome. - side_effects: false // drop side-effect-free statements - } - }; + if (releaseMode) { + return { + compress: { + global_defs: global_defs, + } + }; + } + else { + return { + mangle: false, + //preserveComments: 'all', + output: { + // http://lisperator.net/uglifyjs/codegen + beautify: true, + indent_level: 2, + }, + compress: { + // https://github.com/mishoo/UglifyJS2#compressor-options + global_defs: global_defs, + sequences: false, // join consecutive statements with the “comma operator” + properties: false, // optimize property access: a["foo"] → a.foo + //dead_code: true, // discard unreachable code + drop_debugger: false, // discard “debugger” statements + unsafe: false, // some unsafe optimizations (see below) + //conditionals: false, // optimize if-s and conditional expressions + comparisons: false, // optimize comparisons + //evaluate: true, // evaluate constant expressions + booleans: false, // optimize boolean expressions + typeofs: false, // Transforms typeof foo == "undefined" into foo === void 0. Note: recommend to set this value to false for IE10 and earlier versions due to known issues. + loops: false, // optimize loops + unused: false, // drop unused variables/functions + hoist_funs: false, // hoist function declarations + hoist_vars: false, // hoist variable declarations + if_return: false, // optimize if-s followed by return/continue + inline: false, // embed simple functions + join_vars: false, // join var declarations + cascade: false, // try to cascade `right` into `left` in sequences + collapse_vars: false, // Collapse single-use non-constant variables - side effects permitting. + reduce_vars: false, // Improve optimization on variables assigned with and used as constant values. + //warnings: true, + negate_iife: false, + pure_getters: false, + pure_funcs: null, + drop_console: false, + // expression: false, // Pass true to preserve completion values from terminal statements without return, e.g. in bookmarklets. + keep_fargs: true, + keep_fnames: true, + keep_infinity: true, // Pass true to prevent Infinity from being compressed into 1/0, which may cause performance issues on Chrome. + side_effects: false // drop side-effect-free statements + } + }; + } }; From d1bd91910467301af45065ac7f775946c09d573e Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Tue, 29 Aug 2017 11:11:53 +0800 Subject: [PATCH 02/28] fix conflict --- cocos2d/core/CCDirector.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index d3b4165def..0e60e7d01f 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -589,9 +589,9 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ sgScene = scene._sgNode; // Re-attach or replace persist nodes + CC_DEBUG && console.time('AttachPersist'); for (let i = 0; i < persistNodeList.length; i++) { let node = persistNodeList[i]; - CC_DEBUG && console.time('AttachPersist'); var existNode = scene.getChildByUuid(node.uuid); if (existNode) { // scene also contains the persist node, select the old one From 6bc0ff1caece86fbae5350029cd8d04ceb2f6309 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Tue, 29 Aug 2017 17:58:07 +0800 Subject: [PATCH 03/28] should ignore animation playOnLoad if already play an animation --- cocos2d/core/components/CCAnimation.js | 3 ++- test/qunit/unit-es5/test-animation.js | 32 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCAnimation.js b/cocos2d/core/components/CCAnimation.js index e70f645625..e9a2b5ffc2 100644 --- a/cocos2d/core/components/CCAnimation.js +++ b/cocos2d/core/components/CCAnimation.js @@ -169,7 +169,8 @@ var Animation = cc.Class({ }, start: function () { - if (!CC_EDITOR && this.playOnLoad && this._defaultClip) { + var isPlaying = this._animator && this._animator.isPlaying; + if (!CC_EDITOR && !isPlaying && this.playOnLoad && this._defaultClip) { var state = this.getAnimationState(this._defaultClip.name); this._animator.playState(state); } diff --git a/test/qunit/unit-es5/test-animation.js b/test/qunit/unit-es5/test-animation.js index 4891a817bb..1ff31fbccd 100644 --- a/test/qunit/unit-es5/test-animation.js +++ b/test/qunit/unit-es5/test-animation.js @@ -1553,3 +1553,35 @@ test('animation pause/resume should remove animation-actor from animation manage strictEqual(manager._animators.array.length, 0, 'should remove animation from animation manager'); }); + + +test('animation play on load', function () { + var entity = new cc.Node(); + + var animation = entity.addComponent(cc.Animation); + animation.playOnLoad = true; + + var clip1 = new cc.AnimationClip(); + clip1._name = 'clip1'; + clip1._duration = 1; + + var clip2 = new cc.AnimationClip(); + clip2._name = 'clip2'; + clip2._duration = 1; + + + animation.addClip(clip1); + animation.addClip(clip2); + + animation._defaultClip = clip1; + + animation.play('clip2'); + + entity.parent = cc.director.getScene(); + animation.start(); + + strictEqual(animation.getAnimationState('clip1').isPlaying, false, 'default clip should not be played if there is playing animation'); + strictEqual(animation.getAnimationState('clip2').isPlaying, true, 'should play the specified animation'); + + entity.parent = null; +}); From a6b42859fc98f1e0e9a043cb8163c09f814eb90d Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Tue, 29 Aug 2017 18:08:07 +0800 Subject: [PATCH 04/28] refine code --- cocos2d/core/components/CCAnimation.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/components/CCAnimation.js b/cocos2d/core/components/CCAnimation.js index e9a2b5ffc2..ff1855e8d0 100644 --- a/cocos2d/core/components/CCAnimation.js +++ b/cocos2d/core/components/CCAnimation.js @@ -169,10 +169,12 @@ var Animation = cc.Class({ }, start: function () { - var isPlaying = this._animator && this._animator.isPlaying; - if (!CC_EDITOR && !isPlaying && this.playOnLoad && this._defaultClip) { - var state = this.getAnimationState(this._defaultClip.name); - this._animator.playState(state); + if (!CC_EDITOR && this.playOnLoad && this._defaultClip) { + var isPlaying = this._animator && this._animator.isPlaying; + if (!isPlaying) { + var state = this.getAnimationState(this._defaultClip.name); + this._animator.playState(state); + } } }, From f303bb4c57b9fe7f9188ec68be71254477421118 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 30 Aug 2017 10:39:46 +0800 Subject: [PATCH 05/28] Fixed a bug about remove touchPlayList --- cocos2d/audio/CCAudio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index 6d5420564a..c5f7d8876c 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -195,7 +195,7 @@ Audio.State = { } catch (error) {} this._element.pause(); // remove touchPlayList - for (var i=0; i Date: Wed, 30 Aug 2017 11:59:21 +0800 Subject: [PATCH 06/28] fixed camera api doc --- cocos2d/core/camera/CCCamera.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/camera/CCCamera.js b/cocos2d/core/camera/CCCamera.js index a77cbe58d0..8e621c6aa1 100644 --- a/cocos2d/core/camera/CCCamera.js +++ b/cocos2d/core/camera/CCCamera.js @@ -242,6 +242,7 @@ let Camera = cc.Class({ * Returns the matrix that transform the node's (local) space coordinates into the camera's space coordinates. * !#zh * 返回一个将节点坐标系转换到摄像机坐标系下的矩阵 + * @method getNodeToCameraTransform * @param {Node} node - the node which should transform * @return {AffineTransform} */ @@ -257,7 +258,8 @@ let Camera = cc.Class({ * !#en * Conver a camera coordinates point to world coordinates. * !#zh - * 讲一个摄像机坐标系下的点转换到世界坐标系下。 + * 将一个摄像机坐标系下的点转换到世界坐标系下。 + * @method getCameraToWorldPoint * @param {Node} point - the point which should transform * @return {Vec2} */ @@ -273,6 +275,7 @@ let Camera = cc.Class({ * Check whether the node is in the camera. * !#zh * 检测节点是否被此摄像机影响 + * @method containsNode * @param {Node} node - the node which need to check * @return {Boolean} */ From 813c44e31981431560216514467c1144139b2515 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Thu, 31 Aug 2017 00:51:51 +0800 Subject: [PATCH 07/28] should not enumerate getter values while creating ccclass in TypeScript --- cocos2d/core/platform/CCClassDecorator.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/platform/CCClassDecorator.js b/cocos2d/core/platform/CCClassDecorator.js index 2feda016f6..1217eddf08 100644 --- a/cocos2d/core/platform/CCClassDecorator.js +++ b/cocos2d/core/platform/CCClassDecorator.js @@ -280,13 +280,14 @@ var ccclass = checkCtorArgument(function (ctor, name) { // validate methods if (CC_DEV) { - var methods = Object.getOwnPropertyNames(ctor.prototype); - for (var i = 0; i < methods.length; ++i) { - var methodName = methods[i]; - if (methodName !== 'constructor') { - var func = ctor.prototype[methodName]; + var propNames = Object.getOwnPropertyNames(ctor.prototype); + for (var i = 0; i < propNames.length; ++i) { + var prop = propNames[i]; + if (prop !== 'constructor') { + var desc = Object.getOwnPropertyDescriptor(ctor.prototype, prop); + var func = desc && desc.value; if (typeof func === 'function') { - Preprocess.doValidateMethodWithProps_DEV(func, methodName, JS.getClassName(ctor), ctor, base); + Preprocess.doValidateMethodWithProps_DEV(func, prop, JS.getClassName(ctor), ctor, base); } } } From 96afe621dea7e7731d39e0a30f0cc62da18ff9e8 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Fri, 1 Sep 2017 15:20:58 +0800 Subject: [PATCH 08/28] fix cc.Director api for TypeScript --- cocos2d/core/CCDirector.js | 95 ++++++++++++++++++++++++++++++++++---- cocos2d/core/CCNode.js | 30 ++++-------- 2 files changed, 96 insertions(+), 29 deletions(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 0e60e7d01f..7ab1d383fb 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -1262,6 +1262,13 @@ cc.js.addon(cc.Director.prototype, EventTarget.prototype); * cc.log("Projection changed."); * }); */ +/** + * !#en The event projection changed of cc.Director. + * !#zh cc.Director 投影变化的事件。 + * @property {String} EVENT_PROJECTION_CHANGED + * @readonly + * @static + */ cc.Director.EVENT_PROJECTION_CHANGED = "director_projection_changed"; /** @@ -1271,6 +1278,13 @@ cc.Director.EVENT_PROJECTION_CHANGED = "director_projection_changed"; * @param {Event.EventCustom} event * @param {Vec2} event.detail - The loading scene name */ +/** + * !#en The event which will be triggered before loading a new scene. + * !#zh 加载新场景之前所触发的事件。 + * @property {String} EVENT_BEFORE_SCENE_LOADING + * @readonly + * @static + */ cc.Director.EVENT_BEFORE_SCENE_LOADING = "director_before_scene_loading"; /* @@ -1280,6 +1294,13 @@ cc.Director.EVENT_BEFORE_SCENE_LOADING = "director_before_scene_loading"; * @param {Event.EventCustom} event * @param {Vec2} event.detail - New scene which will be launched */ +/** + * !#en The event which will be triggered before launching a new scene. + * !#zh 运行新场景之前所触发的事件。 + * @property {String} EVENT_BEFORE_SCENE_LAUNCH + * @readonly + * @static + */ cc.Director.EVENT_BEFORE_SCENE_LAUNCH = "director_before_scene_launch"; /** @@ -1289,6 +1310,13 @@ cc.Director.EVENT_BEFORE_SCENE_LAUNCH = "director_before_scene_launch"; * @param {Event.EventCustom} event * @param {Vec2} event.detail - New scene which is launched */ +/** + * !#en The event which will be triggered after launching a new scene. + * !#zh 运行新场景之后所触发的事件。 + * @property {String} EVENT_AFTER_SCENE_LAUNCH + * @readonly + * @static + */ cc.Director.EVENT_AFTER_SCENE_LAUNCH = "director_after_scene_launch"; /** @@ -1297,6 +1325,13 @@ cc.Director.EVENT_AFTER_SCENE_LAUNCH = "director_after_scene_launch"; * @event cc.Director.EVENT_BEFORE_UPDATE * @param {Event.EventCustom} event */ +/** + * !#en The event which will be triggered at the beginning of every frame. + * !#zh 每个帧的开始时所触发的事件。 + * @property {String} EVENT_BEFORE_UPDATE + * @readonly + * @static + */ cc.Director.EVENT_BEFORE_UPDATE = "director_before_update"; /** @@ -1305,6 +1340,13 @@ cc.Director.EVENT_BEFORE_UPDATE = "director_before_update"; * @event cc.Director.EVENT_AFTER_UPDATE * @param {Event.EventCustom} event */ +/** + * !#en The event which will be triggered after engine and components update logic. + * !#zh 将在引擎和组件 “update” 逻辑之后所触发的事件。 + * @property {String} EVENT_AFTER_UPDATE + * @readonly + * @static + */ cc.Director.EVENT_AFTER_UPDATE = "director_after_update"; /** @@ -1313,16 +1355,34 @@ cc.Director.EVENT_AFTER_UPDATE = "director_after_update"; * @event cc.Director.EVENT_BEFORE_VISIT * @param {Event.EventCustom} event */ +/** + * !#en The event which will be triggered before visiting the rendering scene graph. + * !#zh 访问渲染场景树之前所触发的事件。 + * @property {String} EVENT_BEFORE_VISIT + * @readonly + * @static + */ cc.Director.EVENT_BEFORE_VISIT = "director_before_visit"; /** * !#en * The event which will be triggered after visiting the rendering scene graph, * the render queue is ready but not rendered at this point. - * !#zh 访问渲染场景图之后所触发的事件,渲染队列已准备就绪,但在这一时刻还没有呈现在画布上。 + * !#zh + * 访问渲染场景图之后所触发的事件,渲染队列已准备就绪,但在这一时刻还没有呈现在画布上。 * @event cc.Director.EVENT_AFTER_VISIT * @param {Event.EventCustom} event */ +/** + * !#en + * The event which will be triggered after visiting the rendering scene graph, + * the render queue is ready but not rendered at this point. + * !#zh + * 访问渲染场景图之后所触发的事件,渲染队列已准备就绪,但在这一时刻还没有呈现在画布上。 + * @property {String} EVENT_AFTER_VISIT + * @readonly + * @static + */ cc.Director.EVENT_AFTER_VISIT = "director_after_visit"; /** @@ -1331,11 +1391,19 @@ cc.Director.EVENT_AFTER_VISIT = "director_after_visit"; * @event cc.Director.EVENT_AFTER_DRAW * @param {Event.EventCustom} event */ +/** + * !#en The event which will be triggered after the rendering process. + * !#zh 渲染过程之后所触发的事件。 + * @property {String} EVENT_AFTER_DRAW + * @readonly + * @static + */ cc.Director.EVENT_AFTER_DRAW = "director_after_draw"; /*************************************************** * implementation of DisplayLinkDirector **************************************************/ + cc.DisplayLinkDirector = cc.Director.extend(/** @lends cc.Director# */{ invalid: false, @@ -1483,30 +1551,39 @@ cc.Director._getInstance = function () { cc.defaultFPS = 60; //Possible OpenGL projections used by director + /** * Constant for 2D projection (orthogonal projection) - * @constant - * @type {Number} + * @property {Number} PROJECTION_2D + * @default 0 + * @readonly + * @static */ cc.Director.PROJECTION_2D = 0; /** * Constant for 3D projection with a fovy=60, znear=0.5f and zfar=1500. - * @constant - * @type {Number} + * @property {Number} PROJECTION_3D + * @default 1 + * @readonly + * @static */ cc.Director.PROJECTION_3D = 1; /** * Constant for custom projection, if cc.Director's projection set to it, it calls "updateProjection" on the projection delegate. - * @constant - * @type {Number} + * @property {Number} PROJECTION_CUSTOM + * @default 3 + * @readonly + * @static */ cc.Director.PROJECTION_CUSTOM = 3; /** * Constant for default projection of cc.Director, default projection is 2D projection - * @constant - * @type {Number} + * @property {Number} PROJECTION_DEFAULT + * @default cc.Director.PROJECTION_2D + * @readonly + * @static */ cc.Director.PROJECTION_DEFAULT = cc.Director.PROJECTION_2D; diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index b25333ecc0..98b5094a0e 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -58,32 +58,28 @@ var EventType = cc.Enum({ /** * !#en The event type for touch start event, you can use its value directly: 'touchstart' * !#zh 当手指触摸到屏幕时。 - * @property TOUCH_START - * @type {String} + * @property {String} TOUCH_START * @static */ TOUCH_START: 'touchstart', /** * !#en The event type for touch move event, you can use its value directly: 'touchmove' * !#zh 当手指在屏幕上目标节点区域内移动时。 - * @property TOUCH_MOVE - * @type {String} + * @property {String} TOUCH_MOVE * @static */ TOUCH_MOVE: 'touchmove', /** * !#en The event type for touch end event, you can use its value directly: 'touchend' * !#zh 当手指在目标节点区域内离开屏幕时。 - * @property TOUCH_END - * @type {String} + * @property {String} TOUCH_END * @static */ TOUCH_END: 'touchend', /** * !#en The event type for touch end event, you can use its value directly: 'touchcancel' * !#zh 当手指在目标节点区域外离开屏幕时。 - * @property TOUCH_CANCEL - * @type {String} + * @property {String} TOUCH_CANCEL * @static */ TOUCH_CANCEL: 'touchcancel', @@ -91,48 +87,42 @@ var EventType = cc.Enum({ /** * !#en The event type for mouse down events, you can use its value directly: 'mousedown' * !#zh 当鼠标按下时触发一次。 - * @property MOUSE_DOWN - * @type {String} + * @property {String} MOUSE_DOWN * @static */ MOUSE_DOWN: 'mousedown', /** * !#en The event type for mouse move events, you can use its value directly: 'mousemove' * !#zh 当鼠标在目标节点在目标节点区域中移动时,不论是否按下。 - * @property MOUSE_MOVE - * @type {String} + * @property {String} MOUSE_MOVE * @static */ MOUSE_MOVE: 'mousemove', /** * !#en The event type for mouse enter target events, you can use its value directly: 'mouseenter' * !#zh 当鼠标移入目标节点区域时,不论是否按下。 - * @property MOUSE_ENTER - * @type {String} + * @property {String} MOUSE_ENTER * @static */ MOUSE_ENTER: 'mouseenter', /** * !#en The event type for mouse leave target events, you can use its value directly: 'mouseleave' * !#zh 当鼠标移出目标节点区域时,不论是否按下。 - * @property MOUSE_LEAVE - * @type {String} + * @property {String} MOUSE_LEAVE * @static */ MOUSE_LEAVE: 'mouseleave', /** * !#en The event type for mouse up events, you can use its value directly: 'mouseup' * !#zh 当鼠标从按下状态松开时触发一次。 - * @property MOUSE_UP - * @type {String} + * @property {String} MOUSE_UP * @static */ MOUSE_UP: 'mouseup', /** * !#en The event type for mouse wheel events, you can use its value directly: 'mousewheel' * !#zh 当鼠标滚轮滚动时。 - * @property MOUSE_WHEEL - * @type {String} + * @property {String} MOUSE_WHEEL * @static */ MOUSE_WHEEL: 'mousewheel', From 4220d4b1421f4c4a124aee2fd0aedbc17097bf81 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Sat, 2 Sep 2017 21:45:56 +0800 Subject: [PATCH 09/28] =?UTF-8?q?should=20not=20emit=20=E2=80=98size-chang?= =?UTF-8?q?ed=E2=80=99=20directly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos2d/core/components/CCRichText.js | 8 +++----- cocos2d/core/components/CCSprite.js | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/components/CCRichText.js b/cocos2d/core/components/CCRichText.js index 05c8592d78..0c6e5eea26 100644 --- a/cocos2d/core/components/CCRichText.js +++ b/cocos2d/core/components/CCRichText.js @@ -309,13 +309,12 @@ var RichText = cc.Class({ _containsTouchLocation:function (label, point) { var myRect = label.getBoundingBoxToWorld(); - return cc.rectContainsPoint(myRect, point); }, _resetState: function () { var sgNode = this._sgNode; - if(sgNode) { + if (sgNode) { sgNode.removeAllChildren(); } @@ -626,10 +625,9 @@ var RichText = cc.Class({ if(this.maxWidth > 0) { this._labelWidth = this.maxWidth; } - this._labelHeight =this._lineCount * this.lineHeight; + this._labelHeight = this._lineCount * this.lineHeight; - sgNode._setContentSize(this._labelWidth, this._labelHeight); - this.node.emit('size-changed'); + this.node.setContentSize(this._labelWidth, this._labelHeight); this._updateRichTextPosition(); this._layoutDirty = false; diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index 1376c9abcc..596123a8f3 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -527,7 +527,7 @@ var Sprite = cc.Class({ this.node.setContentSize(size); } else if (SizeMode.TRIMMED === this._sizeMode) { var rect = this._spriteFrame.getRect(); - this.node.setContentSize(cc.size(rect.width, rect.height)); + this.node.setContentSize(rect.width, rect.height); } else { this.node.setContentSize(this.node.getContentSize(true)); } From 06011baeb8d28bf5a1a6d57048230413150da080 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 31 Aug 2017 14:14:49 +0800 Subject: [PATCH 10/28] remove empty error handler --- jsb/jsb-etc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jsb/jsb-etc.js b/jsb/jsb-etc.js index 39a3569373..89ec3f4b43 100644 --- a/jsb/jsb-etc.js +++ b/jsb/jsb-etc.js @@ -198,8 +198,8 @@ if (cc.Image && cc.Image.setPNGPremultipliedAlphaEnabled) { } // __errorHandler -window.__errorHandler = function (filename, lineno, message) { -}; +// window.__errorHandler = function (filename, lineno, message, stack) { +// }; // global cleanup. Dangerous!!! please do not invoke this function, it's used internally by the restart process window.__cleanup = function () { From 68c33484c7f91486ba3751f4f93b539496699060 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 4 Sep 2017 21:54:20 +0800 Subject: [PATCH 11/28] fix api doc --- cocos2d/actions/CCActionInterval.js | 4 ++-- cocos2d/audio/CCAudioEngine.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos2d/actions/CCActionInterval.js b/cocos2d/actions/CCActionInterval.js index af705aef10..670ebf1287 100644 --- a/cocos2d/actions/CCActionInterval.js +++ b/cocos2d/actions/CCActionInterval.js @@ -214,7 +214,7 @@ cc.ActionInterval = cc.FiniteTimeAction.extend({ * !#zh * 改变一个动作的速度,使它的执行使用更长的时间(speed > 1)
* 或更少(speed < 1)可以有效得模拟“慢动作”或“快进”的效果。 - * @param speed + * @param {Number} speed * @returns {Action} */ speed: function(speed){ @@ -252,7 +252,7 @@ cc.ActionInterval = cc.FiniteTimeAction.extend({ * To repeat an action forever use the CCRepeatForever action. * !#zh 重复动作可以按一定次数重复一个动作,使用 RepeatForever 动作来永远重复一个动作。 * @method repeat - * @param times + * @param {Number} times * @returns {ActionInterval} */ repeat: function(times){ diff --git a/cocos2d/audio/CCAudioEngine.js b/cocos2d/audio/CCAudioEngine.js index 8c2817f39c..227dc9b76a 100644 --- a/cocos2d/audio/CCAudioEngine.js +++ b/cocos2d/audio/CCAudioEngine.js @@ -473,9 +473,9 @@ var audioEngine = { /** * !#en Preload audio file. * !#zh 预加载一个音频 - * @param filePath The file path of an audio. - * @param callback The callback of an audio. * @method preload + * @param {String} filePath - The file path of an audio. + * @param {Function} callback - The callback of an audio. * @example * //example * cc.audioEngine.preload(path); From a48688e8c74dbf8fe34bcb297920675789561492 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Wed, 6 Sep 2017 11:42:38 +0800 Subject: [PATCH 12/28] fixed node hit test with camera --- cocos2d/core/CCNode.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index b25333ecc0..2deb97f7bd 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -1306,14 +1306,11 @@ var Node = cc.Class({ h = this.height; var rect = cc.rect(0, 0, w, h); - var trans; if (cc.Camera && cc.Camera.main) { - trans = cc.Camera.main.getNodeToCameraTransform(this); + point = cc.Camera.main.getCameraToWorldPoint(point); } - else { - trans = this.getNodeToWorldTransform(); - } - + + var trans = this.getNodeToWorldTransform(); cc._rectApplyAffineTransformIn(rect, trans); var left = point.x - rect.x, right = rect.x + rect.width - point.x, From bb63d5231d7dc762992363f8f7a64df69453dad8 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 6 Sep 2017 21:27:14 +0800 Subject: [PATCH 13/28] persistRootNodes should be reset while restart --- cocos2d/core/CCGame.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cocos2d/core/CCGame.js b/cocos2d/core/CCGame.js index 921aef4b30..45bc3d6c63 100644 --- a/cocos2d/core/CCGame.js +++ b/cocos2d/core/CCGame.js @@ -294,10 +294,16 @@ var game = { */ restart: function () { cc.director.once(cc.Director.EVENT_AFTER_DRAW, function () { + for (var id in game._persistRootNodes) { + game.removePersistRootNode(game._persistRootNodes[id]); + } + // Clear scene cc.director.getScene().destroy(); cc.Object._deferredDestroy(); + cc.director.purgeDirector(); + // Clean up audio if (cc.audioEngine) { cc.audioEngine.uncacheAll(); From 890fd59eda5e836ef23fb371bb1e716a338d515a Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 7 Sep 2017 14:41:20 +0800 Subject: [PATCH 14/28] Fix nested sequence with repeat being considered as reversed issue --- cocos2d/actions/CCActionInterval.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cocos2d/actions/CCActionInterval.js b/cocos2d/actions/CCActionInterval.js index af705aef10..daf6640e1e 100644 --- a/cocos2d/actions/CCActionInterval.js +++ b/cocos2d/actions/CCActionInterval.js @@ -306,6 +306,7 @@ cc.Sequence = cc.ActionInterval.extend({ _actions:null, _split:null, _last:0, + _reversed:false, ctor:function (tempArray) { cc.ActionInterval.prototype.ctor.call(this); @@ -379,7 +380,7 @@ cc.Sequence = cc.ActionInterval.extend({ // action[0] new_t = (locSplit !== 0) ? dt / locSplit : 1; - if (found === 0 && locLast === 1) { + if (found === 0 && locLast === 1 && this._reversed) { // Reverse mode ? // XXX: Bug. this case doesn't contemplate when _last==-1, found=0 and in "reverse mode" // since it will require a hack to know if an action is on reverse mode or not. @@ -398,7 +399,7 @@ cc.Sequence = cc.ActionInterval.extend({ locActions[0].update(1); locActions[0].stop(); } - if (!locLast) { + if (locLast === 0) { // switching to action 1. stop action 0. locActions[0].update(1); locActions[0].stop(); @@ -410,7 +411,7 @@ cc.Sequence = cc.ActionInterval.extend({ if (locLast === found && actionFound.isDone()) return; - // Last action found and it is done + // Last action not found if (locLast !== found) actionFound.startWithTarget(this.target); @@ -423,6 +424,7 @@ cc.Sequence = cc.ActionInterval.extend({ var action = cc.Sequence._actionOneTwo(this._actions[1].reverse(), this._actions[0].reverse()); this._cloneDecoration(action); this._reverseEaseList(action); + action._reversed = true; return action; } }); From 1d421ddc2d4225078c6b956d1f4a353a36279844 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 7 Sep 2017 21:07:17 +0800 Subject: [PATCH 15/28] Fix the EditBox type for numeric access. Invalid focus (FireFox) for fireball/issues/6357 --- cocos2d/core/editbox/CCSGEditBox.js | 35 +++++++++++++++++++---------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/cocos2d/core/editbox/CCSGEditBox.js b/cocos2d/core/editbox/CCSGEditBox.js index 3d12b4cb25..20cd784462 100644 --- a/cocos2d/core/editbox/CCSGEditBox.js +++ b/cocos2d/core/editbox/CCSGEditBox.js @@ -30,6 +30,8 @@ var SCROLLY = 40; var TIMER_NAME = 400; var LEFT_PADDING = 2; +var FOCUS_DELAY_UC = 400; +var FOCUS_DELAY_FIREFOX = 0; var Utils = require('../platform/utils'); function adjustEditBoxPosition (editBox) { @@ -688,6 +690,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; tmpEdTxt.style.position = "absolute"; tmpEdTxt.style.bottom = "0px"; tmpEdTxt.style.left = LEFT_PADDING + "px"; + tmpEdTxt.style['-moz-appearance'] = 'textfield'; tmpEdTxt.style.className = "cocosEditBox"; tmpEdTxt.addEventListener('input', function () { @@ -965,25 +968,33 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; this._updateLabelStringStyle(); }; - proto._beginEditing = function() { - if (!this._editBox._alwaysOnTop) { - if (this._edTxt.style.display === 'none') { - this._edTxt.style.display = ''; + proto._beginEditing = function () { + var self = this; + if (!self._editBox._alwaysOnTop) { + if (self._edTxt.style.display === 'none') { + self._edTxt.style.display = ''; + + function startFocus () { + self._edTxt.focus(); + } + if (cc.sys.browserType === cc.sys.BROWSER_TYPE_UC) { - setTimeout(function () { - this._edTxt.focus(); - }.bind(this), TIMER_NAME); - } else { - this._edTxt.focus(); + setTimeout(startFocus, FOCUS_DELAY_UC); + } + else if (cc.sys.browserType === cc.sys.BROWSER_TYPE_FIREFOX) { + setTimeout(startFocus, FOCUS_DELAY_FIREFOX); + } + else { + startFocus(); } } } - if (cc.sys.isMobile && !this._editingMode) { + if (cc.sys.isMobile && !self._editingMode) { // Pre adaptation and - this._beginEditingOnMobile(this._editBox); + self._beginEditingOnMobile(self._editBox); } - this._editingMode = true; + self._editingMode = true; }; proto._endEditing = function() { From c20ac057b756209345f2a3b0abb98893f6a189ed Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 7 Sep 2017 22:24:30 +0800 Subject: [PATCH 16/28] update TIMER_NAME to DELAY_TIME --- cocos2d/core/editbox/CCSGEditBox.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/editbox/CCSGEditBox.js b/cocos2d/core/editbox/CCSGEditBox.js index 20cd784462..1dd914b28f 100644 --- a/cocos2d/core/editbox/CCSGEditBox.js +++ b/cocos2d/core/editbox/CCSGEditBox.js @@ -28,8 +28,8 @@ // https://segmentfault.com/q/1010000002914610 var SCROLLY = 40; -var TIMER_NAME = 400; var LEFT_PADDING = 2; +var DELAY_TIME = 400; var FOCUS_DELAY_UC = 400; var FOCUS_DELAY_FIREFOX = 0; var Utils = require('../platform/utils'); @@ -49,7 +49,7 @@ function adjustEditBoxPosition (editBox) { if (scrollOffset > 320) scrollOffset = 320; window.scrollTo(scrollOffset, scrollOffset); } - }, TIMER_NAME); + }, DELAY_TIME); } var capitalize = function(string) { @@ -1007,7 +1007,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; // Delay end editing adaptation to ensure virtual keyboard is disapeared setTimeout(function () { self._endEditingOnMobile(); - }, TIMER_NAME); + }, DELAY_TIME); } this._editingMode = false; }; From 19d0b45dc9b4226a849f0ffb1d30c2764de1061f Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 11 Sep 2017 14:45:41 +0800 Subject: [PATCH 17/28] fixed tiledmap culling --- cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js b/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js index 7253514b75..d7d8ff48df 100644 --- a/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js +++ b/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js @@ -121,7 +121,7 @@ proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) { if (enabledCulling) { if (this._cameraFlag > 0) { - var tmpt = cc.affineTransformConcat(cc.Camera.main.viewMatrix, wt); + var tmpt = cc.affineTransformConcat(wt, cc.Camera.main.viewMatrix); cullingA = tmpt.a; cullingD = tmpt.d; cullingMapx = ox * cullingA + oy * tmpt.c + tmpt.tx; From f0a6ad3cee1b3f653e76c3005addb68a6e3a483f Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 11 Sep 2017 14:46:53 +0800 Subject: [PATCH 18/28] remove rotation check from tiledmap culling --- cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js | 6 +++--- cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js b/cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js index 1d1c74ad79..dd90500ffc 100644 --- a/cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js +++ b/cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js @@ -45,7 +45,7 @@ var proto = _ccsg.TMXLayer.CanvasRenderCmd.prototype = Object.create(_ccsg.Node. proto.constructor = _ccsg.TMXLayer.CanvasRenderCmd; proto.rendering = function (ctx, scaleX, scaleY) { - var node = this._node, hasRotation = (node._rotationX || node._rotationY), + var node = this._node, layerOrientation = node.layerOrientation, tiles = node.tiles, alpha = node._opacity / 255; @@ -80,7 +80,7 @@ proto.rendering = function (ctx, scaleX, scaleY) { maxCol = cols, maxRow = rows; if (cc.macro.ENABLE_TILEDMAP_CULLING) { - if (!hasRotation && layerOrientation === Orientation.ORTHO) { + if (layerOrientation === Orientation.ORTHO) { startCol = Math.floor(-(mapx - extw * a) / (maptw * a)); startRow = Math.floor((mapy - exth * d + mapth * rows * d - winh) / (mapth * d)); maxCol = Math.ceil((winw - mapx + extw * a) / (maptw * a)); @@ -171,7 +171,7 @@ proto.rendering = function (ctx, scaleX, scaleY) { right = left + tilew; top = bottom - tileh; // TMX_ORIENTATION_ISO trim - if (!hasRotation && layerOrientation === Orientation.ISO) { + if (layerOrientation === Orientation.ISO) { gb = -mapy + bottom*d; if (gb < -winh-h) { col += Math.floor((-winh - gb)*2/h) - 1; diff --git a/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js b/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js index d7d8ff48df..1dc0b82bb7 100644 --- a/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js +++ b/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js @@ -70,7 +70,7 @@ proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) { // enable Depth Test cc.renderer.setDepthTest(true); - var node = this._node, hasRotation = (node._rotationX || node._rotationY), + var node = this._node, layerOrientation = node.layerOrientation, tiles = node.tiles; @@ -130,7 +130,7 @@ proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) { cullingH = tileh * cullingD; } - if (!hasRotation && layerOrientation === Orientation.ORTHO) { + if (layerOrientation === Orientation.ORTHO) { startCol = Math.floor(-(cullingMapx - extw * cullingA) / (maptw * cullingA)); startRow = Math.floor((cullingMapy - exth * cullingD + mapth * rows * cullingD - winh) / (mapth * cullingD)); maxCol = Math.ceil((winw - cullingMapx + extw * cullingA) / (maptw * cullingA)); @@ -211,7 +211,7 @@ proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) { top = bottom + tileh; // TMX_ORIENTATION_ISO trim - if (enabledCulling && !hasRotation && layerOrientation === Orientation.ISO) { + if (enabledCulling && layerOrientation === Orientation.ISO) { gb = cullingMapy + bottom*cullingD; if (gb > winh+cullingH) { col += Math.floor((gb-winh)*2/cullingH) - 1; From f076f9f575e0cd5f43667f9f7053d20931444800 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Mon, 11 Sep 2017 16:33:54 +0800 Subject: [PATCH 19/28] fix mask clipping area does not match --- cocos2d/shape-nodes/CCDrawNode.js | 58 ++++++++++++++----------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/cocos2d/shape-nodes/CCDrawNode.js b/cocos2d/shape-nodes/CCDrawNode.js index e19b55a924..491786661f 100644 --- a/cocos2d/shape-nodes/CCDrawNode.js +++ b/cocos2d/shape-nodes/CCDrawNode.js @@ -741,43 +741,37 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () { var triangleBytesLen = cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT, trianglesBuffer = this._trianglesArrayBuffer; var locBuffer = this._buffer; - var inset = (outline == false ? 0.5 : 0.0); + + var va, vb, vc; for (i = 0; i < count - 2; i++) { - v0 = cc.pSub(cc.v2(verts[0]), cc.pMult(extrude[0].offset, inset)); - v1 = cc.pSub(cc.v2(verts[i + 1]), cc.pMult(extrude[i + 1].offset, inset)); - v2 = cc.pSub(cc.v2(verts[i + 2]), cc.pMult(extrude[i + 2].offset, inset)); - locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v0, colors: c4bFillColor, texCoords: __t(cc.v2())}, - {vertices: v1, colors: c4bFillColor, texCoords: __t(cc.v2())}, {vertices: v2, colors: c4bFillColor, texCoords: __t(cc.v2())}, - trianglesBuffer, locBuffer.length * triangleBytesLen)); + va = {vertices: verts[0], colors: c4bFillColor, texCoords: __t(cc.v2())}; + vb = {vertices: verts[i + 1], colors: c4bFillColor, texCoords: __t(cc.v2())}; + vc = {vertices: verts[i + 2], colors: c4bFillColor, texCoords: __t(cc.v2())}; + locBuffer.push(new cc.V2F_C4B_T2F_Triangle(va, vb, vc, trianglesBuffer, locBuffer.length * triangleBytesLen)); } + if (outline) { + for (i = 0; i < count; i++) { + var j = (i + 1) % count; + v0 = cc.v2(verts[i]); + v1 = cc.v2(verts[j]); - for (i = 0; i < count; i++) { - var j = (i + 1) % count; - v0 = cc.v2(verts[i]); - v1 = cc.v2(verts[j]); + var n0 = extrude[i].n; + var offset0 = extrude[i].offset; + var offset1 = extrude[j].offset; + var inner0 = cc.pSub(v0, cc.pMult(offset0, borderWidth)); + var inner1 = cc.pSub(v1, cc.pMult(offset1, borderWidth)); + var outer0 = cc.pAdd(v0, cc.pMult(offset0, borderWidth)); + var outer1 = cc.pAdd(v1, cc.pMult(offset1, borderWidth)); - var n0 = extrude[i].n; - var offset0 = extrude[i].offset; - var offset1 = extrude[j].offset; - var inner0 = outline ? cc.pSub(v0, cc.pMult(offset0, borderWidth)) : cc.pSub(v0, cc.pMult(offset0, 0.5)); - var inner1 = outline ? cc.pSub(v1, cc.pMult(offset1, borderWidth)) : cc.pSub(v1, cc.pMult(offset1, 0.5)); - var outer0 = outline ? cc.pAdd(v0, cc.pMult(offset0, borderWidth)) : cc.pAdd(v0, cc.pMult(offset0, 0.5)); - var outer1 = outline ? cc.pAdd(v1, cc.pMult(offset1, borderWidth)) : cc.pAdd(v1, cc.pMult(offset1, 0.5)); + va = { vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0)) }; + vb = { vertices: inner1, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0)) }; + vc = { vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0) }; + locBuffer.push(new cc.V2F_C4B_T2F_Triangle(va, vb, vc, trianglesBuffer, locBuffer.length * triangleBytesLen)); - if (outline) { - locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))}, - {vertices: inner1, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))}, {vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0)}, - trianglesBuffer, locBuffer.length * triangleBytesLen)); - locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))}, - {vertices: outer0, colors: c4bBorderColor, texCoords: __t(n0)}, {vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0)}, - trianglesBuffer, locBuffer.length * triangleBytesLen)); - } else { - locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bFillColor, texCoords: __t(cc.v2())}, - {vertices: inner1, colors: c4bFillColor, texCoords: __t(cc.v2())}, {vertices: outer1, colors: c4bFillColor, texCoords: __t(n0)}, - trianglesBuffer, locBuffer.length * triangleBytesLen)); - locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bFillColor, texCoords: __t(cc.v2())}, - {vertices: outer0, colors: c4bFillColor, texCoords: __t(n0)}, {vertices: outer1, colors: c4bFillColor, texCoords: __t(n0)}, - trianglesBuffer, locBuffer.length * triangleBytesLen)); + va = { vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0)) }; + vb = { vertices: outer0, colors: c4bBorderColor, texCoords: __t(n0) }; + vc = { vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0) }; + locBuffer.push(new cc.V2F_C4B_T2F_Triangle(va, vb, vc, trianglesBuffer, locBuffer.length * triangleBytesLen)); } } extrude = null; From 6ae6cab6800506a71c216e4f6fed266e8fa081ec Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 12 Sep 2017 16:45:53 +0800 Subject: [PATCH 20/28] Fix failed to cancel callback when setting fps --- cocos2d/core/CCGame.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/CCGame.js b/cocos2d/core/CCGame.js index 921aef4b30..94900574c1 100644 --- a/cocos2d/core/CCGame.js +++ b/cocos2d/core/CCGame.js @@ -564,8 +564,8 @@ var game = { } } - director.mainLoop(); self._intervalId = window.requestAnimFrame(callback); + director.mainLoop(); } }; From 0bb9be8e204622cde222afdb4ce2bcafcae49691 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 12 Sep 2017 16:55:13 +0800 Subject: [PATCH 21/28] Improve logic --- cocos2d/core/CCGame.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cocos2d/core/CCGame.js b/cocos2d/core/CCGame.js index 94900574c1..32f486a5e0 100644 --- a/cocos2d/core/CCGame.js +++ b/cocos2d/core/CCGame.js @@ -557,14 +557,12 @@ var game = { callback = function () { if (!self._paused) { + self._intervalId = window.requestAnimFrame(callback); if (frameRate === 30) { if (skip = !skip) { - self._intervalId = window.requestAnimFrame(callback); return; } } - - self._intervalId = window.requestAnimFrame(callback); director.mainLoop(); } }; From 36eac0fbbdb8f3644e4bb7ee27ed2b1dc074057f Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 13 Sep 2017 20:59:30 -0500 Subject: [PATCH 22/28] fix TypeScript def of audioengine --- cocos2d/audio/CCAudioEngine.js | 55 +++++++++++----------------------- 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/cocos2d/audio/CCAudioEngine.js b/cocos2d/audio/CCAudioEngine.js index 227dc9b76a..f02892e6ee 100644 --- a/cocos2d/audio/CCAudioEngine.js +++ b/cocos2d/audio/CCAudioEngine.js @@ -95,7 +95,6 @@ var audioEngine = { * @param {Number} volume - Volume size. * @return {Number} audioId * @example - * //example * var audioID = cc.audioEngine.play(path, false, 0.5); */ play: function (filePath, loop, volume/*, profile*/) { @@ -127,7 +126,6 @@ var audioEngine = { * @param {Number} audioID - audio id. * @param {Boolean} loop - Whether cycle. * @example - * //example * cc.audioEngine.setLoop(id, true); */ setLoop: function (audioID, loop) { @@ -144,7 +142,6 @@ var audioEngine = { * @param {Number} audioID - audio id. * @return {Boolean} Whether cycle. * @example - * //example * cc.audioEngine.isLoop(id); */ isLoop: function (audioID) { @@ -158,10 +155,9 @@ var audioEngine = { * !#en Set the volume of audio. * !#zh 设置音量(0.0 ~ 1.0)。 * @method setVolume - * @param {Number} audioID audio id. - * @param {Number} volume Volume must be in 0.0~1.0 . + * @param {Number} audioID - audio id. + * @param {Number} volume - Volume must be in 0.0~1.0 . * @example - * //example * cc.audioEngine.setVolume(id, 0.5); */ setVolume: function (audioID, volume) { @@ -181,10 +177,9 @@ var audioEngine = { * !#en The volume of the music max value is 1.0,the min value is 0.0 . * !#zh 获取音量(0.0 ~ 1.0)。 * @method getVolume - * @param {Number} audioID audio id. + * @param {Number} audioID - audio id. * @return {Boolean} * @example - * //example * var volume = cc.audioEngine.getVolume(id); */ getVolume: function (audioID) { @@ -198,11 +193,10 @@ var audioEngine = { * !#en Set current time * !#zh 设置当前的音频时间。 * @method setCurrentTime - * @param {Number} audioID audio id. - * @param {Number} sec current time. + * @param {Number} audioID - audio id. + * @param {Number} sec - current time. * @return {Boolean} * @example - * //example * cc.audioEngine.setCurrentTime(id, 2); */ setCurrentTime: function (audioID, sec) { @@ -224,10 +218,9 @@ var audioEngine = { * !#en Get current time * !#zh 获取当前的音频播放时间。 * @method getCurrentTime - * @param {Number} audioID audio id. + * @param {Number} audioID - audio id. * @return {Number} audio current time. * @example - * //example * var time = cc.audioEngine.getCurrentTime(id); */ getCurrentTime: function (audioID) { @@ -241,10 +234,9 @@ var audioEngine = { * !#en Get audio duration * !#zh 获取音频总时长。 * @method getDuration - * @param {Number} audioID audio id. + * @param {Number} audioID - audio id. * @return {Number} audio duration. * @example - * //example * var time = cc.audioEngine.getDuration(id); */ getDuration: function (audioID) { @@ -258,10 +250,9 @@ var audioEngine = { * !#en Get audio state * !#zh 获取音频状态。 * @method getState - * @param {Number} audioID audio id. + * @param {Number} audioID - audio id. * @return {audioEngine.AudioState} audio duration. * @example - * //example * var state = cc.audioEngine.getState(id); */ getState: function (audioID) { @@ -275,10 +266,9 @@ var audioEngine = { * !#en Set Audio finish callback * !#zh 设置一个音频结束后的回调 * @method setFinishCallback - * @param {Number} audioID audio id. - * @param {Function} callback loaded callback. + * @param {Number} audioID - audio id. + * @param {Function} callback - loaded callback. * @example - * //example * cc.audioEngine.setFinishCallback(id, function () {}); */ setFinishCallback: function (audioID, callback) { @@ -297,7 +287,6 @@ var audioEngine = { * @method pause * @param {Number} audioID - The return value of function play. * @example - * //example * cc.audioEngine.pause(audioID); */ pause: function (audioID) { @@ -314,7 +303,6 @@ var audioEngine = { * !#zh 暂停现在正在播放的所有音频。 * @method pauseAll * @example - * //example * cc.audioEngine.pauseAll(); */ pauseAll: function () { @@ -352,7 +340,6 @@ var audioEngine = { * !#zh 恢复播放所有之前暂停的所有音频。 * @method resumeAll * @example - * //example * cc.audioEngine.resumeAll(); */ resumeAll: function () { @@ -370,7 +357,6 @@ var audioEngine = { * @method stop * @param {Number} audioID - The return value of function play. * @example - * //example * cc.audioEngine.stop(audioID); */ stop: function (audioID) { @@ -387,7 +373,6 @@ var audioEngine = { * !#zh 停止正在播放的所有音频。 * @method stopAll * @example - * //example * cc.audioEngine.stopAll(); */ stopAll: function () { @@ -404,9 +389,8 @@ var audioEngine = { * !#en Set up an audio can generate a few examples. * !#zh 设置一个音频可以设置几个实例 * @method setMaxAudioInstance - * @param {Number} num a number of instances to be created from within an audio + * @param {Number} num - a number of instances to be created from within an audio * @example - * //example * cc.audioEngine.setMaxAudioInstance(20); */ setMaxAudioInstance: function (num) { @@ -417,9 +401,8 @@ var audioEngine = { * !#en Getting audio can produce several examples. * !#zh 获取一个音频可以设置几个实例 * @method getMaxAudioInstance - * @return {Number} a number of instances to be created from within an audio + * @return {Number} a - number of instances to be created from within an audio * @example - * //example * cc.audioEngine.getMaxAudioInstance(); */ getMaxAudioInstance: function () { @@ -432,7 +415,6 @@ var audioEngine = { * @method uncache * @param {String} filePath * @example - * //example * cc.audioEngine.uncache(filePath); */ uncache: function (filePath) { @@ -453,7 +435,6 @@ var audioEngine = { * !#zh 卸载所有音频。 * @method uncacheAll * @example - * //example * cc.audioEngine.uncacheAll(); */ uncacheAll: function () { @@ -475,13 +456,12 @@ var audioEngine = { * !#zh 预加载一个音频 * @method preload * @param {String} filePath - The file path of an audio. - * @param {Function} callback - The callback of an audio. + * @param {Function} [callback] - The callback of an audio. * @example - * //example * cc.audioEngine.preload(path); */ preload: function (filePath, callback) { - cc.loader.load(filePath, function (error) { + cc.loader.load(filePath, callback && function (error) { if (!error) { callback(); } @@ -489,12 +469,11 @@ var audioEngine = { }, /** - * !#en Set a size, the unit is KB,Over this size is directly resolved into DOM nodes - * !#zh 设置一个以kb为单位的尺寸,大于这个尺寸的音频在加载的时候会强制使用 dom 方式加载 - * @param kb The file path of an audio. + * !#en Set a size, the unit is KB. Over this size is directly resolved into DOM nodes. + * !#zh 设置一个以 KB 为单位的尺寸,大于这个尺寸的音频在加载的时候会强制使用 dom 方式加载 * @method setMaxWebAudioSize + * @param {Number} kb - The file path of an audio. * @example - * //example * cc.audioEngine.setMaxWebAudioSize(300); */ // Because webAudio takes up too much memory,So allow users to manually choose From 4ae6edd5b21a82eda632d230cbe38ea0981ba5a7 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 14 Sep 2017 13:38:37 +0800 Subject: [PATCH 23/28] update Layout api --- cocos2d/core/components/CCLayout.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index 7dde46334a..7315b320d4 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -148,12 +148,16 @@ var HorizontalDirection = cc.Enum({ /** * !#en - * The Layout is a container component, use it to arrange child elements easily. - * But after setting the Layout, the results need to be updated until the next frame, + * The Layout is a container component, use it to arrange child elements easily.
+ * Note:
+ * 1.Scaling and rotation of child nodes are not considered.
+ * 2.After setting the Layout, the results need to be updated until the next frame, * unless you manually call {{#crossLink "Layout/updateLayout:method"}}{{/crossLink}}。 * !#zh - * Layout 组件相当于一个容器,能自动对它的所有子节点进行统一排版。 - * 但是对 Layout 设置后结果需要到下一帧才会更新,除非你设置完以后手动调用 {{#crossLink "Layout/updateLayout:method"}}{{/crossLink}}。 + * Layout 组件相当于一个容器,能自动对它的所有子节点进行统一排版。
+ * 注意:
+ * 1.不会考虑子节点的缩放和旋转。
+ * 2.对 Layout 设置后结果需要到下一帧才会更新,除非你设置完以后手动调用 {{#crossLink "Layout/updateLayout:method"}}{{/crossLink}}。 * @class Layout * @extends Component */ From 65146cc30208d18eb519fad2334a43b3c6c4b9a3 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Thu, 14 Sep 2017 16:13:17 +0800 Subject: [PATCH 24/28] =?UTF-8?q?can=20not=20set=20content=20size=20of=20R?= =?UTF-8?q?ichText=20by=20using=20public=20function=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos2d/core/components/CCRichText.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCRichText.js b/cocos2d/core/components/CCRichText.js index 0c6e5eea26..aecbf8715f 100644 --- a/cocos2d/core/components/CCRichText.js +++ b/cocos2d/core/components/CCRichText.js @@ -559,7 +559,6 @@ var RichText = cc.Class({ } this._textArray = newTextArray; - var sgNode = this._sgNode; this._resetState(); var lastEmptyLine = false; @@ -627,7 +626,10 @@ var RichText = cc.Class({ } this._labelHeight = this._lineCount * this.lineHeight; + // trigger "size-changed" event this.node.setContentSize(this._labelWidth, this._labelHeight); + // use _setContentSize because sgNode.setContentSize is banned. + this._sgNode._setContentSize(this._labelWidth, this._labelHeight); this._updateRichTextPosition(); this._layoutDirty = false; From a057191a984f0d366f969332c88d48cd7fb27617 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Fri, 15 Sep 2017 14:27:09 +0800 Subject: [PATCH 25/28] add handleTouchEvent to CCRichText for fireball/issues/6369 --- cocos2d/core/components/CCRichText.js | 281 +++++++++++++++----------- 1 file changed, 167 insertions(+), 114 deletions(-) diff --git a/cocos2d/core/components/CCRichText.js b/cocos2d/core/components/CCRichText.js index aecbf8715f..2b1e981efb 100644 --- a/cocos2d/core/components/CCRichText.js +++ b/cocos2d/core/components/CCRichText.js @@ -58,7 +58,7 @@ var RichText = cc.Class({ name: 'cc.RichText', extends: cc._RendererUnderSG, - ctor: function() { + ctor: function () { this._textArray = null; this._labelSegments = []; this._labelSegmentsCache = []; @@ -66,9 +66,10 @@ var RichText = cc.Class({ this._resetState(); - if(CC_EDITOR) { + if (CC_EDITOR) { this._updateRichTextStatus = debounce(this._updateRichText, 200); - } else { + } + else { this._updateRichTextStatus = this._updateRichText; } }, @@ -105,7 +106,7 @@ var RichText = cc.Class({ tooltip: CC_DEV && 'i18n:COMPONENT.richtext.horizontal_align', animatable: false, notify: function (oldValue) { - if(this.horizontalAlign === oldValue) return; + if (this.horizontalAlign === oldValue) return; this._layoutDirty = true; this._updateRichTextStatus(); @@ -121,7 +122,7 @@ var RichText = cc.Class({ default: 40, tooltip: CC_DEV && 'i18n:COMPONENT.richtext.font_size', notify: function (oldValue) { - if(this.fontSize === oldValue) return; + if (this.fontSize === oldValue) return; this._layoutDirty = true; this._updateRichTextStatus(); @@ -138,10 +139,10 @@ var RichText = cc.Class({ type: cc.TTFFont, tooltip: CC_DEV && 'i18n:COMPONENT.richtext.font', notify: function (oldValue) { - if(this.font === oldValue) return; + if (this.font === oldValue) return; this._layoutDirty = true; - if(!CC_JSB && this.font) { + if (!CC_JSB && this.font) { this._onTTFLoaded(); } this._updateRichTextStatus(); @@ -157,7 +158,7 @@ var RichText = cc.Class({ default: 0, tooltip: CC_DEV && 'i18n:COMPONENT.richtext.max_width', notify: function (oldValue) { - if(this.maxWidth === oldValue) return; + if (this.maxWidth === oldValue) return; this._layoutDirty = true; this._updateRichTextStatus(); @@ -173,7 +174,7 @@ var RichText = cc.Class({ default: 40, tooltip: CC_DEV && 'i18n:COMPONENT.richtext.line_height', notify: function (oldValue) { - if(this.lineHeight === oldValue) return; + if (this.lineHeight === oldValue) return; this._layoutDirty = true; this._updateRichTextStatus(); @@ -189,12 +190,32 @@ var RichText = cc.Class({ default: null, type: cc.SpriteAtlas, tooltip: CC_DEV && 'i18n:COMPONENT.richtext.image_atlas', - notify: function(oldValue) { - if(this.imageAtlas === oldValue) return; + notify: function (oldValue) { + if (this.imageAtlas === oldValue) return; this._layoutDirty = true; this._updateRichTextStatus(); } + }, + + /** + * !#en + * Once checked, the RichText will block all input events (mouse and touch) within + * the bounding box of the node, preventing the input from penetrating into the underlying node. + * !#zh + * 选中此选项后,RichText 将阻止节点边界框中的所有输入事件(鼠标和触摸),从而防止输入事件穿透到底层节点。 + * @property {Boolean} handleTouchEvent + * @default true + */ + handleTouchEvent: { + default: true, + tooltip: CC_DEV && 'i18n:COMPONENT.richtext.handleTouchEvent', + notify: function (oldValue) { + if (this.handleTouchEvent === oldValue) return; + if (this.enabledInHierarchy) { + this.handleTouchEvent ? this._addEventListeners() : this._removeEventListeners(); + } + } } }, @@ -205,11 +226,23 @@ var RichText = cc.Class({ onEnable: function () { this._super(); - this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this); + if (this.handleTouchEvent) { + this._addEventListeners(); + } }, onDisable: function () { this._super(); + if (this.handleTouchEvent) { + this._removeEventListeners(); + } + }, + + _addEventListeners: function () { + this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this); + }, + + _removeEventListeners: function () { this.node.off(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this); }, @@ -228,24 +261,24 @@ var RichText = cc.Class({ return sgNode; }, - _updateLabelSegmentTextAttributes: function() { - this._labelSegments.forEach(function(item) { + _updateLabelSegmentTextAttributes: function () { + this._labelSegments.forEach(function (item) { this._applyTextAttribute(item); }.bind(this)); }, _initSgNode: function () { this._updateRichText(); - if(!CC_JSB) { + if (!CC_JSB) { this._onTTFLoaded(); } }, _createFontLabel: function (string) { - return _ccsg.Label.pool.get(string, this.font, null, this.fontSize); + return _ccsg.Label.pool.get(string, this.font, null, this.fontSize); }, - _getFontRawUrl: function() { + _getFontRawUrl: function () { var isAsset = this.font instanceof cc.TTFFont; var fntRawUrl = isAsset ? this.font.rawUrl : ''; return fntRawUrl; @@ -253,7 +286,7 @@ var RichText = cc.Class({ _onTTFLoaded: function () { var rawUrl = this._getFontRawUrl(); - if(!rawUrl) return; + if (!rawUrl) return; var self = this; @@ -269,10 +302,11 @@ var RichText = cc.Class({ var self = this; var func = function (string) { var label; - if(self._labelSegmentsCache.length === 0) { + if (self._labelSegmentsCache.length === 0) { label = self._createFontLabel(string); self._labelSegmentsCache.push(label); - } else { + } + else { label = self._labelSegmentsCache[0]; label.setString(string); } @@ -281,33 +315,33 @@ var RichText = cc.Class({ var labelSize = label.getContentSize(); return labelSize.width; }; - if(string) { + if (string) { return func(string); - } else { + } + else { return func; } }, _onTouchEnded: function (event) { - if(!this.enabledInHierarchy) return; - var components = this.node.getComponents(cc.Component); - for (var i = 0; i < this._labelSegments.length; ++i ) { + for (var i = 0; i < this._labelSegments.length; ++i) { var labelSegment = this._labelSegments[i]; var clickHandler = labelSegment._clickHandler; if (clickHandler && this._containsTouchLocation(labelSegment, event.touch.getLocation())) { - components.forEach(function(component) { - if(component.enabledInHierarchy && component[clickHandler]) { + components.forEach(function (component) { + if (component.enabledInHierarchy && component[clickHandler]) { component[clickHandler](event); } }); + event.stopPropagation(); } } }, - _containsTouchLocation:function (label, point) { + _containsTouchLocation: function (label, point) { var myRect = label.getBoundingBoxToWorld(); return cc.rectContainsPoint(myRect, point); }, @@ -328,11 +362,12 @@ var RichText = cc.Class({ this._layoutDirty = true; }, - _addLabelSegment: function(stringToken, styleIndex) { + _addLabelSegment: function (stringToken, styleIndex) { var labelSegment; - if(this._labelSegmentsCache.length === 0) { + if (this._labelSegmentsCache.length === 0) { labelSegment = this._createFontLabel(stringToken); - } else { + } + else { labelSegment = this._labelSegmentsCache.pop(); labelSegment.setString(stringToken); } @@ -349,7 +384,7 @@ var RichText = cc.Class({ //in Web platform, the extra pixels will be trimed. //so we need to set the overflow to clamp in JSB //FIXME: label in jsb should be refactored to keep the behavior the same as web platform. - if(CC_JSB) { + if (CC_JSB) { labelSegment.setOverflow(1); var size = labelSegment.getContentSize(); labelSegment.enableWrap(false); @@ -368,17 +403,18 @@ var RichText = cc.Class({ var checkStartIndex = 0; while (this._lineOffsetX <= this.maxWidth) { var checkEndIndex = this._getFirstWordLen(labelString, - checkStartIndex, - labelString.length); + checkStartIndex, + labelString.length); var checkString = labelString.substr(checkStartIndex, checkEndIndex); var checkStringWidth = this._measureText(styleIndex, checkString); - if(this._lineOffsetX + checkStringWidth <= this.maxWidth) { + if (this._lineOffsetX + checkStringWidth <= this.maxWidth) { this._lineOffsetX += checkStringWidth; checkStartIndex += checkEndIndex; - } else { + } + else { - if(checkStartIndex > 0) { + if (checkStartIndex > 0) { var remainingString = labelString.substr(0, checkStartIndex); this._addLabelSegment(remainingString, styleIndex); @@ -391,33 +427,34 @@ var RichText = cc.Class({ } } } - if(fragmentWidth > this.maxWidth) { + if (fragmentWidth > this.maxWidth) { var fragments = cc.TextUtils.fragmentText(labelString, - fragmentWidth, - this.maxWidth, - this._measureText(styleIndex)); - for(var k = 0; k < fragments.length; ++k) { + fragmentWidth, + this.maxWidth, + this._measureText(styleIndex)); + for (var k = 0; k < fragments.length; ++k) { var splitString = fragments[k]; - labelSegment = this._addLabelSegment(splitString, styleIndex); + labelSegment = this._addLabelSegment(splitString, styleIndex); var labelSize = labelSegment.getContentSize(); this._lineOffsetX += labelSize.width; - if(fragments.length > 1 && k < fragments.length - 1) { + if (fragments.length > 1 && k < fragments.length - 1) { this._updateLineInfo(); } } - } else { + } + else { this._lineOffsetX += fragmentWidth; this._addLabelSegment(labelString, styleIndex); } }, - _isLastComponentCR: function(stringToken) { - return stringToken.length -1 === stringToken.lastIndexOf("\n"); + _isLastComponentCR: function (stringToken) { + return stringToken.length - 1 === stringToken.lastIndexOf("\n"); }, _updateLineInfo: function () { @@ -427,40 +464,43 @@ var RichText = cc.Class({ }, _needsUpdateTextLayout: function (newTextArray) { - if(this._layoutDirty || !this._textArray || !newTextArray) { + if (this._layoutDirty || !this._textArray || !newTextArray) { return true; } - if(this._textArray.length !== newTextArray.length) { + if (this._textArray.length !== newTextArray.length) { return true; } - for(var i = 0; i < this._textArray.length; ++i) { + for (var i = 0; i < this._textArray.length; ++i) { var oldItem = this._textArray[i]; var newItem = newTextArray[i]; - if(oldItem.text != newItem.text) { + if (oldItem.text != newItem.text) { return true; - } else { + } + else { if (oldItem.style) { if (newItem.style) { - if(oldItem.style.size !== newItem.style.size - || oldItem.style.italic !== newItem.style.italic - || oldItem.style.isImage !== newItem.style.isImage) { + if (oldItem.style.size !== newItem.style.size + || oldItem.style.italic !== newItem.style.italic + || oldItem.style.isImage !== newItem.style.isImage) { return true; } - if(oldItem.style.isImage === newItem.style.isImage) { - if(oldItem.style.src !== newItem.style.src) { + if (oldItem.style.isImage === newItem.style.isImage) { + if (oldItem.style.src !== newItem.style.src) { return true; } } - } else { - if(oldItem.style.size || oldItem.style.italic || oldItem.style.isImage) { + } + else { + if (oldItem.style.size || oldItem.style.italic || oldItem.style.isImage) { return true; } } - } else { + } + else { if (newItem.style) { - if(newItem.style.size || newItem.style.italic || newItem.style.isImage) { + if (newItem.style.size || newItem.style.italic || newItem.style.isImage) { return true; } } @@ -472,9 +512,10 @@ var RichText = cc.Class({ _onSpriteFrameLoaded: function (event, spriteFrame) { var newSpriteFrame; - if(spriteFrame) { + if (spriteFrame) { newSpriteFrame = spriteFrame; - } else { + } + else { newSpriteFrame = event.target; } var sprite = newSpriteFrame.__sprite; @@ -482,10 +523,11 @@ var RichText = cc.Class({ }, _applySpriteFrame: function (spriteFrame) { - if(spriteFrame) { - if(spriteFrame.textureLoaded()) { + if (spriteFrame) { + if (spriteFrame.textureLoaded()) { this._onSpriteFrameLoaded(null, spriteFrame); - } else { + } + else { spriteFrame.once('load', this._onSpriteFrameLoaded, this); spriteFrame.ensureLoadTexture(); } @@ -495,7 +537,7 @@ var RichText = cc.Class({ _addRichTextImageElement: function (richTextElement) { var spriteFrameName = richTextElement.style.src; var spriteFrame = this.imageAtlas.getSpriteFrame(spriteFrameName); - if(spriteFrame) { + if (spriteFrame) { var sprite = new cc.Scale9Sprite(); sprite.setAnchorPoint(0, 0); spriteFrame.__sprite = sprite; @@ -510,27 +552,29 @@ var RichText = cc.Class({ var expectHeight = richTextElement.style.imageHeight; //follow the original rule, expectHeight must less then lineHeight - if(expectHeight > 0 && expectHeight < this.lineHeight ) { + if (expectHeight > 0 && expectHeight < this.lineHeight) { scaleFactor = expectHeight / spriteHeight; spriteWidth = spriteWidth * scaleFactor; spriteHeight = spriteHeight * scaleFactor; - } else { + } + else { scaleFactor = this.lineHeight / spriteHeight; spriteWidth = spriteWidth * scaleFactor; spriteHeight = spriteHeight * scaleFactor; } - if(expectWidth > 0) spriteWidth = expectWidth; + if (expectWidth > 0) spriteWidth = expectWidth; - if(this.maxWidth > 0) { - if(this._lineOffsetX + spriteWidth > this.maxWidth) { + if (this.maxWidth > 0) { + if (this._lineOffsetX + spriteWidth > this.maxWidth) { this._updateLineInfo(); } this._lineOffsetX += spriteWidth; - } else { + } + else { this._lineOffsetX += spriteWidth; - if(this._lineOffsetX > this._labelWidth) { + if (this._lineOffsetX > this._labelWidth) { this._labelWidth = this._lineOffsetX; } } @@ -538,12 +582,13 @@ var RichText = cc.Class({ sprite.setContentSize(spriteWidth, spriteHeight); sprite._lineCount = this._lineCount; - if(richTextElement.style.event) { - if(richTextElement.style.event.click) { + if (richTextElement.style.event) { + if (richTextElement.style.event.click) { sprite._clickHandler = richTextElement.style.event.click; } } - } else { + } + else { cc.warnID(4400); } }, @@ -552,7 +597,7 @@ var RichText = cc.Class({ if (!this.enabled) return; var newTextArray = cc.htmlTextParser.parse(this.string); - if(!this._needsUpdateTextLayout(newTextArray)) { + if (!this._needsUpdateTextLayout(newTextArray)) { this._textArray = newTextArray; this._updateLabelSegmentTextAttributes(); return; @@ -569,12 +614,12 @@ var RichText = cc.Class({ var richTextElement = this._textArray[i]; var text = richTextElement.text; //handle
tag - if(text === "") { - if(richTextElement.style && richTextElement.style.newline) { + if (text === "") { + if (richTextElement.style && richTextElement.style.newline) { this._updateLineInfo(); continue; } - if(richTextElement.style && richTextElement.style.isImage && this.imageAtlas) { + if (richTextElement.style && richTextElement.style.isImage && this.imageAtlas) { this._addRichTextImageElement(richTextElement); continue; } @@ -583,10 +628,10 @@ var RichText = cc.Class({ for (var j = 0; j < multilineTexts.length; ++j) { var labelString = multilineTexts[j]; - if(labelString === "") { + if (labelString === "") { //for continues \n - if(this._isLastComponentCR(text) - && j == multilineTexts.length - 1) { + if (this._isLastComponentCR(text) + && j == multilineTexts.length - 1) { continue; } this._updateLineInfo(); @@ -595,33 +640,34 @@ var RichText = cc.Class({ } lastEmptyLine = false; - if(this.maxWidth > 0) { + if (this.maxWidth > 0) { var labelWidth = this._measureText(i, labelString); this._updateRichTextWithMaxWidth(labelString, labelWidth, i); - if(multilineTexts.length > 1 && j < multilineTexts.length - 1) { + if (multilineTexts.length > 1 && j < multilineTexts.length - 1) { this._updateLineInfo(); } - } else { + } + else { label = this._addLabelSegment(labelString, i); labelSize = label.getContentSize(); this._lineOffsetX += labelSize.width; - if(this._lineOffsetX > this._labelWidth) { + if (this._lineOffsetX > this._labelWidth) { this._labelWidth = this._lineOffsetX; } - if(multilineTexts.length > 1 && j < multilineTexts.length - 1) { + if (multilineTexts.length > 1 && j < multilineTexts.length - 1) { this._updateLineInfo(); } } } } - if(!lastEmptyLine) { + if (!lastEmptyLine) { this._linesWidth.push(this._lineOffsetX); } - if(this.maxWidth > 0) { + if (this.maxWidth > 0) { this._labelWidth = this.maxWidth; } this._labelHeight = this._lineCount * this.lineHeight; @@ -636,7 +682,7 @@ var RichText = cc.Class({ }, - _getFirstWordLen: function(text, startIndex, textLen) { + _getFirstWordLen: function (text, startIndex, textLen) { var character = text.charAt(startIndex); if (cc.TextUtils.isUnicodeCJK(character) || cc.TextUtils.isUnicodeSpace(character)) { @@ -661,7 +707,7 @@ var RichText = cc.Class({ var nextTokenX = 0; var nextLineIndex = 1; var totalLineCount = this._lineCount; - for(var i = 0; i < this._labelSegments.length; ++i) { + for (var i = 0; i < this._labelSegments.length; ++i) { var label = this._labelSegments[i]; var lineCount = label._lineCount; if (lineCount > nextLineIndex) { @@ -670,17 +716,17 @@ var RichText = cc.Class({ } var lineOffsetX = 0; switch (this.horizontalAlign) { - case cc.TextAlignment.LEFT: - lineOffsetX = 0; - break; - case cc.TextAlignment.CENTER: - lineOffsetX = (this._labelWidth - this._linesWidth[lineCount - 1]) / 2; - break; - case cc.TextAlignment.RIGHT: - lineOffsetX = this._labelWidth - this._linesWidth[lineCount - 1]; - break; - default: - break; + case cc.TextAlignment.LEFT: + lineOffsetX = 0; + break; + case cc.TextAlignment.CENTER: + lineOffsetX = (this._labelWidth - this._linesWidth[lineCount - 1]) / 2; + break; + case cc.TextAlignment.RIGHT: + lineOffsetX = this._labelWidth - this._linesWidth[lineCount - 1]; + break; + default: + break; } label.setPositionX(nextTokenX + lineOffsetX); @@ -688,7 +734,7 @@ var RichText = cc.Class({ var positionY = (totalLineCount - lineCount) * this.lineHeight; - if(label instanceof cc.Scale9Sprite) { + if (label instanceof cc.Scale9Sprite) { positionY += (this.lineHeight - label.getContentSize().height) / 2; } @@ -705,13 +751,14 @@ var RichText = cc.Class({ var colorValue = color.toUpperCase(); if (cc.Color[colorValue]) { return cc.Color[colorValue]; - } else { + } + else { return cc.hexToColor(color); } }, _applyTextAttribute: function (label) { - if(label instanceof cc.Scale9Sprite) return; + if (label instanceof cc.Scale9Sprite) return; var index = label._styleIndex; label.setLineHeight(this.lineHeight); @@ -723,25 +770,29 @@ var RichText = cc.Class({ } if (textStyle && textStyle.color) { label.setColor(this._convertLiteralColorValue(textStyle.color)); - } else { + } + else { label.setColor(this.node.color); } if (textStyle && textStyle.bold) { label.enableBold(true); - } else { + } + else { label.enableBold(false); } if (textStyle && textStyle.italic) { label.enableItalics(true); - } else { + } + else { label.enableItalics(false); } if (textStyle && textStyle.underline) { label.enableUnderline(true); - } else { + } + else { label.enableUnderline(false); } @@ -750,14 +801,16 @@ var RichText = cc.Class({ label.setOutlineColor(this._convertLiteralColorValue(textStyle.outline.color)); label.setOutlineWidth(textStyle.outline.width); label.setMargin(textStyle.outline.width); - } else { + } + else { label.setOutlined(false); label.setMargin(0); } if (textStyle && textStyle.size) { label.setFontSize(textStyle.size); - } else { + } + else { label.setFontSize(this.fontSize); } @@ -776,6 +829,6 @@ var RichText = cc.Class({ } this._resetState(); } - }); +}); cc.RichText = module.exports = RichText; From cb9f2b477730701f996ae5dbae59805372ea063c Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 18 Sep 2017 10:31:46 +0800 Subject: [PATCH 26/28] fixed hitTest --- cocos2d/core/CCNode.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 190a3eb8eb..613515b005 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -1296,8 +1296,9 @@ var Node = cc.Class({ h = this.height; var rect = cc.rect(0, 0, w, h); - if (cc.Camera && cc.Camera.main) { - point = cc.Camera.main.getCameraToWorldPoint(point); + var Camera = cc.Camera; + if (Camera && Camera.main && Camera.main.containsNode(this)) { + point = Camera.main.getCameraToWorldPoint(point); } var trans = this.getNodeToWorldTransform(); From 15ef9ba0d3fae11dbd05e3786b9ec8ca5c352958 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Thu, 21 Sep 2017 14:05:59 +0800 Subject: [PATCH 27/28] fixed duplicate definition --- cocos2d/core/graphics/graphics-webgl-cmd.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/graphics/graphics-webgl-cmd.js b/cocos2d/core/graphics/graphics-webgl-cmd.js index e1ae212e7b..dd0f08f17e 100644 --- a/cocos2d/core/graphics/graphics-webgl-cmd.js +++ b/cocos2d/core/graphics/graphics-webgl-cmd.js @@ -743,9 +743,9 @@ _p._expandFill = function () { if (path.complex) { var data = []; var start = offset*VERTS_FLOAT_LENGTH, end = buffer.vertsOffset*VERTS_FLOAT_LENGTH; - for (var i = start; i < end; i+=VERTS_FLOAT_LENGTH) { - data.push(buffer.vertsBuffer[i]); - data.push(buffer.vertsBuffer[i+1]); + for (var j = start; j < end; j+=VERTS_FLOAT_LENGTH) { + data.push(buffer.vertsBuffer[j]); + data.push(buffer.vertsBuffer[j+1]); } var newIndices = Earcut(data, null, 2); From 320d5d59150639e91538b739421a5a994db862f7 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 21 Sep 2017 16:51:43 +0800 Subject: [PATCH 28/28] fix webview event error for fireball/issues/6328 --- cocos2d/core/components/CCWebView.js | 29 ++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/components/CCWebView.js b/cocos2d/core/components/CCWebView.js index aebea9cbb1..04943678dd 100644 --- a/cocos2d/core/components/CCWebView.js +++ b/cocos2d/core/components/CCWebView.js @@ -47,6 +47,9 @@ var EventType = _ccsg.WebView.EventType; * @property {String} ERROR */ +// +function emptyCallback () { } + /** * !#en cc.WebView is a component for display web pages in the game * !#zh WebView 组件,用于在游戏中显示网页 @@ -124,12 +127,6 @@ var WebView = cc.Class({ sgNode.createDomElementIfNeeded(); } - if (!CC_EDITOR) { - sgNode.setEventListener(EventType.LOADED, this._onWebViewLoaded.bind(this)); - sgNode.setEventListener(EventType.LOADING, this._onWebViewLoading.bind(this)); - sgNode.setEventListener(EventType.ERROR, this._onWebViewLoadError.bind(this)); - } - sgNode.loadURL(this._url); if (CC_EDITOR && this._useOriginalSize) { @@ -140,6 +137,26 @@ var WebView = cc.Class({ } }, + onEnable: function () { + this._super(); + if (!CC_EDITOR) { + var sgNode = this._sgNode; + sgNode.setEventListener(EventType.LOADED, this._onWebViewLoaded.bind(this)); + sgNode.setEventListener(EventType.LOADING, this._onWebViewLoading.bind(this)); + sgNode.setEventListener(EventType.ERROR, this._onWebViewLoadError.bind(this)); + } + }, + + onDisable: function () { + this._super(); + if (!CC_EDITOR) { + var sgNode = this._sgNode; + sgNode.setEventListener(EventType.LOADED, emptyCallback); + sgNode.setEventListener(EventType.LOADING, emptyCallback); + sgNode.setEventListener(EventType.ERROR, emptyCallback); + } + }, + _onWebViewLoaded: function () { cc.Component.EventHandler.emitEvents(this.webviewEvents, this, EventType.LOADED); this.node.emit('loaded', this);