public override void update(float t) { // if t==1, ignore. Animation should finish with t==1 if (FloatUtils.Small(t, 1.0f)) { t *= _animation.loops; // new loop? If so, reset frame counter uint loopNumber = (uint)t; if (loopNumber > _executedLoops) { _nextFrame = 0; _executedLoops++; } // new t for animations t = (t % 1.0f); } List <CCAnimationFrame> frames = _animation.frames; uint numberOfFrames = (uint)frames.Count; CCSpriteFrame frameToDisplay = null; for (int i = _nextFrame; i < numberOfFrames; i++) { float splitTime = _splitTimes[i]; if (FloatUtils.ES(splitTime, t)) { CCAnimationFrame frame = frames[i]; frameToDisplay = frame.spriteFrame; ((CCSprite)_target).displayedFrame = frameToDisplay; NSDictionary dict = frame.userInfo; if (dict != null) { // NSNotificationCenter.defaultCenter.postNotification(CCAnimationFrameDisplayedNotification, _target, dict); _nextFrame = i + 1; } } // Issue 1438. Could be more than one frame per tick, due to low frame rate or frame delta < 1/FPS else { break; } } }
public void playAnimation(string anmName, int start) { NSUtils.Assert(start >= 0, "{0}#playAnimation start frame should not be {1}.", GetType().Name, start); AnimationClip clip = getAnimationClip(anmName); NSUtils.Assert(clip != null, "{0}#playAnimation {1} not found.", GetType().Name, anmName); int totalFrames = getTotalFrames(anmName); NSUtils.Assert(start < totalFrames, "{0}#playAnimation start frame {1} should not bigger than {2}.", GetType().Name, start, totalFrames); float startTime = Mathf.Clamp01(1f * start / totalFrames); if (FloatUtils.ES(_transitionDuration, 0)) { _fbxAnimator.Play(anmName, 0, startTime); } else { _fbxAnimator.CrossFadeInFixedTime(anmName, _transitionDuration, 0, startTime * clip.length); } }