[英]VS2012, C#, Monogame - load asset exception
我幾天來一直在與這些問題作斗爭,瀏覽網絡,但沒有任何幫助我解決它:我在Visual Studio 2012上創建一個MonoGame應用程序,但在嘗試加載紋理時,我遇到以下問題:
無法加載Menu / btnPlay資產!
我已設置內容目錄:Content.RootDirectory =“Assets”; 此外,文件btnPlay.png還具有以下屬性:構建操作:內容和復制到輸出目錄:如果較新則復制。
我的構造函數和LoadContent函數是完全空的,但看看自己:
public WizardGame()
{
Window.Title = "Just another Wizard game";
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Assets";
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
_spriteBatch = new SpriteBatch(GraphicsDevice);
Texture2D texture = Content.Load<Texture2D>("Menu/btnPlay");
_graphics.IsFullScreen = true;
_graphics.ApplyChanges();
}
我很樂意提供任何幫助! 我對這個問題非常絕望....
在VS2012,Windows 8 64位和最新的MonoGame(3.0.1):
namespace GameName2
{
public class Game1 : Game
{
private Texture2D _texture2D;
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
_texture2D = Content.Load<Texture2D>("assets/snap0009");
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
spriteBatch.Begin();
spriteBatch.Draw(_texture2D, Vector2.Zero, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
這是你繪制的紋理:D
注意:
為方便起見,我保留了內容根目錄指向的原始值: Content
。
但是,您也可以直接在路徑中指定Assets
:
Content.RootDirectory = @"Content\Assets";
然后加載紋理而不將Assets
添加到其路徑:
_texture2D = Content.Load<Texture2D>("snap0009");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.