1

私がやりたいことを達成する唯一の方法だと思われるので、アクセサを使用しようとしています。これが私のコードです:

Game1.cs

public class GroundTexture
{
    private Texture2D dirt;
    public Texture2D Dirt
    {
        get
        {
            return dirt;
        }

        set
        {
            dirt = value;
        }
    }
}

public class Main : Game
{
    public static Texture2D texture = tile.Texture;
    GroundTexture groundTexture = new GroundTexture();
    public static Texture2D dirt;

    protected override void LoadContent()
    {
        Tile tile = (Tile)currentLevel.GetTile(20, 20);

        dirt = Content.Load<Texture2D>("Dirt");
        groundTexture.Dirt = dirt;

        Texture2D texture = tile.Texture;
    }

    protected override void Update(GameTime gameTime)
    {
        if (texture == groundTexture.Dirt)
        {
            player.TileCollision(groundBounds);
        }

        base.Update(gameTime);
    }

}

LoadContent および Update 関数から無関係な情報を削除しました。

次の行で:

if (texture == groundTexture.Dirt)

エラーが発生しています

Operator '==' cannot be applied to operands of type 'Microsoft.Xna.Framework.Graphics.Texture2D' and 'Game1.GroundTexture'

アクセサーを正しく使用していますか? そして、なぜこのエラーが発生するのですか? 「汚れ」はTexture2Dなので比較できるはずです。

これは、タイル エディターである Realm Factory と呼ばれるプログラムのいくつかの関数を使用します。「20、20」という数字は、私が以下に作成したレベルの単なるサンプルです。

http://i.stack.imgur.com/d8cO3.png

tile.Texture はスプライトを返します。これはコンテンツ アイテム Dirt.png です。

どうもありがとうございました!

4

0 に答える 0