예제 #1
0
        public Player()
        {
            Animation anim = new Animation("default", 1, 1);
            var frame = anim.CreateFrame();
            frame[0].Foreground = Color.Yellow;
            frame[0].Background = Color.Black;
            frame[0].CharacterIndex = 1;
            anim.Commit();

            AddAnimation(anim);
            SetActiveAnimation(anim);
        }
예제 #2
0
        /// <summary>
        /// Creates a new entity with the specified font.
        /// </summary>
        /// <param name="font">The font to use when rendering this entity.</param>
        public Entity(Font font)
            : base(null, new SpriteBatch(Engine.Device))
        {
            Font = font;
            IsVisible = true;

            _currentAnimation = new Animation("default", 1, 1);
            _currentAnimation.Font = font;
            _currentAnimation.CreateFrame();
            _currentAnimation.Commit();

            _animations.Add(CurrentAnimation);
            _animationBoundingBox = new Rectangle(0, 0, 1, 1);
        }
예제 #3
0
        /// <summary>
        /// Removes an animation from this entity.
        /// </summary>
        /// <param name="animation">The animation to remove. If you try to remove the "default" animation, an exception will be thrown.</param>
        public void RemoveAnimation(Animation animation)
        {
            if (_animations.Contains(animation))
            {
                if (animation.Name == "default")
                    throw new System.Exception("Cannot remove default animation. Replace it by adding a new animation with the name 'default'");
                else
                {
                    _animations.Remove(animation);

                    if (_currentAnimation == animation)
                        SetActiveAnimation("default");
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Adds an animation to the entity. Replacing any animation with the same name and setting the font of the animation to the entity's font.
        /// </summary>
        /// <param name="animation">The animation.</param>
        public void AddAnimation(Animation animation)
        {
            var oldAnimation = _animations.Where(a => a.Name.Equals(animation.Name, System.StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (oldAnimation != null)
                _animations.Remove(oldAnimation);

            _currentAnimation = animation;

            animation.Font = _font;

            _animations.Add(animation);
        }
예제 #5
0
 public void RemoveAllAnimations()
 {
     _animations.Clear();
     _currentAnimation = null;
 }
예제 #6
0
        /// <summary>
        /// Sets the active animation.
        /// </summary>
        /// <param name="name">The name of the animation to activate.</param>
        /// <remarks>This animation does not have to be part of the named animations added to the entity.</remarks>
        public void SetActiveAnimation(Animation animation)
        {
            _currentAnimation = animation;

            if (_currentAnimation.Font != null)
                base.Font = _currentAnimation.Font;
            else
                base.Font = Engine.DefaultFont;

            UpdateAnimationBoundingBox();
            CellData = _currentAnimation.CurrentFrame;
            ResetViewArea();
        }
예제 #7
0
        /// <summary>
        /// Sets the active animation.
        /// </summary>
        /// <param name="name">The name of the animation to activate.</param>
        public void SetActiveAnimation(string name)
        {
            var animation = _animations.Where(a => a.Name.Equals(name, System.StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (animation == null)
                return;

            _currentAnimation = animation;

            if (_currentAnimation.Font != null)
                base.Font = _currentAnimation.Font;
            else
                base.Font = Engine.DefaultFont;

            UpdateAnimationBoundingBox();
            CellData = _currentAnimation.CurrentFrame;
            ResetViewArea();
        }
예제 #8
0
        /// <summary>
        /// Sets the active animation.
        /// </summary>
        /// <param name="name">The name of the animation to activate.</param>
        public void SetActiveAnimation(string name)
        {
            if (_animations.ContainsKey(name))
                _currentAnimation = _animations[name];
            else
                return;

            if (_currentAnimation.Font != null)
                base.Font = _currentAnimation.Font;
            else
                base.Font = Engine.DefaultFont;

            UpdateAnimationBoundingBox();
            ResetViewArea();
        }
예제 #9
0
        /// <summary>
        /// Adds an animation to the entity. Replacing any animation with the same name and setting the font of the animation to the entity's font.
        /// </summary>
        /// <param name="animation">The animation.</param>
        public void AddAnimation(Animation animation)
        {
            if (_animations.ContainsKey(animation.Name))
            {
                if (_currentAnimation.Name == animation.Name)
                {
                    _currentAnimation = animation;
                    UpdateAnimationBoundingBox();
                }

                _animations.Remove(animation.Name);
            }

            animation.Font = _font;

            _animations.Add(animation.Name, animation);
        }