From 2bd0f9a45413d19dd8f20e54661caacf0d171786 Mon Sep 17 00:00:00 2001 From: akdcl Date: Mon, 7 Jul 2014 10:56:00 +0800 Subject: [PATCH 01/10] fix bugs --- src/dragonBones/animation/Animation.as | 7 +- src/dragonBones/animation/AnimationState.as | 121 ++++---- src/dragonBones/animation/TimelineState.as | 299 ++++++++++---------- src/dragonBones/objects/AnimationData.as | 11 +- src/dragonBones/objects/Frame.as | 4 +- src/dragonBones/objects/ObjectDataParser.as | 10 +- src/dragonBones/objects/Timeline.as | 2 +- src/dragonBones/objects/XMLDataParser.as | 10 +- src/dragonBones/utils/DBDataUtil.as | 9 +- 9 files changed, 257 insertions(+), 216 deletions(-) diff --git a/src/dragonBones/animation/Animation.as b/src/dragonBones/animation/Animation.as index 5164218..baabada 100644 --- a/src/dragonBones/animation/Animation.as +++ b/src/dragonBones/animation/Animation.as @@ -19,7 +19,7 @@ public static const SAME_LAYER:String = "sameLayer"; public static const SAME_GROUP:String = "sameGroup"; public static const SAME_LAYER_AND_GROUP:String = "sameLayerAndGroup"; - public static const ALL:String = "all"; + public static const ALL:String = "all"; /** * Unrecommended API. Recommend use animationList. @@ -238,12 +238,11 @@ { return null; } - _isPlaying = true; _isFading = true; // - fadeInTime = fadeInTime < 0?(animationData.fadeTime < 0?0.3:animationData.fadeTime):fadeInTime; + fadeInTime = fadeInTime < 0?(animationData.fadeTime < 0?300:animationData.fadeTime):fadeInTime; var durationScale:Number; if(duration < 0) { @@ -251,7 +250,7 @@ } else { - durationScale = duration / animationData.duration; + durationScale = duration * 0.001 / animationData.duration; } playTimes = isNaN(playTimes)?animationData.playTimes:playTimes; diff --git a/src/dragonBones/animation/AnimationState.as b/src/dragonBones/animation/AnimationState.as index e65b9c6..30d0880 100644 --- a/src/dragonBones/animation/AnimationState.as +++ b/src/dragonBones/animation/AnimationState.as @@ -115,12 +115,14 @@ } private var _armature:Armature; - private var _currentFrame:Frame; private var _timelineStateList:Vector.; private var _mixingTransforms:Object; private var _isPlaying:Boolean; - private var _time:Number; + private var _time:int; + private var _currentFrameIndex:int; + private var _currentFramePosition:int; + private var _currentFrameDuration:int; private var _pausePlayheadInFade:Boolean; private var _isFadeOut:Boolean; @@ -192,22 +194,22 @@ return _currentPlayTimes; } - private var _totalTime:Number; + private var _totalTime:int; /** * The length of the animation clip in seconds. */ public function get totalTime():Number { - return _totalTime; + return _totalTime * 0.001; } - private var _currentTime:Number; + private var _currentTime:int; /** * The current time of the animation. */ public function get currentTime():Number { - return _currentTime; + return _currentTime * 0.001; } public function setCurrentTime(value:Number):AnimationState { @@ -215,7 +217,7 @@ { value = 0; } - _currentTime = value; + _currentTime = value * 0.001; _time = _currentTime; return this; } @@ -266,13 +268,12 @@ } public function setPlayTimes(value:int):AnimationState { - if(Math.round(_totalTime * _clip.frameRate) < 2) + if(Math.round(_totalTime * 0.001 * _clip.frameRate) < 2) { _playTimes = value < 0?-1:1; } else { - _timeScale = timeScale; _playTimes = value < 0?-value:value; } autoFadeOut = value < 0?true:false; @@ -300,14 +301,14 @@ autoTween = _clip.autoTween; //clear - _currentFrame = null; + _currentFrameIndex = -1; _mixingTransforms = null; //reset _isComplete = false; _time = 0; _currentPlayTimes = 0; - if(Math.round(_totalTime * _clip.frameRate) < 2 || timeScale == Infinity) + if(Math.round(_totalTime * 0.001 * _clip.frameRate) < 2 || timeScale == Infinity) { _currentTime = _totalTime; } @@ -587,11 +588,18 @@ var timelineState:TimelineState = TimelineState.borrowObject(); timelineState.fadeIn(bone, this, _clip.getTimeline(timelineName)); _timelineStateList.push(timelineState); + bone.addState(timelineState); } } private function removeTimelineState(timelineState:TimelineState):void { + var bone:Bone = _armature.getBone(timelineState.name); + if (bone) + { + bone.removeState(timelineState); + } + var index:int = _timelineStateList.indexOf(timelineState); _timelineStateList.splice(index, 1); TimelineState.returnObject(timelineState); @@ -646,7 +654,7 @@ fadeStartFlg = true; } - //(_fadeState == -1 || _fadeState == 0) && fadeState == -1 + //(_fadeState == -1 || _fadeState == 0) && fadeState == 1 if(fadeState == 1) { fadeCompleteFlg = true; @@ -708,19 +716,19 @@ { if(_isPlaying && !_pausePlayheadInFade) { - _time += passedTime; + _time += passedTime * 1000; } var startFlg:Boolean = false; var completeFlg:Boolean = false; var loopCompleteFlg:Boolean = false; - var currentTime:Number = _time; + var currentTime:int = _time; var currentPlayTimes:int; var isThisComplete:Boolean; if(_playTimes != 0) { - var totalTimes:Number = _playTimes * _totalTime; + var totalTimes:int = _playTimes * _totalTime; if(currentTime >= totalTimes) { currentTime = totalTimes; @@ -741,9 +749,9 @@ currentTime += totalTimes; } - currentPlayTimes = Math.ceil(currentTime/_totalTime) || 1; - //currentTime -= Math.floor(currentTime/_totalTime) * _totalTime; - currentTime -= int(currentTime/_totalTime) * _totalTime; + currentPlayTimes = Math.ceil(currentTime / _totalTime) || 1; + //currentTime -= Math.floor(currentTime / _totalTime) * _totalTime; + currentTime -= int(currentTime / _totalTime) * _totalTime; if(isThisComplete) { @@ -753,9 +761,9 @@ else { isThisComplete = false; - currentPlayTimes = Math.ceil(Math.abs(currentTime)/_totalTime) || 1; - //currentTime -= Math.floor(currentTime/_totalTime) * _totalTime; - currentTime -= int(currentTime/_totalTime) * _totalTime; + currentPlayTimes = Math.ceil(Math.abs(currentTime) / _totalTime) || 1; + //currentTime -= Math.floor(currentTime / _totalTime) * _totalTime; + currentTime -= int(currentTime / _totalTime) * _totalTime; if(currentTime < 0) { @@ -795,13 +803,14 @@ } _currentTime = currentTime; - + /* if(isThisComplete) { currentTime = _totalTime * 0.999999; } //[0, _totalTime) - updateMainTimeline(currentTime); + */ + updateMainTimeline(isThisComplete); } var event:AnimationEvent; @@ -839,54 +848,69 @@ } } - private function updateMainTimeline(currentTime:Number):void + private function updateMainTimeline(isThisComplete:Boolean):void { var frameList:Vector. = _clip.frameList; if(frameList.length > 0) { - var isArrivedAtNewFrame:Boolean = false; - var frameIndex:int = 0; - while(!_currentFrame || currentTime > _currentFrame.position + _currentFrame.duration || currentTime < _currentFrame.position) + var currentFrame:Frame; + while(true) { - if(isArrivedAtNewFrame) + if(currentFrame) { - _armature.arriveAtFrame(_currentFrame, null, this, true); + _armature.arriveAtFrame(currentFrame, null, this, true); } - if(_currentFrame) + + if(_currentFrameIndex < 0) { - frameIndex = frameList.indexOf(_currentFrame); - frameIndex ++; - if(frameIndex >= frameList.length) - { - frameIndex = 0; - } - _currentFrame = frameList[frameIndex]; + _currentFrameIndex = 0; + currentFrame = frameList[_currentFrameIndex]; } - else + else if(_currentTime >= _currentFramePosition + _currentFrameDuration) { - _currentFrame = frameList[0]; + _currentFrameIndex ++; + if(_currentFrameIndex >= frameList.length) + { + if(isThisComplete) + { + _currentFrameIndex --; + break; + } + else + { + _currentFrameIndex = 0; + } + } + currentFrame = frameList[_currentFrameIndex]; } - if(_currentFrame) + else if(_currentTime < _currentFramePosition) { - isArrivedAtNewFrame = true; + _currentFrameIndex --; + if(_currentFrameIndex < 0) + { + _currentFrameIndex = frameList.length - 1; + } + currentFrame = frameList[_currentFrameIndex]; } else { - isArrivedAtNewFrame = false; break; } + + _currentFrameDuration = currentFrame.duration; + _currentFramePosition = currentFrame.position; } - if(isArrivedAtNewFrame) + if(currentFrame) { - _armature.arriveAtFrame(_currentFrame, null, this, false); + _armature.arriveAtFrame(currentFrame, null, this, false); } } } private function hideBones():void { - for(var timelineName:String in _clip.hideTimelineNameMap) + for each(var timelineName:String in _clip.hideTimelineNameMap) { var bone:Bone = _armature.getBone(timelineName); if(bone) @@ -898,15 +922,14 @@ private function clear():void { - - for each(var timelineState:TimelineState in _timelineStateList) + var i:int = _timelineStateList.length; + while(i --) { - TimelineState.returnObject(timelineState); + removeTimelineState(_timelineStateList[i]); } _timelineStateList.length = 0; _armature = null; - _currentFrame = null; _clip = null; _mixingTransforms = null; } diff --git a/src/dragonBones/animation/TimelineState.as b/src/dragonBones/animation/TimelineState.as index 49b1986..5df29c6 100644 --- a/src/dragonBones/animation/TimelineState.as +++ b/src/dragonBones/animation/TimelineState.as @@ -8,6 +8,7 @@ package dragonBones.animation import dragonBones.Slot; import dragonBones.core.dragonBones_internal; import dragonBones.objects.DBTransform; + import dragonBones.objects.Frame; import dragonBones.objects.TimelineCached; import dragonBones.objects.TransformFrame; import dragonBones.objects.TransformTimeline; @@ -89,23 +90,23 @@ package dragonBones.animation /** @private */ dragonBones_internal var _isComplete:Boolean; - private var _updateState:int; - private var _totalTime:Number; - private var _rawAnimationScale:Number; - private var _currentTime:Number; - private var _currentFramePosition:Number; - private var _currentFrameDuration:Number; + private var _totalTime:int; + private var _currentTime:int; + private var _currentFrameIndex:int; + private var _currentFramePosition:int; + private var _currentFrameDuration:int; private var _tweenEasing:Number; private var _tweenTransform:Boolean; private var _tweenScale:Boolean; private var _tweenColor:Boolean; + private var _rawAnimationScale:Number; + private var _updateState:int; private var _armature:Armature; private var _animation:Animation; private var _bone:Bone; private var _animationState:AnimationState; private var _timeline:TransformTimeline; - private var _currentFrame:TransformFrame; private var _originTransform:DBTransform; private var _originPivot:Point; @@ -150,12 +151,12 @@ package dragonBones.animation _animation = _armature.animation; _animationState = animationState; _timeline = timeline; - _currentFrame = null; + _currentFrameIndex = -1; _originTransform = _timeline.originTransform; _originPivot = _timeline.originPivot; _name = _timeline.name; - _totalTime = _animationState.totalTime; + _totalTime = _timeline.duration; _rawAnimationScale = _animationState.clip.scale; _currentTime = -1; @@ -198,8 +199,6 @@ package dragonBones.animation _updateState = 1; break; } - - _bone.addState(this); } /** @private */ @@ -234,11 +233,11 @@ package dragonBones.animation progress /= _timeline.scale; progress += _timeline.offset; - var currentTime:Number = _totalTime * progress; + var currentTime:int = _totalTime * progress; var playTimes:int = _animationState.playTimes; if(playTimes != 0) { - var totalTimes:Number = playTimes * _totalTime; + var totalTimes:int = playTimes * _totalTime; if(currentTime >= totalTimes) { currentTime = totalTimes; @@ -259,9 +258,9 @@ package dragonBones.animation currentTime += totalTimes; } - currentPlayTimes = Math.ceil(currentTime/_totalTime) || 1; - //currentTime -= Math.floor(currentTime/_totalTime) * _totalTime; - currentTime -= int(currentTime/_totalTime) * _totalTime; + currentPlayTimes = Math.ceil(currentTime / _totalTime) || 1; + //currentTime -= Math.floor(currentTime / _totalTime) * _totalTime; + currentTime -= int(currentTime / _totalTime) * _totalTime; if(_isComplete) { @@ -271,9 +270,9 @@ package dragonBones.animation else { _isComplete = false; - currentPlayTimes = Math.ceil(Math.abs(currentTime)/_totalTime) || 1; - //currentTime -= Math.floor(currentTime/_totalTime) * _totalTime; - currentTime -= int(currentTime/_totalTime) * _totalTime; + currentPlayTimes = Math.ceil(Math.abs(currentTime) / _totalTime) || 1; + //currentTime -= Math.floor(currentTime / _totalTime) * _totalTime; + currentTime -= int(currentTime / _totalTime) * _totalTime; if(currentTime < 0) { @@ -284,58 +283,64 @@ package dragonBones.animation if(_currentTime != currentTime) { _currentTime = currentTime; - if(_isComplete) - { - currentTime *= 0.999999; - } - var isArrivedAtNewFrame:Boolean = false; - var frameIndex:int = 0; - while (!_currentFrame || currentTime > _currentFramePosition + _currentFrameDuration || currentTime < _currentFramePosition) + + var frameList:Vector. = _timeline.frameList; + var currentFrame:TransformFrame; + while(true) { - if(isArrivedAtNewFrame) + if(currentFrame) { - _bone.arriveAtFrame(_currentFrame, this, _animationState, true); + _bone.arriveAtFrame(currentFrame, this, _animationState, true); } - if(_currentFrame) + + if(_currentFrameIndex < 0) { - frameIndex = _timeline.frameList.indexOf(_currentFrame) + 1; - if(frameIndex >= _timeline.frameList.length) - { - frameIndex = 0; - } - _currentFrame = _timeline.frameList[frameIndex] as TransformFrame; + _currentFrameIndex = 0; + currentFrame = frameList[_currentFrameIndex] as TransformFrame; } - else + else if(_currentTime >= _currentFramePosition + _currentFrameDuration) { - frameIndex = 0; - _currentFrame = _timeline.frameList[0] as TransformFrame; + _currentFrameIndex ++; + if(_currentFrameIndex >= frameList.length) + { + if(_isComplete) + { + _currentFrameIndex --; + break; + } + else + { + _currentFrameIndex = 0; + } + } + currentFrame = frameList[_currentFrameIndex] as TransformFrame; } - _currentFrameDuration = _currentFrame.duration; - _currentFramePosition = _currentFrame.position; - if(_currentFrame) + else if(_currentTime < _currentFramePosition) { - isArrivedAtNewFrame = true; + _currentFrameIndex --; + if(_currentFrameIndex < 0) + { + _currentFrameIndex = frameList.length - 1; + } + currentFrame = frameList[_currentFrameIndex] as TransformFrame; } else { - isArrivedAtNewFrame = false; break; } + + _currentFrameDuration = currentFrame.duration; + _currentFramePosition = currentFrame.position; } - if(isArrivedAtNewFrame) + if(currentFrame) { - _bone.arriveAtFrame(_currentFrame, this, _animationState, false); + _bone.arriveAtFrame(currentFrame, this, _animationState, false); - _blendEnabled = _currentFrame.displayIndex >= 0; + _blendEnabled = currentFrame.displayIndex >= 0; if(_blendEnabled) { - frameIndex ++; - if(frameIndex >= _timeline.frameList.length) - { - frameIndex = 0; - } - updateToNextFrame(frameIndex, currentPlayTimes); + updateToNextFrame(currentPlayTimes); } else { @@ -353,8 +358,14 @@ package dragonBones.animation } } - private function updateToNextFrame(nextFrameIndex:int, currentPlayTimes:int):void + private function updateToNextFrame(currentPlayTimes:int):void { + var nextFrameIndex:int = _currentFrameIndex + 1; + if(nextFrameIndex >= _timeline.frameList.length) + { + nextFrameIndex = 0; + } + var currentFrame:TransformFrame = _timeline.frameList[_currentFrameIndex] as TransformFrame; var nextFrame:TransformFrame = _timeline.frameList[nextFrameIndex] as TransformFrame; var tweenEnabled:Boolean = false; if( @@ -372,7 +383,7 @@ package dragonBones.animation _tweenEasing = NaN; tweenEnabled = false; } - else if(_currentFrame.displayIndex < 0 || nextFrame.displayIndex < 0) + else if(currentFrame.displayIndex < 0 || nextFrame.displayIndex < 0) { _tweenEasing = NaN; tweenEnabled = false; @@ -382,7 +393,7 @@ package dragonBones.animation _tweenEasing = _animationState.clip.tweenEasing; if(isNaN(_tweenEasing)) { - _tweenEasing = _currentFrame.tweenEasing; + _tweenEasing = currentFrame.tweenEasing; if(isNaN(_tweenEasing)) //frame no tween { tweenEnabled = false; @@ -405,7 +416,7 @@ package dragonBones.animation } else { - _tweenEasing = _currentFrame.tweenEasing; + _tweenEasing = currentFrame.tweenEasing; if(isNaN(_tweenEasing) || _tweenEasing == 10) //frame no tween { _tweenEasing = NaN; @@ -421,18 +432,18 @@ package dragonBones.animation if(tweenEnabled) { //transform - _durationTransform.x = nextFrame.transform.x - _currentFrame.transform.x; - _durationTransform.y = nextFrame.transform.y - _currentFrame.transform.y; - _durationTransform.skewX = nextFrame.transform.skewX - _currentFrame.transform.skewX; - _durationTransform.skewY = nextFrame.transform.skewY - _currentFrame.transform.skewY; + _durationTransform.x = nextFrame.transform.x - currentFrame.transform.x; + _durationTransform.y = nextFrame.transform.y - currentFrame.transform.y; + _durationTransform.skewX = nextFrame.transform.skewX - currentFrame.transform.skewX; + _durationTransform.skewY = nextFrame.transform.skewY - currentFrame.transform.skewY; /* - _durationTransform.scaleX = nextFrame.transform.scaleX - _currentFrame.transform.scaleX; - _durationTransform.scaleY = nextFrame.transform.scaleY - _currentFrame.transform.scaleY; + _durationTransform.scaleX = nextFrame.transform.scaleX - currentFrame.transform.scaleX; + _durationTransform.scaleY = nextFrame.transform.scaleY - currentFrame.transform.scaleY; */ - _durationTransform.scaleX = nextFrame.transform.scaleX - _currentFrame.transform.scaleX + nextFrame.scaleOffset.x; - _durationTransform.scaleY = nextFrame.transform.scaleY - _currentFrame.transform.scaleY + nextFrame.scaleOffset.y; + _durationTransform.scaleX = nextFrame.transform.scaleX - currentFrame.transform.scaleX + nextFrame.scaleOffset.x; + _durationTransform.scaleY = nextFrame.transform.scaleY - currentFrame.transform.scaleY + nextFrame.scaleOffset.y; if(nextFrameIndex == 0) { @@ -440,8 +451,8 @@ package dragonBones.animation _durationTransform.skewY = TransformUtil.formatRadian(_durationTransform.skewY); } - _durationPivot.x = nextFrame.pivot.x - _currentFrame.pivot.x; - _durationPivot.y = nextFrame.pivot.y - _currentFrame.pivot.y; + _durationPivot.x = nextFrame.pivot.x - currentFrame.pivot.x; + _durationPivot.y = nextFrame.pivot.y - currentFrame.pivot.y; if( _durationTransform.x || @@ -455,7 +466,7 @@ package dragonBones.animation ) { _tweenTransform = true; - _tweenScale = _currentFrame.tweenScale; + _tweenScale = currentFrame.tweenScale; } else { @@ -464,17 +475,17 @@ package dragonBones.animation } //color - if(_currentFrame.color && nextFrame.color) + if(currentFrame.color && nextFrame.color) { - _durationColor.alphaOffset = nextFrame.color.alphaOffset - _currentFrame.color.alphaOffset; - _durationColor.redOffset = nextFrame.color.redOffset - _currentFrame.color.redOffset; - _durationColor.greenOffset = nextFrame.color.greenOffset - _currentFrame.color.greenOffset; - _durationColor.blueOffset = nextFrame.color.blueOffset - _currentFrame.color.blueOffset; + _durationColor.alphaOffset = nextFrame.color.alphaOffset - currentFrame.color.alphaOffset; + _durationColor.redOffset = nextFrame.color.redOffset - currentFrame.color.redOffset; + _durationColor.greenOffset = nextFrame.color.greenOffset - currentFrame.color.greenOffset; + _durationColor.blueOffset = nextFrame.color.blueOffset - currentFrame.color.blueOffset; - _durationColor.alphaMultiplier = nextFrame.color.alphaMultiplier - _currentFrame.color.alphaMultiplier; - _durationColor.redMultiplier = nextFrame.color.redMultiplier - _currentFrame.color.redMultiplier; - _durationColor.greenMultiplier = nextFrame.color.greenMultiplier - _currentFrame.color.greenMultiplier; - _durationColor.blueMultiplier = nextFrame.color.blueMultiplier - _currentFrame.color.blueMultiplier; + _durationColor.alphaMultiplier = nextFrame.color.alphaMultiplier - currentFrame.color.alphaMultiplier; + _durationColor.redMultiplier = nextFrame.color.redMultiplier - currentFrame.color.redMultiplier; + _durationColor.greenMultiplier = nextFrame.color.greenMultiplier - currentFrame.color.greenMultiplier; + _durationColor.blueMultiplier = nextFrame.color.blueMultiplier - currentFrame.color.blueMultiplier; if( _durationColor.alphaOffset || @@ -494,18 +505,18 @@ package dragonBones.animation _tweenColor = false; } } - else if(_currentFrame.color) + else if(currentFrame.color) { _tweenColor = true; - _durationColor.alphaOffset = -_currentFrame.color.alphaOffset; - _durationColor.redOffset = -_currentFrame.color.redOffset; - _durationColor.greenOffset = -_currentFrame.color.greenOffset; - _durationColor.blueOffset = -_currentFrame.color.blueOffset; + _durationColor.alphaOffset = -currentFrame.color.alphaOffset; + _durationColor.redOffset = -currentFrame.color.redOffset; + _durationColor.greenOffset = -currentFrame.color.greenOffset; + _durationColor.blueOffset = -currentFrame.color.blueOffset; - _durationColor.alphaMultiplier = 1 - _currentFrame.color.alphaMultiplier; - _durationColor.redMultiplier = 1 - _currentFrame.color.redMultiplier; - _durationColor.greenMultiplier = 1 - _currentFrame.color.greenMultiplier; - _durationColor.blueMultiplier = 1 - _currentFrame.color.blueMultiplier; + _durationColor.alphaMultiplier = 1 - currentFrame.color.alphaMultiplier; + _durationColor.redMultiplier = 1 - currentFrame.color.redMultiplier; + _durationColor.greenMultiplier = 1 - currentFrame.color.greenMultiplier; + _durationColor.blueMultiplier = 1 - currentFrame.color.blueMultiplier; } else if(nextFrame.color) { @@ -538,27 +549,27 @@ package dragonBones.animation { if(_animationState.additiveBlending) { - _transform.x = _currentFrame.transform.x; - _transform.y = _currentFrame.transform.y; - _transform.skewX = _currentFrame.transform.skewX; - _transform.skewY = _currentFrame.transform.skewY; - _transform.scaleX = _currentFrame.transform.scaleX; - _transform.scaleY = _currentFrame.transform.scaleY; + _transform.x = currentFrame.transform.x; + _transform.y = currentFrame.transform.y; + _transform.skewX = currentFrame.transform.skewX; + _transform.skewY = currentFrame.transform.skewY; + _transform.scaleX = currentFrame.transform.scaleX; + _transform.scaleY = currentFrame.transform.scaleY; - _pivot.x = _currentFrame.pivot.x; - _pivot.y = _currentFrame.pivot.y; + _pivot.x = currentFrame.pivot.x; + _pivot.y = currentFrame.pivot.y; } else { - _transform.x = _originTransform.x + _currentFrame.transform.x; - _transform.y = _originTransform.y + _currentFrame.transform.y; - _transform.skewX = _originTransform.skewX + _currentFrame.transform.skewX; - _transform.skewY = _originTransform.skewY + _currentFrame.transform.skewY; - _transform.scaleX = _originTransform.scaleX + _currentFrame.transform.scaleX; - _transform.scaleY = _originTransform.scaleY + _currentFrame.transform.scaleY; + _transform.x = _originTransform.x + currentFrame.transform.x; + _transform.y = _originTransform.y + currentFrame.transform.y; + _transform.skewX = _originTransform.skewX + currentFrame.transform.skewX; + _transform.skewY = _originTransform.skewY + currentFrame.transform.skewY; + _transform.scaleX = _originTransform.scaleX + currentFrame.transform.scaleX; + _transform.scaleY = _originTransform.scaleY + currentFrame.transform.scaleY; - _pivot.x = _originPivot.x + _currentFrame.pivot.x; - _pivot.y = _originPivot.y + _currentFrame.pivot.y; + _pivot.x = _originPivot.x + currentFrame.pivot.x; + _pivot.y = _originPivot.y + currentFrame.pivot.y; } } @@ -568,29 +579,29 @@ package dragonBones.animation { if(_animationState.additiveBlending) { - _transform.scaleX = _currentFrame.transform.scaleX; - _transform.scaleY = _currentFrame.transform.scaleY; + _transform.scaleX = currentFrame.transform.scaleX; + _transform.scaleY = currentFrame.transform.scaleY; } else { - _transform.scaleX = _originTransform.scaleX + _currentFrame.transform.scaleX; - _transform.scaleY = _originTransform.scaleY + _currentFrame.transform.scaleY; + _transform.scaleX = _originTransform.scaleX + currentFrame.transform.scaleX; + _transform.scaleY = _originTransform.scaleY + currentFrame.transform.scaleY; } } if(!_tweenColor && _animationState.displayControl) { - if(_currentFrame.color) + if(currentFrame.color) { _bone.updateColor( - _currentFrame.color.alphaOffset, - _currentFrame.color.redOffset, - _currentFrame.color.greenOffset, - _currentFrame.color.blueOffset, - _currentFrame.color.alphaMultiplier, - _currentFrame.color.redMultiplier, - _currentFrame.color.greenMultiplier, - _currentFrame.color.blueMultiplier, + currentFrame.color.alphaOffset, + currentFrame.color.redOffset, + currentFrame.color.greenOffset, + currentFrame.color.blueOffset, + currentFrame.color.alphaMultiplier, + currentFrame.color.redMultiplier, + currentFrame.color.greenMultiplier, + currentFrame.color.blueMultiplier, true ); } @@ -605,17 +616,18 @@ package dragonBones.animation private function updateTween():void { var progress:Number = (_currentTime - _currentFramePosition) / _currentFrameDuration; - if(_tweenEasing > 0) + if(_tweenEasing) { progress = getEaseValue(progress, _tweenEasing); } + var currentFrame:TransformFrame = _timeline.frameList[_currentFrameIndex] as TransformFrame; if(_tweenTransform) { if(!updateTimelineCached(false)) { - var currentTransform:DBTransform = _currentFrame.transform; - var currentPivot:Point = _currentFrame.pivot; + var currentTransform:DBTransform = currentFrame.transform; + var currentPivot:Point = currentFrame.pivot; if(_animationState.additiveBlending) { //additive blending @@ -655,17 +667,17 @@ package dragonBones.animation if(_tweenColor && _animationState.displayControl) { - if(_currentFrame.color) + if(currentFrame.color) { _bone.updateColor( - _currentFrame.color.alphaOffset + _durationColor.alphaOffset * progress, - _currentFrame.color.redOffset + _durationColor.redOffset * progress, - _currentFrame.color.greenOffset + _durationColor.greenOffset * progress, - _currentFrame.color.blueOffset + _durationColor.blueOffset * progress, - _currentFrame.color.alphaMultiplier + _durationColor.alphaMultiplier * progress, - _currentFrame.color.redMultiplier + _durationColor.redMultiplier * progress, - _currentFrame.color.greenMultiplier + _durationColor.greenMultiplier * progress, - _currentFrame.color.blueMultiplier + _durationColor.blueMultiplier * progress, + currentFrame.color.alphaOffset + _durationColor.alphaOffset * progress, + currentFrame.color.redOffset + _durationColor.redOffset * progress, + currentFrame.color.greenOffset + _durationColor.greenOffset * progress, + currentFrame.color.blueOffset + _durationColor.blueOffset * progress, + currentFrame.color.alphaMultiplier + _durationColor.alphaMultiplier * progress, + currentFrame.color.redMultiplier + _durationColor.redMultiplier * progress, + currentFrame.color.greenMultiplier + _durationColor.greenMultiplier * progress, + currentFrame.color.blueMultiplier + _durationColor.blueMultiplier * progress, true ); } @@ -706,7 +718,7 @@ package dragonBones.animation } } //Math.floor - var framePosition:int = (isNoTweenFrame?_currentFramePosition:_currentTime) * _rawAnimationScale * _armature.cacheFrameRate; + var framePosition:int = (isNoTweenFrame?_currentFramePosition:_currentTime) * 0.001 * _rawAnimationScale * _armature.cacheFrameRate; _bone._frameCachedPosition = framePosition; if(timelineCached.getFrame(framePosition)) { @@ -715,7 +727,7 @@ package dragonBones.animation } else { - _bone._frameCachedDuration = isNoTweenFrame?(_currentFrameDuration * _rawAnimationScale * _armature.cacheFrameRate || 1):1; + _bone._frameCachedDuration = isNoTweenFrame?(_currentFrameDuration * 0.001 * _rawAnimationScale * _armature.cacheFrameRate || 1):1; } } else if(_bone._timelineCached) @@ -734,15 +746,15 @@ package dragonBones.animation private function updateSingleFrame():void { - _currentFrame = _timeline.frameList[0] as TransformFrame; - _bone.arriveAtFrame(_currentFrame, this, _animationState, false); + var currentFrame:TransformFrame = _timeline.frameList[0] as TransformFrame; + _bone.arriveAtFrame(currentFrame, this, _animationState, false); _isComplete = true; _tweenEasing = NaN; _tweenTransform = false; _tweenScale = false; _tweenColor = false; - _blendEnabled = _currentFrame.displayIndex >= 0; + _blendEnabled = currentFrame.displayIndex >= 0; if(_blendEnabled) { /** @@ -778,17 +790,17 @@ package dragonBones.animation if(_animationState.displayControl) { - if(_currentFrame.color) + if(currentFrame.color) { _bone.updateColor( - _currentFrame.color.alphaOffset, - _currentFrame.color.redOffset, - _currentFrame.color.greenOffset, - _currentFrame.color.blueOffset, - _currentFrame.color.alphaMultiplier, - _currentFrame.color.redMultiplier, - _currentFrame.color.greenMultiplier, - _currentFrame.color.blueMultiplier, + currentFrame.color.alphaOffset, + currentFrame.color.redOffset, + currentFrame.color.greenOffset, + currentFrame.color.blueOffset, + currentFrame.color.alphaMultiplier, + currentFrame.color.redMultiplier, + currentFrame.color.greenMultiplier, + currentFrame.color.blueMultiplier, true ); } @@ -802,14 +814,15 @@ package dragonBones.animation private function clear():void { - _bone.removeState(this); - + if(_bone) + { + _bone.removeState(this); + } _bone = null; _armature = null; _animation = null; _animationState = null; _timeline = null; - _currentFrame = null; _originTransform = null; _originPivot = null; } diff --git a/src/dragonBones/objects/AnimationData.as b/src/dragonBones/objects/AnimationData.as index 787eed4..7ed1e2d 100644 --- a/src/dragonBones/objects/AnimationData.as +++ b/src/dragonBones/objects/AnimationData.as @@ -10,10 +10,9 @@ package dragonBones.objects //overwrite frame tweenEase, [-1, 0):ease in, 0:line easing, (0, 1]:ease out, (1, 2]:ease in out public var tweenEasing:Number; public var autoTween:Boolean; - public var lastFrameDuration:Number; + public var lastFrameDuration:int; - //string map - public var hideTimelineNameMap:Object; + public var hideTimelineNameMap:Vector.; private var _timelineList:Vector.; public function get timelineList():Vector. @@ -28,7 +27,8 @@ package dragonBones.objects playTimes = 0; autoTween = true; tweenEasing = NaN; - hideTimelineNameMap = {}; + hideTimelineNameMap = new Vector.; + hideTimelineNameMap.fixed = true; _timelineList = new Vector.; _timelineList.fixed = true; @@ -38,7 +38,8 @@ package dragonBones.objects { super.dispose(); - //clear + hideTimelineNameMap.fixed = false; + hideTimelineNameMap.length = 0; hideTimelineNameMap = null; _timelineList.fixed = false; diff --git a/src/dragonBones/objects/Frame.as b/src/dragonBones/objects/Frame.as index e4709ab..f01c8c1 100644 --- a/src/dragonBones/objects/Frame.as +++ b/src/dragonBones/objects/Frame.as @@ -3,8 +3,8 @@ package dragonBones.objects /** @private */ public class Frame { - public var position:Number; - public var duration:Number; + public var position:int; + public var duration:int; public var action:String; public var event:String; diff --git a/src/dragonBones/objects/ObjectDataParser.as b/src/dragonBones/objects/ObjectDataParser.as index 22c0eda..ef58044 100644 --- a/src/dragonBones/objects/ObjectDataParser.as +++ b/src/dragonBones/objects/ObjectDataParser.as @@ -253,7 +253,7 @@ animationData.frameRate = frameRate; animationData.playTimes = int(animationObject[ConstValues.A_LOOP]); animationData.fadeTime = Number(animationObject[ConstValues.A_FADE_IN_TIME]); - animationData.duration = (Number(animationObject[ConstValues.A_DURATION]) || 1)/ frameRate; + animationData.duration = Math.round((Number(animationObject[ConstValues.A_DURATION]) || 1) / frameRate * 1000); animationData.scale = getNumber(animationObject, ConstValues.A_SCALE, 1) || 0; //use frame tweenEase, NaN //overwrite frame tweenEase, [-1, 0):ease in, 0:line easing, (0, 1]:ease out, (1, 2]:ease in out @@ -262,7 +262,7 @@ parseTimeline(animationObject, animationData, parseMainFrame, frameRate); - var lastFrameDuration:Number = animationData.duration; + var lastFrameDuration:int = animationData.duration; for each(var timelineObject:Object in animationObject[ConstValues.TIMELINE]) { var timeline:TransformTimeline = parseTransformTimeline(timelineObject, animationData.duration, frameRate); @@ -284,7 +284,7 @@ private static function parseTimeline(timelineObject:Object, timeline:Timeline, frameParser:Function, frameRate:uint):void { - var position:Number = 0; + var position:int = 0; var frame:Frame; for each(var frameObject:Object in timelineObject[ConstValues.FRAME]) { @@ -299,7 +299,7 @@ } } - private static function parseTransformTimeline(timelineObject:Object, duration:Number, frameRate:uint):TransformTimeline + private static function parseTransformTimeline(timelineObject:Object, duration:int, frameRate:uint):TransformTimeline { var timeline:TransformTimeline = new TransformTimeline(); timeline.name = timelineObject[ConstValues.A_NAME]; @@ -314,7 +314,7 @@ private static function parseFrame(frameObject:Object, frame:Frame, frameRate:uint):void { - frame.duration = (Number(frameObject[ConstValues.A_DURATION]) || 1) / frameRate; + frame.duration = Math.round((Number(frameObject[ConstValues.A_DURATION]) || 1) / frameRate * 1000); frame.action = frameObject[ConstValues.A_ACTION]; frame.event = frameObject[ConstValues.A_EVENT]; frame.sound = frameObject[ConstValues.A_SOUND]; diff --git a/src/dragonBones/objects/Timeline.as b/src/dragonBones/objects/Timeline.as index ed72d6b..c224009 100644 --- a/src/dragonBones/objects/Timeline.as +++ b/src/dragonBones/objects/Timeline.as @@ -8,7 +8,7 @@ package dragonBones.objects return _frameList; } - public var duration:Number; + public var duration:int; public var scale:Number; public function Timeline() diff --git a/src/dragonBones/objects/XMLDataParser.as b/src/dragonBones/objects/XMLDataParser.as index 8fc574c..42e664e 100644 --- a/src/dragonBones/objects/XMLDataParser.as +++ b/src/dragonBones/objects/XMLDataParser.as @@ -253,7 +253,7 @@ animationData.frameRate = frameRate; animationData.playTimes = int(animationXML.@[ConstValues.A_LOOP]); animationData.fadeTime = Number(animationXML.@[ConstValues.A_FADE_IN_TIME]); - animationData.duration = (Number(animationXML.@[ConstValues.A_DURATION]) || 1) / frameRate; + animationData.duration = Math.round((Number(animationXML.@[ConstValues.A_DURATION]) || 1) / frameRate * 1000); animationData.scale = getNumber(animationXML, ConstValues.A_SCALE, 1) || 0; //use frame tweenEase, NaN //overwrite frame tweenEase, [-1, 0):ease in, 0:line easing, (0, 1]:ease out, (1, 2]:ease in out @@ -262,7 +262,7 @@ parseTimeline(animationXML, animationData, parseMainFrame, frameRate); - var lastFrameDuration:Number = animationData.duration; + var lastFrameDuration:int = animationData.duration; for each(var timelineXML:XML in animationXML[ConstValues.TIMELINE]) { var timeline:TransformTimeline = parseTransformTimeline(timelineXML, animationData.duration, frameRate); @@ -286,7 +286,7 @@ private static function parseTimeline(timelineXML:XML, timeline:Timeline, frameParser:Function, frameRate:uint):void { - var position:Number = 0; + var position:int = 0; var frame:Frame; for each(var frameXML:XML in timelineXML[ConstValues.FRAME]) { @@ -301,7 +301,7 @@ } } - private static function parseTransformTimeline(timelineXML:XML, duration:Number, frameRate:uint):TransformTimeline + private static function parseTransformTimeline(timelineXML:XML, duration:int, frameRate:uint):TransformTimeline { var timeline:TransformTimeline = new TransformTimeline(); timeline.name = timelineXML.@[ConstValues.A_NAME]; @@ -316,7 +316,7 @@ private static function parseFrame(frameXML:XML, frame:Frame, frameRate:uint):void { - frame.duration = (Number(frameXML.@[ConstValues.A_DURATION]) || 1) / frameRate; + frame.duration = Math.round((Number(frameXML.@[ConstValues.A_DURATION]) || 1) / frameRate * 1000); frame.action = frameXML.@[ConstValues.A_ACTION]; frame.event = frameXML.@[ConstValues.A_EVENT]; frame.sound = frameXML.@[ConstValues.A_SOUND]; diff --git a/src/dragonBones/utils/DBDataUtil.as b/src/dragonBones/utils/DBDataUtil.as index 012c0fd..69da2f7 100644 --- a/src/dragonBones/utils/DBDataUtil.as +++ b/src/dragonBones/utils/DBDataUtil.as @@ -260,7 +260,7 @@ package dragonBones.utils } } - private static function getTimelineTransform(timeline:TransformTimeline, position:Number, retult:DBTransform, isGlobal:Boolean):void + private static function getTimelineTransform(timeline:TransformTimeline, position:int, retult:DBTransform, isGlobal:Boolean):void { var frameList:Vector. = timeline.frameList; var i:int = frameList.length; @@ -310,7 +310,12 @@ package dragonBones.utils var boneName:String = boneData.name; if(!animationData.getTimeline(boneName)) { - animationData.hideTimelineNameMap[boneName] = true; + if(animationData.hideTimelineNameMap.indexOf(boneName) < 0) + { + animationData.hideTimelineNameMap.fixed = false; + animationData.hideTimelineNameMap.push(boneName); + animationData.hideTimelineNameMap.fixed = true; + } } } } From cd07429c2c502980fa8f298347be48155dd8acf2 Mon Sep 17 00:00:00 2001 From: akdcl Date: Mon, 7 Jul 2014 14:14:18 +0800 Subject: [PATCH 02/10] fix bug boneData -> boneObject --- src/dragonBones/objects/ObjectDataParser.as | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dragonBones/objects/ObjectDataParser.as b/src/dragonBones/objects/ObjectDataParser.as index ef58044..09f48ef 100644 --- a/src/dragonBones/objects/ObjectDataParser.as +++ b/src/dragonBones/objects/ObjectDataParser.as @@ -150,12 +150,12 @@ parseTransform(boneObject[ConstValues.TRANSFORM], boneData.global); boneData.transform.copy(boneData.global); - for each(var rectangleObject:Object in boneData[ConstValues.RECTANGLE]) + for each(var rectangleObject:Object in boneObject[ConstValues.RECTANGLE]) { boneData.addAreaData(parseRectangleData(rectangleObject)); } - for each(var ellipseObject:Object in boneData[ConstValues.ELLIPSE]) + for each(var ellipseObject:Object in boneObject[ConstValues.ELLIPSE]) { boneData.addAreaData(parseEllipseData(ellipseObject)); } From 120036e5d776d338cec6b0c1816b17ced7974272 Mon Sep 17 00:00:00 2001 From: Chenguang Liu Date: Mon, 7 Jul 2014 14:16:05 +0800 Subject: [PATCH 03/10] change defer parse animation feature to parse the first animation --- src/dragonBones/objects/ObjectDataParser.as | 10 ++++++---- src/dragonBones/objects/XMLDataParser.as | 7 ++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/dragonBones/objects/ObjectDataParser.as b/src/dragonBones/objects/ObjectDataParser.as index ef58044..1caa3f1 100644 --- a/src/dragonBones/objects/ObjectDataParser.as +++ b/src/dragonBones/objects/ObjectDataParser.as @@ -117,11 +117,12 @@ DBDataUtil.transformArmatureData(armatureData); armatureData.sortBoneDataList(); - if(!ifSkipAnimationData) + for each(var animationObject:Object in armatureObject[ConstValues.ANIMATION]) { - for each(var animationObject:Object in armatureObject[ConstValues.ANIMATION]) + armatureData.addAnimationData(parseAnimationData(animationObject, armatureData, frameRate)); + if(ifSkipAnimationData) { - armatureData.addAnimationData(parseAnimationData(animationObject, armatureData, frameRate)); + break; } } @@ -150,6 +151,7 @@ parseTransform(boneObject[ConstValues.TRANSFORM], boneData.global); boneData.transform.copy(boneData.global); + /* for each(var rectangleObject:Object in boneData[ConstValues.RECTANGLE]) { boneData.addAreaData(parseRectangleData(rectangleObject)); @@ -159,7 +161,7 @@ { boneData.addAreaData(parseEllipseData(ellipseObject)); } - + */ return boneData; } diff --git a/src/dragonBones/objects/XMLDataParser.as b/src/dragonBones/objects/XMLDataParser.as index 42e664e..1fc3311 100644 --- a/src/dragonBones/objects/XMLDataParser.as +++ b/src/dragonBones/objects/XMLDataParser.as @@ -118,11 +118,12 @@ DBDataUtil.transformArmatureData(armatureData); armatureData.sortBoneDataList(); - if(!ifSkipAnimationData) + for each(var animationXML:XML in armatureXML[ConstValues.ANIMATION]) { - for each(var animationXML:XML in armatureXML[ConstValues.ANIMATION]) + armatureData.addAnimationData(parseAnimationData(animationXML, armatureData, frameRate)); + if(ifSkipAnimationData) { - armatureData.addAnimationData(parseAnimationData(animationXML, armatureData, frameRate)); + break; } } From 7426223865289d2293c3ec18268de11980aeca66 Mon Sep 17 00:00:00 2001 From: Chenguang Liu Date: Mon, 7 Jul 2014 14:24:20 +0800 Subject: [PATCH 04/10] change defer parse animation feature to parse the first animation --- src/dragonBones/objects/ObjectDataParser.as | 7 ++++--- src/dragonBones/objects/XMLDataParser.as | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/dragonBones/objects/ObjectDataParser.as b/src/dragonBones/objects/ObjectDataParser.as index ef58044..1b59176 100644 --- a/src/dragonBones/objects/ObjectDataParser.as +++ b/src/dragonBones/objects/ObjectDataParser.as @@ -117,11 +117,12 @@ DBDataUtil.transformArmatureData(armatureData); armatureData.sortBoneDataList(); - if(!ifSkipAnimationData) + for each(var animationObject:Object in armatureObject[ConstValues.ANIMATION]) { - for each(var animationObject:Object in armatureObject[ConstValues.ANIMATION]) + armatureData.addAnimationData(parseAnimationData(animationObject, armatureData, frameRate)); + if(ifSkipAnimationData) { - armatureData.addAnimationData(parseAnimationData(animationObject, armatureData, frameRate)); + break; } } diff --git a/src/dragonBones/objects/XMLDataParser.as b/src/dragonBones/objects/XMLDataParser.as index 42e664e..1fc3311 100644 --- a/src/dragonBones/objects/XMLDataParser.as +++ b/src/dragonBones/objects/XMLDataParser.as @@ -118,11 +118,12 @@ DBDataUtil.transformArmatureData(armatureData); armatureData.sortBoneDataList(); - if(!ifSkipAnimationData) + for each(var animationXML:XML in armatureXML[ConstValues.ANIMATION]) { - for each(var animationXML:XML in armatureXML[ConstValues.ANIMATION]) + armatureData.addAnimationData(parseAnimationData(animationXML, armatureData, frameRate)); + if(ifSkipAnimationData) { - armatureData.addAnimationData(parseAnimationData(animationXML, armatureData, frameRate)); + break; } } From 5872dc9a9c0a7bbaf6d08441a932d144ea4c8139 Mon Sep 17 00:00:00 2001 From: akdcl Date: Mon, 7 Jul 2014 14:33:56 +0800 Subject: [PATCH 05/10] update --- src/dragonBones/objects/ObjectDataParser.as | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dragonBones/objects/ObjectDataParser.as b/src/dragonBones/objects/ObjectDataParser.as index 1b59176..11cbf32 100644 --- a/src/dragonBones/objects/ObjectDataParser.as +++ b/src/dragonBones/objects/ObjectDataParser.as @@ -151,14 +151,14 @@ parseTransform(boneObject[ConstValues.TRANSFORM], boneData.global); boneData.transform.copy(boneData.global); - for each(var rectangleObject:Object in boneData[ConstValues.RECTANGLE]) + for each(var rectangleObject:Object in boneObject[ConstValues.RECTANGLE]) { - boneData.addAreaData(parseRectangleData(rectangleObject)); + boneObject.addAreaData(parseRectangleData(rectangleObject)); } - for each(var ellipseObject:Object in boneData[ConstValues.ELLIPSE]) + for each(var ellipseObject:Object in boneObject[ConstValues.ELLIPSE]) { - boneData.addAreaData(parseEllipseData(ellipseObject)); + boneObject.addAreaData(parseEllipseData(ellipseObject)); } return boneData; From 02b032d66f0c7a9dbf5c61f110000fed789bff8b Mon Sep 17 00:00:00 2001 From: Chenguang Liu Date: Mon, 7 Jul 2014 14:53:25 +0800 Subject: [PATCH 06/10] remove framerate from add AnimationToArmature interface --- src/dragonBones/factorys/BaseFactory.as | 4 ++-- src/dragonBones/objects/DataParser.as | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/dragonBones/factorys/BaseFactory.as b/src/dragonBones/factorys/BaseFactory.as index efd50e0..3a8d50c 100644 --- a/src/dragonBones/factorys/BaseFactory.as +++ b/src/dragonBones/factorys/BaseFactory.as @@ -288,9 +288,9 @@ package dragonBones.factorys * @param target armature. * @param frame rate. */ - public function addAnimationToArmature(animationRawData:Object, armature:Armature, frameRate:uint):void + public function addAnimationToArmature(animationRawData:Object, armature:Armature):void { - armature._armatureData.addAnimationData(DataParser.parseAnimationDataByAnimationRawData(animationRawData,armature._armatureData, frameRate)); + armature._armatureData.addAnimationData(DataParser.parseAnimationDataByAnimationRawData(animationRawData,armature._armatureData)); } /** diff --git a/src/dragonBones/objects/DataParser.as b/src/dragonBones/objects/DataParser.as index 0ea6164..c19d6b0 100644 --- a/src/dragonBones/objects/DataParser.as +++ b/src/dragonBones/objects/DataParser.as @@ -130,15 +130,17 @@ return null; } - public static function parseAnimationDataByAnimationRawData(animationRawData:Object, armatureData:ArmatureData, fameRate:uint):AnimationData + public static function parseAnimationDataByAnimationRawData(animationRawData:Object, armatureData:ArmatureData):AnimationData { + var animationData:AnimationData = armatureData.animationDataList[0]; + if(animationRawData is XML) { - return XMLDataParser.parseAnimationData((animationRawData as XML), armatureData, fameRate); + return XMLDataParser.parseAnimationData((animationRawData as XML), armatureData, animationData.frameRate); } else { - return ObjectDataParser.parseAnimationData(animationRawData, armatureData, fameRate); + return ObjectDataParser.parseAnimationData(animationRawData, armatureData, animationData.frameRate); } } From ea58216f5e195bc483acceb736f6995871355a98 Mon Sep 17 00:00:00 2001 From: akdcl Date: Mon, 7 Jul 2014 16:36:08 +0800 Subject: [PATCH 07/10] fix bugs --- src/dragonBones/animation/Animation.as | 3 +- src/dragonBones/animation/AnimationState.as | 45 +++++++++------------ src/dragonBones/animation/TimelineState.as | 45 ++++++++++++--------- 3 files changed, 46 insertions(+), 47 deletions(-) diff --git a/src/dragonBones/animation/Animation.as b/src/dragonBones/animation/Animation.as index baabada..52ad6bb 100644 --- a/src/dragonBones/animation/Animation.as +++ b/src/dragonBones/animation/Animation.as @@ -242,7 +242,7 @@ _isFading = true; // - fadeInTime = fadeInTime < 0?(animationData.fadeTime < 0?300:animationData.fadeTime):fadeInTime; + fadeInTime = fadeInTime < 0?(animationData.fadeTime < 0?0.3:animationData.fadeTime):fadeInTime; var durationScale:Number; if(duration < 0) { @@ -256,7 +256,6 @@ playTimes = isNaN(playTimes)?animationData.playTimes:playTimes; var animationState:AnimationState; - var j:int; switch(fadeOutMode) { case NONE: diff --git a/src/dragonBones/animation/AnimationState.as b/src/dragonBones/animation/AnimationState.as index 30d0880..c386c04 100644 --- a/src/dragonBones/animation/AnimationState.as +++ b/src/dragonBones/animation/AnimationState.as @@ -588,18 +588,11 @@ var timelineState:TimelineState = TimelineState.borrowObject(); timelineState.fadeIn(bone, this, _clip.getTimeline(timelineName)); _timelineStateList.push(timelineState); - bone.addState(timelineState); } } private function removeTimelineState(timelineState:TimelineState):void { - var bone:Bone = _armature.getBone(timelineState.name); - if (bone) - { - bone.removeState(timelineState); - } - var index:int = _timelineStateList.indexOf(timelineState); _timelineStateList.splice(index, 1); TimelineState.returnObject(timelineState); @@ -726,7 +719,19 @@ var currentTime:int = _time; var currentPlayTimes:int; var isThisComplete:Boolean; - if(_playTimes != 0) + if(_playTimes == 0) + { + isThisComplete = false; + currentPlayTimes = Math.ceil(Math.abs(currentTime) / _totalTime) || 1; + //currentTime -= Math.floor(currentTime / _totalTime) * _totalTime; + currentTime -= int(currentTime / _totalTime) * _totalTime; + + if(currentTime < 0) + { + currentTime += _totalTime; + } + } + else { var totalTimes:int = _playTimes * _totalTime; if(currentTime >= totalTimes) @@ -758,18 +763,6 @@ currentTime = _totalTime; } } - else - { - isThisComplete = false; - currentPlayTimes = Math.ceil(Math.abs(currentTime) / _totalTime) || 1; - //currentTime -= Math.floor(currentTime / _totalTime) * _totalTime; - currentTime -= int(currentTime / _totalTime) * _totalTime; - - if(currentTime < 0) - { - currentTime += _totalTime; - } - } //update timeline _isComplete = isThisComplete; @@ -853,14 +846,10 @@ var frameList:Vector. = _clip.frameList; if(frameList.length > 0) { + var prevFrame:Frame; var currentFrame:Frame; while(true) { - if(currentFrame) - { - _armature.arriveAtFrame(currentFrame, null, this, true); - } - if(_currentFrameIndex < 0) { _currentFrameIndex = 0; @@ -897,8 +886,14 @@ break; } + if(prevFrame) + { + _armature.arriveAtFrame(prevFrame, null, this, true); + } + _currentFrameDuration = currentFrame.duration; _currentFramePosition = currentFrame.position; + prevFrame = currentFrame; } if(currentFrame) diff --git a/src/dragonBones/animation/TimelineState.as b/src/dragonBones/animation/TimelineState.as index 5df29c6..9ea5e7e 100644 --- a/src/dragonBones/animation/TimelineState.as +++ b/src/dragonBones/animation/TimelineState.as @@ -151,7 +151,6 @@ package dragonBones.animation _animation = _armature.animation; _animationState = animationState; _timeline = timeline; - _currentFrameIndex = -1; _originTransform = _timeline.originTransform; _originPivot = _timeline.originPivot; @@ -159,6 +158,7 @@ package dragonBones.animation _totalTime = _timeline.duration; _rawAnimationScale = _animationState.clip.scale; + _currentFrameIndex = -1; _currentTime = -1; _isComplete = false; _blendEnabled = false; @@ -199,6 +199,8 @@ package dragonBones.animation _updateState = 1; break; } + + _bone.addState(this); } /** @private */ @@ -235,7 +237,19 @@ package dragonBones.animation var currentTime:int = _totalTime * progress; var playTimes:int = _animationState.playTimes; - if(playTimes != 0) + if(playTimes == 0) + { + _isComplete = false; + currentPlayTimes = Math.ceil(Math.abs(currentTime) / _totalTime) || 1; + //currentTime -= Math.floor(currentTime / _totalTime) * _totalTime; + currentTime -= int(currentTime / _totalTime) * _totalTime; + + if(currentTime < 0) + { + currentTime += _totalTime; + } + } + else { var totalTimes:int = playTimes * _totalTime; if(currentTime >= totalTimes) @@ -259,24 +273,14 @@ package dragonBones.animation } currentPlayTimes = Math.ceil(currentTime / _totalTime) || 1; - //currentTime -= Math.floor(currentTime / _totalTime) * _totalTime; - currentTime -= int(currentTime / _totalTime) * _totalTime; - if(_isComplete) { currentTime = _totalTime; } - } - else - { - _isComplete = false; - currentPlayTimes = Math.ceil(Math.abs(currentTime) / _totalTime) || 1; - //currentTime -= Math.floor(currentTime / _totalTime) * _totalTime; - currentTime -= int(currentTime / _totalTime) * _totalTime; - - if(currentTime < 0) + else { - currentTime += _totalTime; + //currentTime -= Math.floor(currentTime / _totalTime) * _totalTime; + currentTime -= int(currentTime / _totalTime) * _totalTime; } } @@ -285,14 +289,10 @@ package dragonBones.animation _currentTime = currentTime; var frameList:Vector. = _timeline.frameList; + var prevFrame:TransformFrame; var currentFrame:TransformFrame; while(true) { - if(currentFrame) - { - _bone.arriveAtFrame(currentFrame, this, _animationState, true); - } - if(_currentFrameIndex < 0) { _currentFrameIndex = 0; @@ -329,6 +329,11 @@ package dragonBones.animation break; } + if(prevFrame) + { + _bone.arriveAtFrame(prevFrame, this, _animationState, true); + } + _currentFrameDuration = currentFrame.duration; _currentFramePosition = currentFrame.position; } From 9fe1f56d890df54c0aa644f9b03254991682fae3 Mon Sep 17 00:00:00 2001 From: Chenguang Liu Date: Mon, 7 Jul 2014 16:40:53 +0800 Subject: [PATCH 08/10] refine outputAnimation Dictionary --- src/dragonBones/objects/DataParser.as | 19 ++----- src/dragonBones/objects/ObjectDataParser.as | 47 ++++++++++------- src/dragonBones/objects/XMLDataParser.as | 57 ++++++++++++--------- 3 files changed, 65 insertions(+), 58 deletions(-) diff --git a/src/dragonBones/objects/DataParser.as b/src/dragonBones/objects/DataParser.as index c19d6b0..018fe57 100644 --- a/src/dragonBones/objects/DataParser.as +++ b/src/dragonBones/objects/DataParser.as @@ -117,15 +117,15 @@ return null; } - public static function parseData(rawData:Object, ifSkipAnimationData:Boolean = false):SkeletonData + public static function parseData(rawData:Object, ifSkipAnimationData:Boolean = false, outputAnimationDictionary:Dictionary = null):SkeletonData { if(rawData is XML) { - return XMLDataParser.parseSkeletonData(rawData as XML, ifSkipAnimationData); + return XMLDataParser.parseSkeletonData(rawData as XML, ifSkipAnimationData, outputAnimationDictionary); } else { - return ObjectDataParser.parseSkeletonData(rawData, ifSkipAnimationData); + return ObjectDataParser.parseSkeletonData(rawData, ifSkipAnimationData, outputAnimationDictionary); } return null; } @@ -134,6 +134,7 @@ { var animationData:AnimationData = armatureData.animationDataList[0]; + if(animationRawData is XML) { return XMLDataParser.parseAnimationData((animationRawData as XML), armatureData, animationData.frameRate); @@ -144,18 +145,6 @@ } } - public static function parseAnimationRawDataDictionary(rawData:Object, outputDictionary:Dictionary):void - { - if(rawData is XML) - { - return XMLDataParser.parseAnimationRawDataDictionary((rawData as XML), outputDictionary); - } - else - { - return ObjectDataParser.parseAnimationRawDataDictionary(rawData, outputDictionary); - } - } - public static function parseFrameRate(rawData:Object):uint { if(rawData is XML) diff --git a/src/dragonBones/objects/ObjectDataParser.as b/src/dragonBones/objects/ObjectDataParser.as index 11cbf32..b8a6177 100644 --- a/src/dragonBones/objects/ObjectDataParser.as +++ b/src/dragonBones/objects/ObjectDataParser.as @@ -65,7 +65,7 @@ return textureAtlasData; } - public static function parseSkeletonData(rawData:Object, ifSkipAnimationData:Boolean=false):SkeletonData + public static function parseSkeletonData(rawData:Object, ifSkipAnimationData:Boolean=false, outputAnimationDictionary:Dictionary = null):SkeletonData { if(!rawData) { @@ -93,13 +93,13 @@ for each(var armatureObject:Object in rawData[ConstValues.ARMATURE]) { - data.addArmatureData(parseArmatureData(armatureObject, data, frameRate, ifSkipAnimationData)); + data.addArmatureData(parseArmatureData(armatureObject, data, frameRate, ifSkipAnimationData, outputAnimationDictionary)); } return data; } - private static function parseArmatureData(armatureObject:Object, data:SkeletonData, frameRate:uint, ifSkipAnimationData:Boolean):ArmatureData + private static function parseArmatureData(armatureObject:Object, data:SkeletonData, frameRate:uint, ifSkipAnimationData:Boolean, outputAnimationDictionary:Dictionary):ArmatureData { var armatureData:ArmatureData = new ArmatureData(); armatureData.name = armatureObject[ConstValues.A_NAME]; @@ -117,12 +117,33 @@ DBDataUtil.transformArmatureData(armatureData); armatureData.sortBoneDataList(); - for each(var animationObject:Object in armatureObject[ConstValues.ANIMATION]) + var animationObject:Object; + if(ifSkipAnimationData) { - armatureData.addAnimationData(parseAnimationData(animationObject, armatureData, frameRate)); - if(ifSkipAnimationData) + if(outputAnimationDictionary!= null) { - break; + outputAnimationDictionary[armatureData.name] = new Dictionary(); + } + + var index:int = 0; + for each(animationObject in armatureObject[ConstValues.ANIMATION]) + { + if(index == 0) + { + armatureData.addAnimationData(parseAnimationData(animationObject, armatureData, frameRate)); + } + else if(outputAnimationDictionary != null) + { + outputAnimationDictionary[armatureData.name][animationObject[ConstValues.A_NAME]] = animationObject; + } + index++; + } + } + else + { + for each(animationObject in armatureObject[ConstValues.ANIMATION]) + { + armatureData.addAnimationData(parseAnimationData(animationObject, armatureData, frameRate)); } } @@ -234,18 +255,6 @@ return displayData; } - /** @private */ - dragonBones_internal static function parseAnimationRawDataDictionary(rawData:Object, outputDictionary:Dictionary):void - { - for each(var armatureObject:Object in rawData[ConstValues.ARMATURE]) - { - for each(var animationObject:Object in armatureObject[ConstValues.ANIMATION]) - { - outputDictionary[animationObject[ConstValues.A_NAME]] = animationObject; - } - } - } - /** @private */ dragonBones_internal static function parseAnimationData(animationObject:Object, armatureData:ArmatureData, frameRate:uint):AnimationData { diff --git a/src/dragonBones/objects/XMLDataParser.as b/src/dragonBones/objects/XMLDataParser.as index 1fc3311..1521626 100644 --- a/src/dragonBones/objects/XMLDataParser.as +++ b/src/dragonBones/objects/XMLDataParser.as @@ -7,17 +7,17 @@ * @version 2.0 */ - import flash.geom.ColorTransform; - import flash.geom.Point; - import flash.geom.Rectangle; - import flash.utils.Dictionary; - import dragonBones.core.DragonBones; import dragonBones.core.dragonBones_internal; import dragonBones.textures.TextureData; import dragonBones.utils.ConstValues; import dragonBones.utils.DBDataUtil; + import flash.geom.ColorTransform; + import flash.geom.Point; + import flash.geom.Rectangle; + import flash.utils.Dictionary; + use namespace dragonBones_internal; /** @@ -68,7 +68,7 @@ * @param xml The SkeletonData xml to parse. * @return A SkeletonData instance. */ - public static function parseSkeletonData(rawData:XML, ifSkipAnimationData:Boolean = false):SkeletonData + public static function parseSkeletonData(rawData:XML, ifSkipAnimationData:Boolean = false, outputAnimationDictionary:Dictionary = null):SkeletonData { if(!rawData) { @@ -94,13 +94,13 @@ data.name = rawData.@[ConstValues.A_NAME]; for each(var armatureXML:XML in rawData[ConstValues.ARMATURE]) { - data.addArmatureData(parseArmatureData(armatureXML, data, frameRate, ifSkipAnimationData)); + data.addArmatureData(parseArmatureData(armatureXML, data, frameRate, ifSkipAnimationData, outputAnimationDictionary)); } return data; } - private static function parseArmatureData(armatureXML:XML, data:SkeletonData, frameRate:uint, ifSkipAnimationData:Boolean):ArmatureData + private static function parseArmatureData(armatureXML:XML, data:SkeletonData, frameRate:uint, ifSkipAnimationData:Boolean, outputAnimationDictionary:Dictionary):ArmatureData { var armatureData:ArmatureData = new ArmatureData(); armatureData.name = armatureXML.@[ConstValues.A_NAME]; @@ -118,12 +118,33 @@ DBDataUtil.transformArmatureData(armatureData); armatureData.sortBoneDataList(); - for each(var animationXML:XML in armatureXML[ConstValues.ANIMATION]) + var animationXML:XML; + if(ifSkipAnimationData) { - armatureData.addAnimationData(parseAnimationData(animationXML, armatureData, frameRate)); - if(ifSkipAnimationData) + if(outputAnimationDictionary!= null) { - break; + outputAnimationDictionary[armatureData.name] = new Dictionary(); + } + + var index:int = 0; + for each(animationXML in armatureXML[ConstValues.ANIMATION]) + { + if(index == 0) + { + armatureData.addAnimationData(parseAnimationData(animationXML, armatureData, frameRate)); + } + else if(outputAnimationDictionary != null) + { + outputAnimationDictionary[armatureData.name][animationXML.@[ConstValues.A_NAME]] = animationXML; + } + index++; + } + } + else + { + for each(animationXML in armatureXML[ConstValues.ANIMATION]) + { + armatureData.addAnimationData(parseAnimationData(animationXML, armatureData, frameRate)); } } @@ -234,18 +255,6 @@ return displayData; } - /** @private */ - dragonBones_internal static function parseAnimationRawDataDictionary(rawData:XML, outputDictionary:Dictionary):void - { - for each(var armatureXML:XML in rawData[ConstValues.ARMATURE]) - { - for each(var animationXML:XML in armatureXML[ConstValues.ANIMATION]) - { - outputDictionary[animationXML.@[ConstValues.A_NAME]] = animationXML; - } - } - } - /** @private */ dragonBones_internal static function parseAnimationData(animationXML:XML, armatureData:ArmatureData, frameRate:uint):AnimationData { From e122835987a66ce4e6dd8c0ab70ed7cf66c11b26 Mon Sep 17 00:00:00 2001 From: akdcl Date: Mon, 7 Jul 2014 17:31:58 +0800 Subject: [PATCH 09/10] fix bug --- src/dragonBones/animation/AnimationState.as | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dragonBones/animation/AnimationState.as b/src/dragonBones/animation/AnimationState.as index c386c04..52b1da1 100644 --- a/src/dragonBones/animation/AnimationState.as +++ b/src/dragonBones/animation/AnimationState.as @@ -217,7 +217,7 @@ { value = 0; } - _currentTime = value * 0.001; + _currentTime = value * 1000; _time = _currentTime; return this; } From 21cdc1714bbfb8918670c9de2100340eb89e0069 Mon Sep 17 00:00:00 2001 From: Chenguang Liu Date: Mon, 7 Jul 2014 17:38:11 +0800 Subject: [PATCH 10/10] add outputAnimation Dictionary parameter to BaseFactory.parseData interface --- src/dragonBones/factorys/BaseFactory.as | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dragonBones/factorys/BaseFactory.as b/src/dragonBones/factorys/BaseFactory.as index 3a8d50c..d4503a2 100644 --- a/src/dragonBones/factorys/BaseFactory.as +++ b/src/dragonBones/factorys/BaseFactory.as @@ -26,6 +26,7 @@ package dragonBones.factorys import flash.system.ApplicationDomain; import flash.system.LoaderContext; import flash.utils.ByteArray; + import flash.utils.Dictionary; use namespace dragonBones_internal; @@ -286,7 +287,6 @@ package dragonBones.factorys * Add a new animation to armature. * @param animationRawData (XML, JSON). * @param target armature. - * @param frame rate. */ public function addAnimationToArmature(animationRawData:Object, armature:Armature):void { @@ -502,9 +502,11 @@ package dragonBones.factorys * * @param ByteArray. Represents the raw data for the whole DragonBones system. * @param String. (optional) The SkeletonData instance name. + * @param Boolean. (optional) flag if delay animation data parsing. Delay animation data parsing can reduce the data paring time to improve loading performance. + * @param Dictionary. (optional) output parameter. If it is not null, and ifSkipAnimationData is true, it will be fulfilled animationData, so that developers can parse it later. * @return A SkeletonData instance. */ - public function parseData(bytes:ByteArray, dataName:String = null, ifSkipAnimationData:Boolean = false):SkeletonData + public function parseData(bytes:ByteArray, dataName:String = null, ifSkipAnimationData:Boolean = false, outputAnimationDictionary:Dictionary = null):SkeletonData { if(!bytes) { @@ -512,7 +514,7 @@ package dragonBones.factorys } var decompressedData:DecompressedData = DataParser.decompressData(bytes); - var data:SkeletonData = DataParser.parseData(decompressedData.dragonBonesData, ifSkipAnimationData); + var data:SkeletonData = DataParser.parseData(decompressedData.dragonBonesData, ifSkipAnimationData, outputAnimationDictionary); dataName = dataName || data.name; addSkeletonData(data, dataName);