Xna WP 8游戏中的System.InvalidoOperationException(单游戏)
这是我的Game1课程:Xna WP 8游戏中的System.InvalidoOperationException(单游戏),xna,windows-phone-8,monogame,content-pipeline,Xna,Windows Phone 8,Monogame,Content Pipeline,这是我的Game1课程: using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace GameName2 { public class Game1 : Game { GraphicsDeviceManager _graphics; SpriteBatch _spriteBatch; Texture2D _bg;
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);
}
}
}
特别是在_spriteBatch.Draw(…….)方法中。有人能帮我吗?谢谢。请看一些示例程序_必须在_spriteBatch.Begin和_spriteBatch.End之间调用spriteBatch.Draw
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);
请看一些示例程序_必须在_spriteBatch.Begin和_spriteBatch.End之间调用spriteBatch.Draw
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);
请发布整个错误和stacktrace。请发布整个错误和stacktrace.hmm,我已尝试在.Draw方法的开始和结束处添加.Begin和.End。它不会导致任何错误。但是我加载的图像只显示GraphicsDevice.Clear生成的普通颜色。造成这种情况的可能问题是什么??这是因为我的“坏”xnb文件还是有其他可能?感谢这是我的.png文件,我使用它作为.xnb(它是纯黄色的,只是为了加载图像测试目的)我使用emulator 720p我的图像有任何兼容性问题或问题吗?您只是将.png重命名为.xnb还是使用内容库将其转换为.xnb?如果您只是重命名它,那么您应该将其保留为.png,并将该扩展名添加到您的调用中_bg=Content.Load(@“Load.png”);嗯,我尝试在.Draw方法的开始和结束处添加.Begin和.End。它不会导致任何错误。但是我加载的图像只显示GraphicsDevice.Clear生成的普通颜色。造成这种情况的可能问题是什么??这是因为我的“坏”xnb文件还是有其他可能?感谢这是我的.png文件,我使用它作为.xnb(它是纯黄色的,只是为了加载图像测试目的)我使用emulator 720p我的图像有任何兼容性问题或问题吗?您只是将.png重命名为.xnb还是使用内容库将其转换为.xnb?如果您只是重命名它,那么您应该将其保留为.png,并将该扩展名添加到您的调用中_bg=Content.Load(@“Load.png”);