diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index a34a3a30c9..f3cf247b6e 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -174,7 +174,7 @@ Audio.State = { }; proto.resume = function () { - if (!this._element || this._element.currentTime === 0) return; + if (!this._element || this._state === Audio.State.PLAYING) return; this._bindEnded(); this._element.play(); this._state = Audio.State.PLAYING; diff --git a/cocos2d/audio/CCAudioEngine.js b/cocos2d/audio/CCAudioEngine.js index 42548a9404..cffe06ddf6 100644 --- a/cocos2d/audio/CCAudioEngine.js +++ b/cocos2d/audio/CCAudioEngine.js @@ -328,12 +328,7 @@ var audioEngine = { resume: function (audioID) { var audio = getAudioFromId(audioID); if (audio) { - if (audio.getCurrentTime() === 0) { - audio.play(); - } - else { - audio.resume(); - } + audio.resume(); } }, diff --git a/cocos2d/core/components/CCAnimation.js b/cocos2d/core/components/CCAnimation.js index 98f6f214b3..37009d77df 100644 --- a/cocos2d/core/components/CCAnimation.js +++ b/cocos2d/core/components/CCAnimation.js @@ -263,6 +263,14 @@ var Animation = cc.Class({ animator.playState(state, startTime); } + // Animation cannot be played when the component is not enabledInHierarchy. + // That would cause an error for the animation lost the reference after destroying the node. + // If users play the animation when the component is not enabledInHierarchy, + // we pause the animator here so that it will automatically resume the animation when users enable the component. + if (!this.enabledInHierarchy) { + animator.pause(); + } + this.currentClip = state.clip; } return state; diff --git a/cocos2d/core/components/CCScrollView.js b/cocos2d/core/components/CCScrollView.js index 8996df112b..307f6c5a2c 100644 --- a/cocos2d/core/components/CCScrollView.js +++ b/cocos2d/core/components/CCScrollView.js @@ -1249,7 +1249,7 @@ var ScrollView = cc.Class({ } var contentPos = newPosition.sub(this.getContentPosition()); - this._moveContent(contentPos, reachedEnd); + this._moveContent(this._clampDelta(deltaMove), reachedEnd); this._dispatchEvent('scrolling'); if (!this._autoScrolling) { @@ -1337,7 +1337,6 @@ var ScrollView = cc.Class({ this._autoScrollBraking = true; } } - }, _calculateTouchMoveVelocity: function() { @@ -1368,7 +1367,6 @@ var ScrollView = cc.Class({ _moveContent: function(deltaMove, canStartBounceBack) { var adjustedMove = this._flattenVectorByDirection(deltaMove); - var newPosition = this.getContentPosition().add(adjustedMove); this.setContentPosition(newPosition); @@ -1379,10 +1377,8 @@ var ScrollView = cc.Class({ if (this.elastic && canStartBounceBack) { this._startBounceBackIfNeeded(); } - }, - _getContentLeftBoundary: function() { var contentPos = this.getContentPosition(); var leftBoundary = contentPos.x - this.content.getAnchorPoint().x * this.content.getContentSize().width; diff --git a/cocos2d/core/platform/CCSys.js b/cocos2d/core/platform/CCSys.js index c3bfad9320..bc8aae7e4f 100644 --- a/cocos2d/core/platform/CCSys.js +++ b/cocos2d/core/platform/CCSys.js @@ -681,6 +681,14 @@ function initSys () { format: ['.mp3'] }; } + + var version = /[\d\.]+/.exec(env.system); + sys.osVersion = version[0]; + sys.osMainVersion = parseInt(sys.osVersion); + // wechagame subdomain + if (!wx.getFileSystemManager) { + sys.browserType = sys.BROWSER_TYPE_WECHAT_GAME_SUB; + } else { // browser or runtime var win = window, nav = win.navigator, doc = document, docEle = doc.documentElement; diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index ff1df85ed3..c8febfc70e 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -1155,8 +1155,11 @@ var BaseNode = cc.Class({ var myPrefabInfo = this._prefab; if (myPrefabInfo) { if (newPrefabRoot) { - // change prefab - _Scene.PrefabUtils.linkPrefab(newPrefabRoot._prefab.asset, newPrefabRoot, this); + if (myPrefabInfo.root !== newPrefabRoot) { + // change prefab + _Scene.PrefabUtils.unlinkPrefab(this); + _Scene.PrefabUtils.linkPrefab(newPrefabRoot._prefab.asset, newPrefabRoot, this); + } } else if (myPrefabInfo.root !== this) { // detach from prefab