4

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: プレーヤー アセットを非コンテンツ ファイルとして読み込めませんでした! ---> Microsoft.Xna.Framework.Content.ContentLoadException: ディレクトリが見つかりませんでした。---> System.IO.DirectoryNotFoundException: パス 'C:\Users\Flame\Documents\Projects\TestGame\TestGame\bin\Debug\Content\player.xnb' の一部が見つかりませんでした。---> System.Exception:

--- 内部例外スタック トレースの終了 ---

at System.IO.__Error.WinIOError(Int32 errorCode, String MaybeFullPath)

System.IO.FileStream.Init で (文字列パス、FileMode モード、FileAccess アクセス、Int32 権限、Boolean useRights、FileShare 共有、Int32 bufferSize、FileOptions オプション、SECURITY_ATTRIBUTES secAttrs、String msgPath、Boolean bFromProxy、Boolean useLongPath)

System.IO.FileStream..ctor で (文字列パス、FileMode モード、FileAccess アクセス、FileShare 共有、Int32 bufferSize、FileOptions オプション、文字列 msgPath、ブール値 bFromProxy)

at at System.IO.FileStream..ctor(文字列パス、FileMode モード、FileAccess アクセス、FileShare 共有)

at at System.IO.File.OpenRead(文字列パス)

at at Microsoft.Xna.Framework.TitleContainer.OpenStream(文字列名)

at at Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName)

--- 内部例外スタック トレースの終了 ---

at at 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)

at at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName)

c:\Users\Flame\Documents\Projects\TestGame\TestGame\Game1.cs:0 の TestGame.Game1.LoadContent() で

Microsoft.Xna.Framework.Game.Initialize() で

c:\Users\Flame\Documents\Projects\TestGame\TestGame\Game1.cs:0 の TestGame.Game1.Initialize() で

Microsoft.Xna.Framework.Game.DoInitialize() で

Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior) で

Microsoft.Xna.Framework.Game.Run() で

c:\Users\Flame\Documents\Projects\TestGame\TestGame\Program.cs:0 の TestGame.Program.Main() で

それで、私は何を間違っていますか?

4

5 に答える 5

2

ファイルをソリューションの Content ディレクトリに追加し、プロパティ ウィンドウで新しい場合は content / copy に設定する必要があります。その後、ビルド プロセス中に出力ディレクトリにコピーされます。

コンパイル済みの XNB ファイル (通常は XNA ゲーム スタジオで作成) を使用するか、生の PNG 画像ファイルを使用できることに注意してください。後者を使用する場合は、コードにファイル拡張子を追加する必要があります。

于 2013-05-09T21:51:32.580 に答える
0

このように使うだけ

using (var stream = TitleContainer.OpenStream ("Content/charactersheet.png"))
{
    characterSheetTexture = Texture2D.FromStream (this.GraphicsDevice, stream);

}

それ以外の

texture = Content.Load<Texture2D>("player");
于 2016-12-20T17:04:32.297 に答える
-4

それを機能させるには、私の指示に従ってください:

Xamarin を使用したシンプルな 2D ゲーム

私はそれが少し長いことを知っていますが、それは私を信じて動作します.追加の質問がある場合は、お気軽にお尋ねください:Dに関して

于 2013-07-16T21:36:56.473 に答える