예제 #1
0
  private void advanceTimelinesTime(double passedTime) {
    if (_isPlaying && !_pausePlayheadInFade) {
      _time += passedTime;
    }

    boolean startFlg = false;
    boolean completeFlg = false;
    boolean loopCompleteFlg = false;
    boolean isThisComplete = false;
    int currentPlayTimes = 0;
    int currentTime = (int) (_time * 1000);
    if (_playTimes == 0) {
      isThisComplete = false;
      currentPlayTimes = (int) Math.ceil(Math.abs(currentTime) / _totalTime);
      if (currentPlayTimes == 0) currentPlayTimes = 1;
      // currentTime -= Math.floor(currentTime / _totalTime) * _totalTime;

      currentTime -= (int) (currentTime / _totalTime) * _totalTime;

      if (currentTime < 0) {
        currentTime += _totalTime;
      }
    } else {
      int totalTimes = _playTimes * _totalTime;
      if (currentTime >= totalTimes) {
        currentTime = totalTimes;
        isThisComplete = true;
      } else if (currentTime <= -totalTimes) {
        currentTime = -totalTimes;
        isThisComplete = true;
      } else {
        isThisComplete = false;
      }

      if (currentTime < 0) {
        currentTime += totalTimes;
      }

      currentPlayTimes = (int) Math.ceil(currentTime / _totalTime);
      if (currentPlayTimes == 0) currentPlayTimes = 1;
      // currentTime -= Math.floor(currentTime / _totalTime) * _totalTime;
      currentTime -= (int) (currentTime / _totalTime) * _totalTime;

      if (isThisComplete) {
        currentTime = _totalTime;
      }
    }

    // update timeline
    _isComplete = isThisComplete;
    double progress = _time * 1000 / _totalTime;
    for (TimelineState timeline : _timelineStateList) {
      timeline.update(progress);
      _isComplete = timeline._isComplete && _isComplete;
    }
    // update slotTimelie
    for (SlotTimelineState slotTimeline : _slotTimelineStateList) {
      slotTimeline.update(progress);
      _isComplete = slotTimeline._isComplete && _isComplete;
    }
    // update main timeline
    if (_currentTime != currentTime) {
      if (_currentPlayTimes != currentPlayTimes) // check loop complete
      {
        if (_currentPlayTimes > 0 && currentPlayTimes > 1) {
          loopCompleteFlg = true;
        }
        _currentPlayTimes = currentPlayTimes;
      }

      if (_currentTime < 0) // check start
      {
        startFlg = true;
      }

      if (_isComplete) // check complete
      {
        completeFlg = true;
      }
      _lastTime = _currentTime;
      _currentTime = currentTime;
      /*
      if(isThisComplete)
      {
      currentTime = _totalTime * 0.999999;
      }
      //[0, _totalTime)
      */
      updateMainTimeline(isThisComplete);
    }

    AnimationEvent event;
    if (startFlg) {
      if (_armature.hasEventListener(AnimationEvent.START)) {
        event = new AnimationEvent(AnimationEvent.START);
        event.animationState = this;
        _armature._eventList.add(event);
      }
    }

    if (completeFlg) {
      if (_armature.hasEventListener(AnimationEvent.COMPLETE)) {
        event = new AnimationEvent(AnimationEvent.COMPLETE);
        event.animationState = this;
        _armature._eventList.add(event);
      }
      if (autoFadeOut) {
        fadeOut(fadeOutTime, true);
      }
    } else if (loopCompleteFlg) {
      if (_armature.hasEventListener(AnimationEvent.LOOP_COMPLETE)) {
        event = new AnimationEvent(AnimationEvent.LOOP_COMPLETE);
        event.animationState = this;
        _armature._eventList.add(event);
      }
    }
  }
예제 #2
0
  private void advanceFadeTime(double passedTime) {
    boolean fadeStartFlg = false;
    boolean fadeCompleteFlg = false;

    if (_fadeBeginTime >= 0) {
      int fadeState = _fadeState;
      _fadeCurrentTime += passedTime < 0 ? -passedTime : passedTime;
      if (_fadeCurrentTime >= _fadeBeginTime + _fadeTotalTime) {
        // fade完全结束之后触发
        // TODO 研究明白为什么要下次再触发
        if (_fadeWeight == 1 || _fadeWeight == 0) {
          fadeState = 1;
          if (_pausePlayheadInFade) {
            _pausePlayheadInFade = false;
            _currentTime = -1;
          }
        }

        _fadeWeight = _isFadeOut ? 0 : 1;
      } else if (_fadeCurrentTime >= _fadeBeginTime) {
        // fading
        fadeState = 0;
        // 暂时只支持线性淡入淡出
        // Currently only support Linear fadein and fadeout
        _fadeWeight = (_fadeCurrentTime - _fadeBeginTime) / _fadeTotalTime * _fadeTotalWeight;
        if (_isFadeOut) {
          _fadeWeight = _fadeTotalWeight - _fadeWeight;
        }
      } else {
        // before fade
        fadeState = -1;
        _fadeWeight = _isFadeOut ? 1 : 0;
      }

      if (_fadeState != fadeState) {
        // _fadeState == -1 && (fadeState == 0 || fadeState == 1)
        if (_fadeState == -1) {
          fadeStartFlg = true;
        }

        // (_fadeState == -1 || _fadeState == 0) && fadeState == 1
        if (fadeState == 1) {
          fadeCompleteFlg = true;
        }
        _fadeState = fadeState;
      }
    }

    AnimationEvent event;

    if (fadeStartFlg) {
      if (_isFadeOut) {
        if (_armature.hasEventListener(AnimationEvent.FADE_OUT)) {
          event = new AnimationEvent(AnimationEvent.FADE_OUT);
          event.animationState = this;
          _armature._eventList.add(event);
        }
      } else {
        // 动画开始,先隐藏不需要的骨头
        hideBones();

        if (_armature.hasEventListener(AnimationEvent.FADE_IN)) {
          event = new AnimationEvent(AnimationEvent.FADE_IN);
          event.animationState = this;
          _armature._eventList.add(event);
        }
      }
    }

    if (fadeCompleteFlg) {
      if (_isFadeOut) {
        if (_armature.hasEventListener(AnimationEvent.FADE_OUT_COMPLETE)) {
          event = new AnimationEvent(AnimationEvent.FADE_OUT_COMPLETE);
          event.animationState = this;
          _armature._eventList.add(event);
        }
      } else {
        if (_armature.hasEventListener(AnimationEvent.FADE_IN_COMPLETE)) {
          event = new AnimationEvent(AnimationEvent.FADE_IN_COMPLETE);
          event.animationState = this;
          _armature._eventList.add(event);
        }
      }
    }
  }