Platformer.Player.LoadContent C# (CSharp) Method

LoadContent() public method

Loads the player sprite sheet and sounds.
public LoadContent ( Microsoft.Xna.Framework.Content.ContentManager content ) : void
content Microsoft.Xna.Framework.Content.ContentManager
return void
        public void LoadContent(ContentManager content)
        {
            // Load animated textures.
            idleRightAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Idle-Right"), 0.1f, true);
            idleLeftAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Idle-Left"), 0.1f, true);
            runRightAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Walk-Right"), 0.1f, true);
            runLeftAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Walk-Left"), 0.1f, true);
            fallRightAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Fall-Right"), 0.15f, true);
            fallLeftAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Fall-Left"), 0.15f, true);
            jumpRightAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Jump-Right"), 0.05f, delegate
            {
                sprite.PlayAnimation(fallRightAnimation);
            });
            jumpLeftAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Jump-Left"), 0.05f, delegate
            {
                sprite.PlayAnimation(fallLeftAnimation);
            });
            dieRightAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Spiked-Right"), 0.05f, false);
            dieLeftAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Spiked-Left"), 0.05f, false);
            drownRightAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Drown-Right"), 0.1f, true);
            drownLeftAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Drown-Left"), 0.1f, true);

            ladderUpAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Ladder"), 0.15f, true);
            ladderDownAnimation = new Animation(content.Load<Texture2D>("Sprites/Player/Ladder"), 0.1f, true);

            // Calculate bounds within texture size.
            float width = idleLeftAnimation.FrameWidth * 0.4f;
            float left = (idleLeftAnimation.FrameWidth - width) / 2;
            float height = idleLeftAnimation.FrameWidth * 0.8f;
            float top = idleLeftAnimation.FrameHeight - height;
            localBounds = new RectangleF(left, top, width, height);

            // Load sounds.
            killedSound = content.Load<SoundEffect>("Sounds/PlayerKilled");
            jumpSound = content.Load<SoundEffect>("Sounds/PlayerJump");
            fallSound = content.Load<SoundEffect>("Sounds/PlayerFall");

            spikeImpaleSound = content.Load<SoundEffect>("Sounds/PlayerKilledSpike");
            //spikeImpaleSound = jumpSound;
            waterDrownSound = content.Load<SoundEffect>("Sounds/PlayerKilledWater");
            fallImpactSound = content.Load<SoundEffect>("Sounds/PlayerKilledFall");
            //fallImpactSound = jumpSound;
        }

Usage Example

示例#1
0
        public override void LoadContent(ContentManager Content, InputManager inputManager)
        {
            base.LoadContent(Content, inputManager);

            map.LoadContent(Content);
            player.LoadContent(Content);

            txtScoreBar = Content.Load <Texture2D>(Values.txtScoreBar);
            ScoreBar    = new Sprite(txtScoreBar);
            ScoreBar.SetPosition(Values.scoreBarPosition);
        }
All Usage Examples Of Platformer.Player::LoadContent