From e15de2bfd64c2beb8e5059560e1453f7566b6e71 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 3 Jul 2017 16:39:59 +0800 Subject: [PATCH 1/4] export function from PolygonSeparator --- .../physics/{CCPolygonSeprator.js => CCPolygonSeparator.js} | 6 +++++- cocos2d/core/physics/collider/CCPhysicsPolygonCollider.js | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) rename cocos2d/core/physics/{CCPolygonSeprator.js => CCPolygonSeparator.js} (98%) diff --git a/cocos2d/core/physics/CCPolygonSeprator.js b/cocos2d/core/physics/CCPolygonSeparator.js similarity index 98% rename from cocos2d/core/physics/CCPolygonSeprator.js rename to cocos2d/core/physics/CCPolygonSeparator.js index 22ccabd6ac..330033bcd9 100644 --- a/cocos2d/core/physics/CCPolygonSeprator.js +++ b/cocos2d/core/physics/CCPolygonSeparator.js @@ -312,4 +312,8 @@ function Area(a, b, c) { return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y); } -module.exports = ConvexPartition; +cc.PolygonSeparator = module.exports = { + ConvexPartition: ConvexPartition, + ForceCounterClockWise: ForceCounterClockWise, + IsCounterClockWise: IsCounterClockWise +}; diff --git a/cocos2d/core/physics/collider/CCPhysicsPolygonCollider.js b/cocos2d/core/physics/collider/CCPhysicsPolygonCollider.js index cc946132db..c61d6438f0 100644 --- a/cocos2d/core/physics/collider/CCPhysicsPolygonCollider.js +++ b/cocos2d/core/physics/collider/CCPhysicsPolygonCollider.js @@ -24,7 +24,7 @@ ****************************************************************************/ var PTM_RATIO = require('../CCPhysicsTypes').PTM_RATIO; -var PolygonSeprator = require('../CCPolygonSeprator'); +var PolygonSeparator = require('../CCPolygonSeparator'); /** * @class PhysicsPolygonCollider @@ -52,7 +52,7 @@ var PhysicsPolygonCollider = cc.Class({ points.length -= 1; } - var polys = PolygonSeprator(points); + var polys = PolygonSeparator.ConvexPartition(points); var offset = this.offset; for (var i = 0; i < polys.length; i++) { From a46c32ea75a488637c5f16e0df998d58870be954 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 3 Jul 2017 17:02:53 +0800 Subject: [PATCH 2/4] refine code --- cocos2d/core/physics/CCPolygonSeparator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/physics/CCPolygonSeparator.js b/cocos2d/core/physics/CCPolygonSeparator.js index 330033bcd9..dd14c21500 100644 --- a/cocos2d/core/physics/CCPolygonSeparator.js +++ b/cocos2d/core/physics/CCPolygonSeparator.js @@ -312,7 +312,7 @@ function Area(a, b, c) { return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y); } -cc.PolygonSeparator = module.exports = { +module.exports = { ConvexPartition: ConvexPartition, ForceCounterClockWise: ForceCounterClockWise, IsCounterClockWise: IsCounterClockWise From fd89b551f11ff899f2fc433019099d139630ea02 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Wed, 5 Jul 2017 16:29:37 +0800 Subject: [PATCH 3/4] #5920 Audio preload error --- cocos2d/audio/CCAudio.js | 8 ++++++++ cocos2d/core/components/CCAudioSource.js | 14 +++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index e86787a786..247d9226f3 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -127,6 +127,14 @@ Audio.State = { } }; + proto.unmount = function () { + this._src = ''; + this._audioType = Audio.Type.UNKNOWN; + this._element = null; + this._state = Audio.State.INITIALZING; + this._loaded = false; + }; + proto.mount = function (elem) { if (elem instanceof HTMLElement) { this._element = document.createElement('audio'); diff --git a/cocos2d/core/components/CCAudioSource.js b/cocos2d/core/components/CCAudioSource.js index 91d2cd5a44..94ea539a9c 100644 --- a/cocos2d/core/components/CCAudioSource.js +++ b/cocos2d/core/components/CCAudioSource.js @@ -41,7 +41,11 @@ var AudioSource = cc.Class({ }, ctor: function () { - this.audio = new cc.Audio(this._clip); + this.audio = new cc.Audio(); + }, + + onLoad: function () { + this.clip = this._clip; }, properties: { @@ -93,8 +97,12 @@ var AudioSource = cc.Class({ this._clip = value; this.audio.stop(); this.audio.src = this._clip; - if (this.audio.preload) { - this.audio.preload(); + if (value) { + if (this.audio.preload) { + this.audio.preload(); + } + } else { + this.audio.unmount(); } }, url: cc.AudioClip, From 62cb07094c0baba4c824d0e507bcbca5e3fd0567 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Thu, 6 Jul 2017 09:58:36 +0800 Subject: [PATCH 4/4] #5920 review code --- cocos2d/audio/CCAudio.js | 21 +++++++++++---------- cocos2d/core/components/CCAudioSource.js | 8 ++------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index 247d9226f3..12175071e6 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -85,8 +85,17 @@ Audio.State = { (function (proto) { proto.preload = function () { - var src = this._src, - audio = this; + var src = this._src, audio = this; + + if (!src) { + this._src = ''; + this._audioType = Audio.Type.UNKNOWN; + this._element = null; + this._state = Audio.State.INITIALZING; + this._loaded = false; + return; + } + var item = cc.loader.getItem(src); if (!item) { @@ -127,14 +136,6 @@ Audio.State = { } }; - proto.unmount = function () { - this._src = ''; - this._audioType = Audio.Type.UNKNOWN; - this._element = null; - this._state = Audio.State.INITIALZING; - this._loaded = false; - }; - proto.mount = function (elem) { if (elem instanceof HTMLElement) { this._element = document.createElement('audio'); diff --git a/cocos2d/core/components/CCAudioSource.js b/cocos2d/core/components/CCAudioSource.js index 94ea539a9c..37da741dd2 100644 --- a/cocos2d/core/components/CCAudioSource.js +++ b/cocos2d/core/components/CCAudioSource.js @@ -97,12 +97,8 @@ var AudioSource = cc.Class({ this._clip = value; this.audio.stop(); this.audio.src = this._clip; - if (value) { - if (this.audio.preload) { - this.audio.preload(); - } - } else { - this.audio.unmount(); + if (this.audio.preload) { + this.audio.preload(); } }, url: cc.AudioClip,