Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
superlancelot committed Jul 7, 2014
2 parents 4fb70ad + 21cdc17 commit 67ed799
Show file tree
Hide file tree
Showing 11 changed files with 352 additions and 299 deletions.
6 changes: 2 additions & 4 deletions src/dragonBones/animation/Animation.as
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -238,7 +238,6 @@
{
return null;
}

_isPlaying = true;
_isFading = true;

Expand All @@ -251,13 +250,12 @@
}
else
{
durationScale = duration / animationData.duration;
durationScale = duration * 0.001 / animationData.duration;
}

playTimes = isNaN(playTimes)?animationData.playTimes:playTimes;

var animationState:AnimationState;
var j:int;
switch(fadeOutMode)
{
case NONE:
Expand Down
136 changes: 77 additions & 59 deletions src/dragonBones/animation/AnimationState.as
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,14 @@
}

private var _armature:Armature;
private var _currentFrame:Frame;
private var _timelineStateList:Vector.<TimelineState>;
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;
Expand Down Expand Up @@ -192,30 +194,30 @@
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
{
if(isNaN(value))
{
value = 0;
}
_currentTime = value;
_currentTime = value * 1000;
_time = _currentTime;
return this;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -646,7 +647,7 @@
fadeStartFlg = true;
}

//(_fadeState == -1 || _fadeState == 0) && fadeState == -1
//(_fadeState == -1 || _fadeState == 0) && fadeState == 1
if(fadeState == 1)
{
fadeCompleteFlg = true;
Expand Down Expand Up @@ -708,19 +709,31 @@
{
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)
if(_playTimes == 0)
{
var totalTimes:Number = _playTimes * _totalTime;
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)
{
currentTime = totalTimes;
Expand All @@ -741,27 +754,15 @@
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)
{
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;
Expand Down Expand Up @@ -795,13 +796,14 @@
}

_currentTime = currentTime;

/*
if(isThisComplete)
{
currentTime = _totalTime * 0.999999;
}
//[0, _totalTime)
updateMainTimeline(currentTime);
*/
updateMainTimeline(isThisComplete);
}

var event:AnimationEvent;
Expand Down Expand Up @@ -839,54 +841,71 @@
}
}

private function updateMainTimeline(currentTime:Number):void
private function updateMainTimeline(isThisComplete:Boolean):void
{
var frameList:Vector.<Frame> = _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 prevFrame:Frame;
var currentFrame:Frame;
while(true)
{
if(isArrivedAtNewFrame)
if(_currentFrameIndex < 0)
{
_armature.arriveAtFrame(_currentFrame, null, this, true);
_currentFrameIndex = 0;
currentFrame = frameList[_currentFrameIndex];
}
if(_currentFrame)
else if(_currentTime >= _currentFramePosition + _currentFrameDuration)
{
frameIndex = frameList.indexOf(_currentFrame);
frameIndex ++;
if(frameIndex >= frameList.length)
_currentFrameIndex ++;
if(_currentFrameIndex >= frameList.length)
{
frameIndex = 0;
if(isThisComplete)
{
_currentFrameIndex --;
break;
}
else
{
_currentFrameIndex = 0;
}
}
_currentFrame = frameList[frameIndex];
currentFrame = frameList[_currentFrameIndex];
}
else
{
_currentFrame = frameList[0];
}
if(_currentFrame)
else if(_currentTime < _currentFramePosition)
{
isArrivedAtNewFrame = true;
_currentFrameIndex --;
if(_currentFrameIndex < 0)
{
_currentFrameIndex = frameList.length - 1;
}
currentFrame = frameList[_currentFrameIndex];
}
else
{
isArrivedAtNewFrame = false;
break;
}

if(prevFrame)
{
_armature.arriveAtFrame(prevFrame, null, this, true);
}

_currentFrameDuration = currentFrame.duration;
_currentFramePosition = currentFrame.position;
prevFrame = currentFrame;
}

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)
Expand All @@ -898,15 +917,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;
}
Expand Down
Loading

0 comments on commit 67ed799

Please sign in to comment.