1

这是我第一次做 XNA 项目。

我一直在学习教程(http://rbwhitaker.wikidot.com/using-3d-models),但我在运行游戏时遇到了问题,返回了相关错误。

我在这里以及在网上阅读了一些类似的问题,它们几乎总是与内容项目、根目录、自定义内容管理器等有关。现在,我对这些都不太熟悉,因为我没有修改 XNA 的模板代码,我只是添加了一些(来自教程)。

有问题的文件

这是代码:

    public class mainClass : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        // Below: Added as of 5/2/13 - referenced from tutorial
        private Model testModel;
        private Matrix testWorld = Matrix.CreateTranslation(new Vector3(0, 0, 0));
        private Matrix testView = Matrix.CreateLookAt(new Vector3(0, 0, 10), new Vector3(0, 0, 0), Vector3.UnitY);
        private Matrix testProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 480f, 0.1f, 100f);
        // Code ends here

        public mainClass()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            base.Initialize();
        }

        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            testModel = Content.Load<Model>("Models/g01-12-13.fbx");
        }

        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here

            base.Draw(gameTime);            
        }
    }

它在 testModel 内容加载部分出错。说找不到型号。我试过把它放在文件夹外,但无济于事。我可以帮忙吗?谢谢。

PS 我正在使用 XNA 4.0、Visual Studio 2010 和 Windows 8(呃)。

4

0 回答 0