我一直在尝试使用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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我调试它时,它给我错误:
Microsoft.Xna.Framework.Content.ContentLoadException:无法将播放器资产加载为非内容文件!---> Microsoft.Xna.Framework.Content.ContentLoadException:找不到目录.---> System.IO.DirectoryNotFoundException:找不到路径'C:\ Users\Flame\Documents\Projects\TestGame\TestGame\bin\Debug\Content\player.xnb'的一部分.---> System.Exception:
---内部异常堆栈跟踪结束---
在System.IO .__ Error.WinIOError(Int32 errorCode,String maybeFullPath)
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 System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share,Int32 bufferSize,FileOptions options,String msgPath,Boolean bFromProxy)
在System.IO.FileStream..ctor(字符串路径,FileMode模式,FileAccess访问,FileShare共享)
在System.IO.File.OpenRead(String path)
at at Microsoft.Xna.Framework.TitleContainer.OpenStream(String name)
在Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName)
---内部异常堆栈跟踪结束---
在Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName)
at at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset [T](String assetName,Action`1 recordDisposableObject)
---内部异常堆栈跟踪结束---
at at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset [T](String assetName,Action`1 recordDisposableObject)
在Microsoft.Xna.Framework.Content.ContentManager.Load [T](String assetName)
在TestGame.Game1.LoadContent()中的c:\ Users\Flame\Documents\Projects\TestGame\TestGame\Game1.cs:0
在Microsoft.Xna.Framework.Game.Initialize()
在c:\ Users\Flame\Documents\Projects\TestGame\TestGame\Game1.cs中的TestGame.Game1.Initialize():0
在Microsoft.Xna.Framework.Game.DoInitialize()
在Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
在Microsoft.Xna.Framework.Game.Run()
在TestGame.Program.Main()中的c:\ Users\Flame\Documents\Projects\TestGame\TestGame\Program.cs:0
那么我做错了什么?
将'Build action'png文件'Content'设置'Copy to output directory'为并设置为'Copy if newer'.
您可以通过单击文件并按属性来调出Xamarin Studio中的属性窗口.
您不应该包含文件扩展名.
| 归档时间: |
|
| 查看次数: |
7551 次 |
| 最近记录: |