Exemplo n.º 1
0
        /// <summary>
        /// Create a new Sprite with a position.
        /// Optionally pass in a default animation name and animation.
        /// </summary>
        /// <param name="startPosition">Required: Start position of sprite</param>
        /// <param name="animationName">Optional: Default animation name (Required with animation parameter)</param>
        /// <param name="animation">Optional: Default animation (Required with animationName parameter)</param>
        public Sprite(Vector2 startPosition, Animation animation = null, string animationName = "main")
            : this()
        {
            OffsetX = startPosition.X;
            OffsetY = startPosition.Y;

            if (animation != null)
            {
                AddAnimation(animationName, animation);
            }
        }
Exemplo n.º 2
0
 public void AddAnimation(string animationName, Animation animation)
 {
     animations.Add(animationName, animation);
     // If this is the first animation added
     // Set it to the current running animation
     if (animations.Count == 1)
         SetAnimation(animationName);
 }
Exemplo n.º 3
0
        private static void LoadAnimation(AnimationInfo animInfo)
        {
            var animation = new Animation {Texture = G.Content.Load<Texture2D>(animInfo.AssetName), Frames = new List<Frame>()};

            foreach (var frameInfo in animInfo.Frames)
            {
                var sourceRect = GetIndexSourceRectangle(animation.Texture.Width, animation.Texture.Height,
                                                         animInfo.Width, animInfo.Height, frameInfo.Index);
                var frame = new Frame(sourceRect, frameInfo.Duration);
                animation.Frames.Add(frame);
            }

            Animations.Add(animInfo.Name, animation);
        }