Esempio n. 1
0
        /// <summary>
        /// Load content.
        /// </summary>
        /// <param name="content">The content manager to use.</param>
        public void LoadContent(ContentManager content)
        {
            // Clear all sprites.
            _Sprites = new SpriteManager();

            // Front.
            Sprite front = _Sprites.Add(new Sprite(_Sprites, "Front"));
            front.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Front[1]");
            front.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Front[2]");
            front.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Front[3]");

            // Back.
            Sprite back = _Sprites.Add(new Sprite(_Sprites, "Back"));
            back.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Back[0]");
            back.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Back[1]");
            back.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Back[2]");
            back.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Back[3]");

            // Right.
            Sprite right = _Sprites.Add(new Sprite(_Sprites, "Right"));
            right.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Right[0]");
            right.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Right[1]");
            right.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Right[2]");

            // Left.
            Sprite left = _Sprites.Add(new Sprite(_Sprites, "Left"));
            left.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Left[0]");
            left.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Left[1]");
            left.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Left[2]");

            // Only make one sprite visible.
            back.Visibility = Visibility.Invisible;
            right.Visibility = Visibility.Invisible;
            left.Visibility = Visibility.Invisible;

            //Set the frame-rate.
            front.TimePerFrame = .1f;
            back.TimePerFrame = .1f;
            right.TimePerFrame = .1f;
            left.TimePerFrame = .1f;

            // Current sprite is facing up.
            _CurrentSprite = front;

            // Load all sprites' content.
            _Sprites.LoadContent(content);

            //Update the frames' origin.
            front.Frames.ForEach(item => item.Origin = new Vector2(item.Width / 2, item.Height / 2));
            back.Frames.ForEach(item => item.Origin = new Vector2(item.Width / 2, item.Height / 2));
            right.Frames.ForEach(item => item.Origin = new Vector2(item.Width / 2, item.Height / 2));
            left.Frames.ForEach(item => item.Origin = new Vector2(item.Width / 2, item.Height / 2));

            // Set the shape of the body.
            _Body.Shape.Width = 15;
            _Body.Shape.Height = 15;
            _Body.Shape.Depth = _Sprites[0][_Sprites[0].CurrentFrameIndex].Height / 3;

            // Update the sprites' position offset.
            front.PositionOffset = new Vector2(0, -front[front.CurrentFrameIndex].Origin.Y + (_Body.Shape.Height / 2));
            back.PositionOffset = new Vector2(0, -back[back.CurrentFrameIndex].Origin.Y + (_Body.Shape.Height / 2));
            right.PositionOffset = new Vector2(0, -right[right.CurrentFrameIndex].Origin.Y + (_Body.Shape.Height / 2));
            left.PositionOffset = new Vector2(0, -left[left.CurrentFrameIndex].Origin.Y + (_Body.Shape.Height / 2));
        }
Esempio n. 2
0
        /// <summary>
        /// Load content and add a sprite.
        /// </summary>
        /// <param name="contentManager">The content manager to use.</param>
        /// <param name="spritePath">The path to the main sprite.</param>
        /// <param name="height">The height of the shape as seen on picture. This is used for collision data.
        /// -1 results in the use of the full height of the sprite and a depth of 1.</param>
        public virtual void LoadContent(ContentManager contentManager, String spritePath, float height)
        {
            //Clear all sprites.
            _Sprites = new SpriteManager();

            //Add the color texture.
            Sprite sprite = _Sprites.Add(new Sprite(_Sprites, "Entity"));
            sprite.AddFrame(spritePath);

            //Load all sprites' content.
            _Sprites.LoadContent(contentManager);

            //Update the frame's origin.
            sprite.Frames[0].Origin = new Vector2(sprite.Frames[0].Width / 2, sprite.Frames[0].Height / 2);

            //Check if the normal and depth maps exist.
            bool n = File.Exists(Path.Combine(contentManager.RootDirectory, spritePath + "(Normal)" + ".xnb"));
            bool d = File.Exists(Path.Combine(contentManager.RootDirectory, spritePath + "(Depth)" + ".xnb"));

            //Set the normal and depth maps.
            _Sprites[0].Frames[0].NormalPath = n ? spritePath + "(Normal)" : @"Entities\DepthDefault";
            _Sprites[0].Frames[0].DepthPath = d ? spritePath + "(Depth)" : @"Entities\DepthDefault";

            // Set the shape of the body.
            _Body.Shape.Width = sprite.CurrentFrame.Width;
            _Body.Shape.Height = (height == -1) ? sprite.CurrentFrame.Height : height;
            _Body.Shape.Depth = (height == -1) ? 1 : sprite.CurrentFrame.Height - height;

            //Update the sprite's position offset.
            _Sprites[0].PositionOffset = new Vector2(0, -sprite.CurrentFrame.Origin.Y + (_Body.Shape.Height / 2));
        }