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; }
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; }
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); }
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); }