-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix sample and setCurrentTime invalid when animation is not playing. #7943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,7 @@ let EventType = cc.Enum({ | |
| /** | ||
| * !#en Emit when pause animation | ||
| * !#zh 暂停播放时触发 | ||
| * @property {String} PAUSE | ||
| * @property {String} PAUSE | ||
| * @static | ||
| */ | ||
| PAUSE: 'pause', | ||
|
|
@@ -89,7 +89,7 @@ let EventType = cc.Enum({ | |
|
|
||
| /** | ||
| * !#en The animation component is used to play back animations. | ||
| * | ||
| * | ||
| * Animation provide several events to register: | ||
| * - play : Emit when begin playing animation | ||
| * - stop : Emit when stop playing animation | ||
|
|
@@ -99,15 +99,15 @@ let EventType = cc.Enum({ | |
| * - finished : Emit when finish playing animation | ||
| * | ||
| * !#zh Animation 组件用于播放动画。 | ||
| * | ||
| * | ||
| * Animation 提供了一系列可注册的事件: | ||
| * - play : 开始播放时 | ||
| * - stop : 停止播放时 | ||
| * - pause : 暂停播放时 | ||
| * - resume : 恢复播放时 | ||
| * - lastframe : 假如动画循环次数大于 1,当动画播放到最后一帧时 | ||
| * - finished : 动画播放完成时 | ||
| * | ||
| * | ||
| * @class Animation | ||
| * @extends Component | ||
| * @uses EventTarget | ||
|
|
@@ -391,7 +391,7 @@ let Animation = cc.Class({ | |
| return; | ||
| } | ||
| if (name) { | ||
| let state = this._nameToState[name]; | ||
| let state = this.getAnimationState(name); | ||
| if (state) { | ||
| this._animator.resumeState(state); | ||
| } | ||
|
|
@@ -411,7 +411,7 @@ let Animation = cc.Class({ | |
| setCurrentTime: function (time, name) { | ||
| this._init(); | ||
| if (name) { | ||
| let state = this._nameToState[name]; | ||
| let state = this.getAnimationState(name); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处不应该这么做.有点浪费性能. 建议如下: 因为 getAnimationState 里也会执行 _init() . cc @jare @knoxHuang @holycanvas
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if (state) { | ||
| this._animator.setStateTime(state, time); | ||
| } | ||
|
|
@@ -492,7 +492,7 @@ let Animation = cc.Class({ | |
| }, | ||
|
|
||
| /** | ||
| * !#en | ||
| * !#en | ||
| * Remove clip from the animation list. This will remove the clip and any animation states based on it. | ||
| * If there are animation states depand on the clip are playing or clip is defaultClip, it will not delete the clip. | ||
| * But if force is true, then will always remove the clip and any animation states based on it. If clip is defaultClip, defaultClip will be reset to null | ||
|
|
@@ -524,7 +524,7 @@ let Animation = cc.Class({ | |
| else { | ||
| if (!CC_TEST) cc.warnID(3902); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (state && state.isPlaying) { | ||
|
|
@@ -540,7 +540,7 @@ let Animation = cc.Class({ | |
| }); | ||
|
|
||
| if (state) { | ||
| delete this._nameToState[state.name]; | ||
| delete this._nameToState[state.name]; | ||
| } | ||
| }, | ||
|
|
||
|
|
@@ -556,7 +556,7 @@ let Animation = cc.Class({ | |
| this._init(); | ||
|
|
||
| if (name) { | ||
| let state = this._nameToState[name]; | ||
| let state = this.getAnimationState(name); | ||
| if (state) { | ||
| state.sample(); | ||
| } | ||
|
|
@@ -568,7 +568,7 @@ let Animation = cc.Class({ | |
|
|
||
|
|
||
| /** | ||
| * !#en | ||
| * !#en | ||
| * Register animation event callback. | ||
| * The event arguments will provide the AnimationState which emit the event. | ||
| * When play an animation, will auto register the event callback to the AnimationState, and unregister the event callback from the AnimationState when animation stopped. | ||
|
|
@@ -580,7 +580,7 @@ let Animation = cc.Class({ | |
| * @param {String} type - A string representing the event type to listen for. | ||
| * @param {Function} callback - The callback that will be invoked when the event is dispatched. | ||
| * The callback is ignored if it is a duplicate (the callbacks are unique). | ||
| * @param {cc.AnimationState} state | ||
| * @param {cc.AnimationState} state | ||
| * @param {Object} [target] - The target (this object) to invoke the callback, can be null | ||
| * @param {Boolean} [useCapture=false] - When set to true, the capture argument prevents callback | ||
| * from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. | ||
|
|
@@ -596,15 +596,15 @@ let Animation = cc.Class({ | |
| * onPlay: function (type, state) { | ||
| * // callback | ||
| * } | ||
| * | ||
| * | ||
| * // register event to all animation | ||
| * animation.on('play', this.onPlay, this); | ||
| */ | ||
| on: function (type, callback, target, useCapture) { | ||
| this._init(); | ||
|
|
||
| let ret = this._EventTargetOn(type, callback, target, useCapture); | ||
|
|
||
| if (type === 'lastframe') { | ||
| let states = this._nameToState; | ||
| for (let name in states) { | ||
|
|
@@ -665,7 +665,7 @@ let Animation = cc.Class({ | |
|
|
||
| _createStates: function() { | ||
| this._nameToState = js.createMap(true); | ||
|
|
||
| // create animation states | ||
| let state = null; | ||
| let defaultClipState = false; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处不应该这么做.有点浪费性能. 建议如下:
因为执行到 let state = ... 这一行时, 必然是已经 init过了 (否则第一行就return了)
那么何必 再执行一次 getAnimationState 里的init 呢?