|
115 | 115 | } |
116 | 116 |
|
117 | 117 | private var _armature:Armature; |
118 | | - private var _currentFrame:Frame; |
119 | 118 | private var _timelineStateList:Vector.<TimelineState>; |
120 | 119 | private var _mixingTransforms:Object; |
121 | 120 |
|
122 | 121 | private var _isPlaying:Boolean; |
123 | | - private var _time:Number; |
| 122 | + private var _time:int; |
| 123 | + private var _currentFrameIndex:int; |
| 124 | + private var _currentFramePosition:int; |
| 125 | + private var _currentFrameDuration:int; |
124 | 126 |
|
125 | 127 | private var _pausePlayheadInFade:Boolean; |
126 | 128 | private var _isFadeOut:Boolean; |
|
192 | 194 | return _currentPlayTimes; |
193 | 195 | } |
194 | 196 |
|
195 | | - private var _totalTime:Number; |
| 197 | + private var _totalTime:int; |
196 | 198 | /** |
197 | 199 | * The length of the animation clip in seconds. |
198 | 200 | */ |
199 | 201 | public function get totalTime():Number |
200 | 202 | { |
201 | | - return _totalTime; |
| 203 | + return _totalTime * 0.001; |
202 | 204 | } |
203 | 205 |
|
204 | | - private var _currentTime:Number; |
| 206 | + private var _currentTime:int; |
205 | 207 | /** |
206 | 208 | * The current time of the animation. |
207 | 209 | */ |
208 | 210 | public function get currentTime():Number |
209 | 211 | { |
210 | | - return _currentTime; |
| 212 | + return _currentTime * 0.001; |
211 | 213 | } |
212 | 214 | public function setCurrentTime(value:Number):AnimationState |
213 | 215 | { |
214 | 216 | if(isNaN(value)) |
215 | 217 | { |
216 | 218 | value = 0; |
217 | 219 | } |
218 | | - _currentTime = value; |
| 220 | + _currentTime = value * 1000; |
219 | 221 | _time = _currentTime; |
220 | 222 | return this; |
221 | 223 | } |
|
266 | 268 | } |
267 | 269 | public function setPlayTimes(value:int):AnimationState |
268 | 270 | { |
269 | | - if(Math.round(_totalTime * _clip.frameRate) < 2) |
| 271 | + if(Math.round(_totalTime * 0.001 * _clip.frameRate) < 2) |
270 | 272 | { |
271 | 273 | _playTimes = value < 0?-1:1; |
272 | 274 | } |
273 | 275 | else |
274 | 276 | { |
275 | | - _timeScale = timeScale; |
276 | 277 | _playTimes = value < 0?-value:value; |
277 | 278 | } |
278 | 279 | autoFadeOut = value < 0?true:false; |
|
300 | 301 | autoTween = _clip.autoTween; |
301 | 302 |
|
302 | 303 | //clear |
303 | | - _currentFrame = null; |
| 304 | + _currentFrameIndex = -1; |
304 | 305 | _mixingTransforms = null; |
305 | 306 |
|
306 | 307 | //reset |
307 | 308 | _isComplete = false; |
308 | 309 | _time = 0; |
309 | 310 | _currentPlayTimes = 0; |
310 | | - if(Math.round(_totalTime * _clip.frameRate) < 2 || timeScale == Infinity) |
| 311 | + if(Math.round(_totalTime * 0.001 * _clip.frameRate) < 2 || timeScale == Infinity) |
311 | 312 | { |
312 | 313 | _currentTime = _totalTime; |
313 | 314 | } |
|
646 | 647 | fadeStartFlg = true; |
647 | 648 | } |
648 | 649 |
|
649 | | - //(_fadeState == -1 || _fadeState == 0) && fadeState == -1 |
| 650 | + //(_fadeState == -1 || _fadeState == 0) && fadeState == 1 |
650 | 651 | if(fadeState == 1) |
651 | 652 | { |
652 | 653 | fadeCompleteFlg = true; |
|
708 | 709 | { |
709 | 710 | if(_isPlaying && !_pausePlayheadInFade) |
710 | 711 | { |
711 | | - _time += passedTime; |
| 712 | + _time += passedTime * 1000; |
712 | 713 | } |
713 | 714 |
|
714 | 715 | var startFlg:Boolean = false; |
715 | 716 | var completeFlg:Boolean = false; |
716 | 717 | var loopCompleteFlg:Boolean = false; |
717 | 718 |
|
718 | | - var currentTime:Number = _time; |
| 719 | + var currentTime:int = _time; |
719 | 720 | var currentPlayTimes:int; |
720 | 721 | var isThisComplete:Boolean; |
721 | | - if(_playTimes != 0) |
| 722 | + if(_playTimes == 0) |
722 | 723 | { |
723 | | - var totalTimes:Number = _playTimes * _totalTime; |
| 724 | + isThisComplete = false; |
| 725 | + currentPlayTimes = Math.ceil(Math.abs(currentTime) / _totalTime) || 1; |
| 726 | + //currentTime -= Math.floor(currentTime / _totalTime) * _totalTime; |
| 727 | + currentTime -= int(currentTime / _totalTime) * _totalTime; |
| 728 | + |
| 729 | + if(currentTime < 0) |
| 730 | + { |
| 731 | + currentTime += _totalTime; |
| 732 | + } |
| 733 | + } |
| 734 | + else |
| 735 | + { |
| 736 | + var totalTimes:int = _playTimes * _totalTime; |
724 | 737 | if(currentTime >= totalTimes) |
725 | 738 | { |
726 | 739 | currentTime = totalTimes; |
|
741 | 754 | currentTime += totalTimes; |
742 | 755 | } |
743 | 756 |
|
744 | | - currentPlayTimes = Math.ceil(currentTime/_totalTime) || 1; |
745 | | - //currentTime -= Math.floor(currentTime/_totalTime) * _totalTime; |
746 | | - currentTime -= int(currentTime/_totalTime) * _totalTime; |
| 757 | + currentPlayTimes = Math.ceil(currentTime / _totalTime) || 1; |
| 758 | + //currentTime -= Math.floor(currentTime / _totalTime) * _totalTime; |
| 759 | + currentTime -= int(currentTime / _totalTime) * _totalTime; |
747 | 760 |
|
748 | 761 | if(isThisComplete) |
749 | 762 | { |
750 | 763 | currentTime = _totalTime; |
751 | 764 | } |
752 | 765 | } |
753 | | - else |
754 | | - { |
755 | | - isThisComplete = false; |
756 | | - currentPlayTimes = Math.ceil(Math.abs(currentTime)/_totalTime) || 1; |
757 | | - //currentTime -= Math.floor(currentTime/_totalTime) * _totalTime; |
758 | | - currentTime -= int(currentTime/_totalTime) * _totalTime; |
759 | | - |
760 | | - if(currentTime < 0) |
761 | | - { |
762 | | - currentTime += _totalTime; |
763 | | - } |
764 | | - } |
765 | 766 |
|
766 | 767 | //update timeline |
767 | 768 | _isComplete = isThisComplete; |
|
795 | 796 | } |
796 | 797 |
|
797 | 798 | _currentTime = currentTime; |
798 | | - |
| 799 | + /* |
799 | 800 | if(isThisComplete) |
800 | 801 | { |
801 | 802 | currentTime = _totalTime * 0.999999; |
802 | 803 | } |
803 | 804 | //[0, _totalTime) |
804 | | - updateMainTimeline(currentTime); |
| 805 | + */ |
| 806 | + updateMainTimeline(isThisComplete); |
805 | 807 | } |
806 | 808 |
|
807 | 809 | var event:AnimationEvent; |
|
839 | 841 | } |
840 | 842 | } |
841 | 843 |
|
842 | | - private function updateMainTimeline(currentTime:Number):void |
| 844 | + private function updateMainTimeline(isThisComplete:Boolean):void |
843 | 845 | { |
844 | 846 | var frameList:Vector.<Frame> = _clip.frameList; |
845 | 847 | if(frameList.length > 0) |
846 | 848 | { |
847 | | - var isArrivedAtNewFrame:Boolean = false; |
848 | | - var frameIndex:int = 0; |
849 | | - while(!_currentFrame || currentTime > _currentFrame.position + _currentFrame.duration || currentTime < _currentFrame.position) |
| 849 | + var prevFrame:Frame; |
| 850 | + var currentFrame:Frame; |
| 851 | + while(true) |
850 | 852 | { |
851 | | - if(isArrivedAtNewFrame) |
| 853 | + if(_currentFrameIndex < 0) |
852 | 854 | { |
853 | | - _armature.arriveAtFrame(_currentFrame, null, this, true); |
| 855 | + _currentFrameIndex = 0; |
| 856 | + currentFrame = frameList[_currentFrameIndex]; |
854 | 857 | } |
855 | | - if(_currentFrame) |
| 858 | + else if(_currentTime >= _currentFramePosition + _currentFrameDuration) |
856 | 859 | { |
857 | | - frameIndex = frameList.indexOf(_currentFrame); |
858 | | - frameIndex ++; |
859 | | - if(frameIndex >= frameList.length) |
| 860 | + _currentFrameIndex ++; |
| 861 | + if(_currentFrameIndex >= frameList.length) |
860 | 862 | { |
861 | | - frameIndex = 0; |
| 863 | + if(isThisComplete) |
| 864 | + { |
| 865 | + _currentFrameIndex --; |
| 866 | + break; |
| 867 | + } |
| 868 | + else |
| 869 | + { |
| 870 | + _currentFrameIndex = 0; |
| 871 | + } |
862 | 872 | } |
863 | | - _currentFrame = frameList[frameIndex]; |
| 873 | + currentFrame = frameList[_currentFrameIndex]; |
864 | 874 | } |
865 | | - else |
866 | | - { |
867 | | - _currentFrame = frameList[0]; |
868 | | - } |
869 | | - if(_currentFrame) |
| 875 | + else if(_currentTime < _currentFramePosition) |
870 | 876 | { |
871 | | - isArrivedAtNewFrame = true; |
| 877 | + _currentFrameIndex --; |
| 878 | + if(_currentFrameIndex < 0) |
| 879 | + { |
| 880 | + _currentFrameIndex = frameList.length - 1; |
| 881 | + } |
| 882 | + currentFrame = frameList[_currentFrameIndex]; |
872 | 883 | } |
873 | 884 | else |
874 | 885 | { |
875 | | - isArrivedAtNewFrame = false; |
876 | 886 | break; |
877 | 887 | } |
| 888 | + |
| 889 | + if(prevFrame) |
| 890 | + { |
| 891 | + _armature.arriveAtFrame(prevFrame, null, this, true); |
| 892 | + } |
| 893 | + |
| 894 | + _currentFrameDuration = currentFrame.duration; |
| 895 | + _currentFramePosition = currentFrame.position; |
| 896 | + prevFrame = currentFrame; |
878 | 897 | } |
879 | 898 |
|
880 | | - if(isArrivedAtNewFrame) |
| 899 | + if(currentFrame) |
881 | 900 | { |
882 | | - _armature.arriveAtFrame(_currentFrame, null, this, false); |
| 901 | + _armature.arriveAtFrame(currentFrame, null, this, false); |
883 | 902 | } |
884 | 903 | } |
885 | 904 | } |
886 | 905 |
|
887 | 906 | private function hideBones():void |
888 | 907 | { |
889 | | - for(var timelineName:String in _clip.hideTimelineNameMap) |
| 908 | + for each(var timelineName:String in _clip.hideTimelineNameMap) |
890 | 909 | { |
891 | 910 | var bone:Bone = _armature.getBone(timelineName); |
892 | 911 | if(bone) |
|
898 | 917 |
|
899 | 918 | private function clear():void |
900 | 919 | { |
901 | | - |
902 | | - for each(var timelineState:TimelineState in _timelineStateList) |
| 920 | + var i:int = _timelineStateList.length; |
| 921 | + while(i --) |
903 | 922 | { |
904 | | - TimelineState.returnObject(timelineState); |
| 923 | + removeTimelineState(_timelineStateList[i]); |
905 | 924 | } |
906 | 925 | _timelineStateList.length = 0; |
907 | 926 |
|
908 | 927 | _armature = null; |
909 | | - _currentFrame = null; |
910 | 928 | _clip = null; |
911 | 929 | _mixingTransforms = null; |
912 | 930 | } |
|
0 commit comments