- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我一直在尝试使用 Xamarin Studio 在 MonoGame 中加载纹理。我的代码设置如下:
#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Input;
#endregion
namespace TestGame
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
//Game World
Texture2D texture;
Vector2 position = new Vector2(0,0);
public Game1 ()
{
graphics = new GraphicsDeviceManager (this);
Content.RootDirectory = "Content";
graphics.IsFullScreen = false;
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize ()
{
// TODO: Add your initialization logic here
base.Initialize ();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent ()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch (GraphicsDevice);
//Content
texture = Content.Load<Texture2D>("player");
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update (GameTime gameTime)
{
// For Mobile devices, this logic will close the Game when the Back button is pressed
if (GamePad.GetState (PlayerIndex.One).Buttons.Back == ButtonState.Pressed) {
Exit ();
}
// TODO: Add your update logic here
base.Update (gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw (GameTime gameTime)
{
graphics.GraphicsDevice.Clear (Color.CornflowerBlue);
//Draw
spriteBatch.Begin ();
spriteBatch.Draw (texture, position, Color.White);
spriteBatch.End ();
base.Draw (gameTime);
}
}
}
当我调试它时,它给我错误:
Microsoft.Xna.Framework.Content.ContentLoadException: Could not load player asset as a non-content file! ---> Microsoft.Xna.Framework.Content.ContentLoadException: The directory was not found. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\Flame\Documents\Projects\TestGame\TestGame\bin\Debug\Content\player.xnb'. ---> System.Exception:
--- End of inner exception stack trace ---
at at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at at System.IO.File.OpenRead(String path)
at at Microsoft.Xna.Framework.TitleContainer.OpenStream(String name)
at at Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName)
--- End of inner exception stack trace ---
at at Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName)
at at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject)
--- End of inner exception stack trace ---
at at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject)
at at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName)
at TestGame.Game1.LoadContent() in c:\Users\Flame\Documents\Projects\TestGame\TestGame\Game1.cs:0
at at Microsoft.Xna.Framework.Game.Initialize()
at TestGame.Game1.Initialize() in c:\Users\Flame\Documents\Projects\TestGame\TestGame\Game1.cs:0
at at Microsoft.Xna.Framework.Game.DoInitialize()
at at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
at at Microsoft.Xna.Framework.Game.Run()
at TestGame.Program.Main() in c:\Users\Flame\Documents\Projects\TestGame\TestGame\Program.cs:0
那我做错了什么?
最佳答案
设置png文件的'Build action'
为'Content'
,设置'Copy to output directory'
为 '如果更新则复制'
。
您可以通过按住 Ctrl 单击文件并按属性来在 Xamarin Studio 中调出属性窗口。
您不应包含文件扩展名。
关于c# - MonoGame 中的 ContentLoadException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16467207/
我开始学习“一些”XNA 并且 - 正如预期的那样 - 我很早就遇到了障碍。 我已经创建了一个 WP7 XNA 游戏解决方案 我已经删除了默认内容项目 我已经添加了自己的内容项目“Sprites” 我
我一直在尝试使用 Xamarin Studio 在 MonoGame 中加载纹理。我的代码设置如下: #region Using Statements using System; using Micr
我是一名优秀的程序员,十分优秀!