无法在XNA游戏工作室游戏中更改图像

时间:2013-04-17 13:13:41

标签: c# visual-studio-2010 xna

对于大学项目,我不得不下载一个名为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工作室中做些什么吗?

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

由于

0 个答案:

没有答案
相关问题