From b7ce3032ba6b2a4f12be0950432672aa0bab2d84 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 10 May 2018 16:47:44 +0800 Subject: [PATCH] Fix more issues for 2.0 (#2662) * Use black as camera default clear color * Fix director delta time issue in editor * Fix particle system init and editor update issue * Improve Node API ref --- cocos2d/core/CCDirector.js | 2 ++ cocos2d/core/CCNode.js | 26 ++++++++++++++------------ cocos2d/core/camera/CCCamera.js | 2 +- cocos2d/particle/CCParticleSystem.js | 16 ++++++++++------ 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 017701f714..38d7bf6950 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -916,6 +916,8 @@ cc.Director.prototype = { * Run main loop of director */ mainLoop: CC_EDITOR ? function (deltaTime, updateAnimate) { + this._deltaTime = deltaTime; + // Update if (!this._paused) { this.emit(cc.Director.EVENT_BEFORE_UPDATE); diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 24ec9d7b10..5234171380 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -2508,8 +2508,12 @@ var Node = cc.Class({ }, /** - * !#en Converts a Point to node (local) space coordinates. The result is in Vec2. - * !#zh 将一个点转换到节点 (局部) 坐标系。结果以 Vec2 为单位。 + * !#en Converts a Point to node (local) space coordinates then add the anchor point position. + * So the return position will be related to the left bottom corner of the node's bounding box. + * This equals to the API behavior of cocos2d-x, you probably want to use convertToNodeSpaceAR instead + * !#zh 将一个点转换到节点 (局部) 坐标系,并加上锚点的坐标。
+ * 也就是说返回的坐标是相对于节点包围盒左下角的坐标。
+ * 这个 API 的设计是为了和 cocos2d-x 中行为一致,更多情况下你可能需要使用 convertToNodeSpaceAR。 * @method convertToNodeSpace * @param {Vec2} worldPoint * @return {Vec2} @@ -2527,8 +2531,10 @@ var Node = cc.Class({ }, /** - * !#en Converts a Point to world space coordinates. The result is in Points. - * !#zh 将一个点转换到世界空间坐标系。结果以 Vec2 为单位。 + * !#en Converts a Point related to the left bottom corner of the node's bounding box to world space coordinates. + * This equals to the API behavior of cocos2d-x, you probably want to use convertToWorldSpaceAR instead + * !#zh 将一个相对于节点左下角的坐标位置转换到世界空间坐标系。 + * 这个 API 的设计是为了和 cocos2d-x 中行为一致,更多情况下你可能需要使用 convertToWorldSpaceAR * @method convertToWorldSpace * @param {Vec2} nodePoint * @return {Vec2} @@ -2546,11 +2552,9 @@ var Node = cc.Class({ /** * !#en - * Converts a Point to node (local) space coordinates. The result is in Points.
- * treating the returned/received node point as anchor relative. + * Converts a Point to node (local) space coordinates in which the anchor point is the origin position. * !#zh - * 将一个点转换到节点 (局部) 空间坐标系。结果以 Vec2 为单位。
- * 返回值将基于节点坐标。 + * 将一个点转换到节点 (局部) 空间坐标系,这个坐标系以锚点为原点。 * @method convertToNodeSpaceAR * @param {Vec2} worldPoint * @return {Vec2} @@ -2566,11 +2570,9 @@ var Node = cc.Class({ /** * !#en - * Converts a local Point to world space coordinates.The result is in Points.
- * treating the returned/received node point as anchor relative. + * Converts a Point in node coordinates to world space coordinates. * !#zh - * 将一个点转换到世界空间坐标系。结果以 Vec2 为单位。
- * 返回值将基于世界坐标。 + * 将节点坐标系下的一个点转换到世界空间坐标系。 * @method convertToWorldSpaceAR * @param {Vec2} nodePoint * @return {Vec2} diff --git a/cocos2d/core/camera/CCCamera.js b/cocos2d/core/camera/CCCamera.js index d9eb84ff3e..60f528e674 100644 --- a/cocos2d/core/camera/CCCamera.js +++ b/cocos2d/core/camera/CCCamera.js @@ -95,7 +95,7 @@ let Camera = cc.Class({ properties: { _cullingMask: 0xffffffff, _clearFlags: 0, - _backgroundColor: cc.color(51, 77, 120, 255), + _backgroundColor: cc.color(0, 0, 0, 255), _depth: 0, _zoomRatio: 1, _targetTexture: null, diff --git a/cocos2d/particle/CCParticleSystem.js b/cocos2d/particle/CCParticleSystem.js index 1a1ac2fa54..fee3c3435b 100644 --- a/cocos2d/particle/CCParticleSystem.js +++ b/cocos2d/particle/CCParticleSystem.js @@ -901,6 +901,7 @@ var ParticleSystem = cc.Class({ // vfx handle real particle step process based on GPU shaders this._vfx = new Particles(cc.renderer.device, cc.renderer._forward, this); + this._vfx.stopSystem(); this._vertexFormat = this._vfx.vertexFormat; // Config update flags, vfx constructor has updated with the current config, so not dirty @@ -976,10 +977,10 @@ var ParticleSystem = cc.Class({ onEnable: function () { this._super(); - this._updateMaterial(); - // should add render flag after particle loaded this.node._renderFlag &= !(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA); + + this._updateMaterial(); }, onDestroy: function () { @@ -995,11 +996,12 @@ var ParticleSystem = cc.Class({ this._focused = true; if (this.preview) { this.resetSystem(); + this.node._renderFlag |= RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA; var self = this; this._previewTimer = setInterval(function () { // attemptToReplay - if (self.particleCount === 0 && !self._willStart) { + if (self._vfx && !self._willStart && self.particleCount === 0) { self._willStart = true; setTimeout(function () { self._willStart = false; @@ -1017,6 +1019,7 @@ var ParticleSystem = cc.Class({ if (this.preview) { this.resetSystem(); this.stopSystem(); + this.node._renderFlag &= !(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA); cc.engine.repaintInEditMode(); } if (this._previewTimer) { @@ -1291,9 +1294,7 @@ var ParticleSystem = cc.Class({ this._renderData.uvDirty = true; } // Reactivate material - if (this.enabledInHierarchy) { - this._updateMaterial(); - } + this._updateMaterial(); }, _applySpriteFrame: function (oldFrame) { @@ -1328,6 +1329,9 @@ var ParticleSystem = cc.Class({ _updateMaterial: function () { // cannot be activated if texture not loaded yet if (!this._texture || !this._texture.loaded) { + if (this._spriteFrame) { + this._applySpriteFrame(); + } return; }