0

对于一个大学项目,我必须下载一个名为Platformer的现有 2D XNA 游戏并更改其中的各种内容,例如角色渲染、背景图像和一些变量(每个项目拾取点数、剩余时间等)。

在我的游戏中,我试图用我自己的替换可玩的角色图像。我已经更改了游戏内容文件夹中的图像,确保它是相同的文件类型和尺寸。

换了这张图:

Platformer > Content > Sprites > Player > Idle.png

有了这个:

Platformer > Content > Sprites > Player > Gorilla.png

在 Visual Studios 的 player.cs 文件中,有一个名为的类LoadContent(),它似乎加载了所有播放器动画和声音等。

public void LoadContent()
    {
        // Load animated textures.
        idleAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Player/Gorilla"), 0.1f, true);
        runAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Player/Run"), 0.1f, true);
        jumpAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Player/Jump"), 0.1f, false);
        celebrateAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Player/Celebrate"), 0.1f, false);
        dieAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Player/Die"), 0.1f, false);

        // Calculate bounds within texture size.            
        int width = (int)(idleAnimation.FrameWidth * 0.4);
        int left = (idleAnimation.FrameWidth - width) / 2;
        int height = (int)(idleAnimation.FrameWidth * 0.8);
        int top = idleAnimation.FrameHeight - height;
        localBounds = new Rectangle(left, top, width, height);

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

更改Sprites文件夹中的图像并尝试运行项目(F5)后,出现以下错误:

Error loading "Sprites\Player\Gorilla". File not found.

参考这行代码:

idleAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Player/Gorilla"), 0.1f, true);

IntelliTrace右侧的窗口中,我得到:

Exception Thrown: Could not find file: Platformer\bin\x86\Debug\Content\Sprites\Player\Gorilla.xnb

所以我假设我必须制作一个 Gorilla.xnb 和一个 Gorilla.png 文件?但是我该怎么做呢?这是我可以在 Visual Studio 中做的事情吗?

我已经从上面的网站构建并运行了项目,所以不确定如何将新的内容图像添加到此类项目中。

谢谢

4

0 回答 0