Beispiel #1
0
        public void PlayAnimation(SpriteSheetAnimation animation, Action onCompleteAction = null)
        {
            if (!_animations.ContainsValue(animation))
            {
                throw new InvalidOperationException("Animation does not belong to this animator");
            }

            PlayAnimation(animation.Name);
        }
 public void PlayAnimation(string name, Action onCompleteAction = null)
 {
     if(_currentAnimation != null && _currentAnimation.Name == name)
         return;
     
     _currentAnimation = _animations[name];
     _frameIndex = 0;
     _onCompleteAction = onCompleteAction;
 }
Beispiel #3
0
        public void PlayAnimation(string name, Action onCompleteAction = null)
        {
            if (_currentAnimation != null && _currentAnimation.Name == name && IsPlaying)
            {
                return;
            }

            _currentAnimation = _animations[name];
            _frameIndex       = 0;
            _onCompleteAction = onCompleteAction;
            IsPlaying         = true;
        }
Beispiel #4
0
        public SpriteSheetAnimation AddAnimation(string name, int framesPerSecond, int[] frameIndices)
        {
            if (_animations.ContainsKey(name))
            {
                throw new InvalidOperationException(string.Format("Animator already contrains an animation called {0}", name));
            }

            var animation = new SpriteSheetAnimation(name, framesPerSecond, frameIndices);

            _animations.Add(name, animation);
            return(animation);
        }
        public SpriteSheetAnimation Play(string name, Action onCompleted = null)
        {
            if (_currentAnimation == null || _currentAnimation.IsComplete || _currentAnimation.Name != name)
            {
                var cycle     = _spriteSheet.Cycles[name];
                var keyFrames = cycle.Frames.Select(f => _spriteSheet.TextureAtlas[f.Index]).ToArray();
                _currentAnimation = new SpriteSheetAnimation(name, keyFrames, cycle.FrameDuration, cycle.IsLooping, cycle.IsReversed, cycle.IsPingPong);

                if (_currentAnimation != null)
                {
                    _currentAnimation.OnCompleted = onCompleted;
                }
            }

            return(_currentAnimation);
        }
Beispiel #6
0
        public bool RemoveAnimation(string name)
        {
            SpriteSheetAnimation animation;

            if (!_animations.TryGetValue(name, out animation))
            {
                return(false);
            }

            if (_currentAnimation == animation)
            {
                _currentAnimation = null;
            }

            _animations.Remove(name);
            return(true);
        }
 public void AddAnimation(string name, int framesPerSecond, params int[] frameIndices)
 {
     var animation = new SpriteSheetAnimation(name, framesPerSecond, frameIndices);
     _animations.Add(name, animation);
 }