首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WP8游戏中的System.InvalidOperationException (MonoGame )

WP8游戏中的System.InvalidOperationException (MonoGame )
EN

Stack Overflow用户
提问于 2013-04-26 13:36:28
回答 1查看 474关注 0票数 1

这是我的Game1类:

代码语言:javascript
复制
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameName2
{
     public class Game1 : Game
     {
         GraphicsDeviceManager _graphics;
         SpriteBatch _spriteBatch;
         Texture2D _bg;

         public Game1()
         {
             _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);

             _bg = Content.Load<Texture2D>(@"Loading");
             // TODO: use this.Content to load your game content here
         }

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


         protected override void Update(GameTime gameTime)
         {
             // 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

             _spriteBatch.Draw(_bg,
                 new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height),
                 null,
                 Color.White,
                 0,
                 Vector2.Zero,
                 SpriteEffects.None,
                 0);

             base.Draw(gameTime);
         }
     }
 }

我在项目中创建了一个"Content“文件夹,并将Loading.xnb添加为现有项。然后,我将Loading.xnb的构建操作更改为"Content“,将Copy更改为Output为"Copy Always”。

但是当我编译它时,这一节抛出了System.InvalidOperationException

代码语言:javascript
复制
protected override void Draw(GameTime gameTime)
     {
         GraphicsDevice.Clear(Color.CornflowerBlue);

         // TODO: Add your drawing code here

         _spriteBatch.Draw(_bg,
             new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height),
             null,
             Color.White,
             0,
             Vector2.Zero,
             SpriteEffects.None,
             0);

         base.Draw(gameTime);
     }

特别是在_spriteBatch.Draw(......)方法。有人能帮帮我吗?谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-04-26 17:05:09

请看一些示例程序。必须在_spriteBatch.Begin和_spriteBatch.End之间调用_spriteBatch.Draw。

代码语言:javascript
复制
     GraphicsDevice.Clear(Color.CornflowerBlue);

     // TODO: Add your drawing code here

     _spriteBatch.Begin();
     _spriteBatch.Draw(_bg,
         new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height),
         null,
         Color.White,
         0,
         Vector2.Zero,
         SpriteEffects.None,
         0);
     _spriteBatch.End();

     base.Draw(gameTime);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16229416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档