Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# tile worldscreen系统有问题吗?_C#_Xna 4.0_Tile - Fatal编程技术网

C# tile worldscreen系统有问题吗?

C# tile worldscreen系统有问题吗?,c#,xna-4.0,tile,C#,Xna 4.0,Tile,我正在尝试为我的游戏制作一个基于瓷砖的世界屏幕,下面是我的三个课程 namespace WindowsGame1 { public enum Tiletype {Grass, Water, Foothill, Mountain } public struct Tile { public Tiletype TerrainType { get; set; } public Texture2D TileGFX { get; set; } publi

我正在尝试为我的游戏制作一个基于瓷砖的世界屏幕,下面是我的三个课程

namespace WindowsGame1
{
 public enum Tiletype
{Grass,
    Water,
    Foothill,
    Mountain

}
public struct Tile
{
    public  Tiletype TerrainType { get; set; }
    public Texture2D TileGFX { get; set; }
    public Rectangle SrcRect { get; set; }
    public Vector2 Location { get; set; }
    public int AniFrame { get; set; }

    // TILE ACTIONS
    public bool IsActivated { get; set; }
    public bool IsBlocked { get; set; }
    public bool IsTouchTrigger { get; set; }
    public bool IsStepTrigger { get; set; }
}
}
MapBase类

    public class MapBase
{

    public Tile[,] TileList = new Tile[1, 1];
    public MapBase(int width, int height, Vector2 start)
    {
        TileList = new Tile[width + 1, height + 1];

        // TEMPORARY MAP
        for (int X = 0; X <= width; X++)
        {
            for (int Y = 0; Y <= height; Y++)
            {
                TileList[X, Y] = new Tile();
                var _with1 = TileList[X, Y];
                _with1.TerrainType = Tiletype.Water;
                _with1.TileGFX = Textures.World;
                _with1.AniFrame = 0;
                _with1.IsBlocked = true;
            }
        }

        // SIMPLE ISLAND
        for (int z = 22; z <= 33; z++)
        {
            for (int c = 22; c <= 31; c++)
            {
                TileList[z, c].TerrainType = Tiletype.Grass;
            }
        }

        TileList[27, 25].TerrainType = Tiletype.Foothill;
        TileList[28, 25].TerrainType = Tiletype.Foothill;
        TileList[27, 24].TerrainType = Tiletype.Foothill;
        TileList[28, 26].TerrainType = Tiletype.Mountain;


        for (int x = 0; x <= width; x++)
        {
            for (int y = 0; y <= height; y++)
            {
                TileList[x, y].SrcRect = GetTileSource(TileList[x, y].TerrainType);
            }
        }

    }
世界级屏幕

 class Worldscreen : BaseScreen
{
    public int MapWidth = 100;
    public int MapHeight = 100;
    public int TileSize = 32;
    public int MapX = 20;
    public int MapY = 19;
    public MapBase Map = new MapBase(100, 100, new Vector2(0, 0));

    public Worldscreen(GraphicsDevice device)
        : base(device, "WorldScreen")
    {
        Map = new MapBase(MapWidth, MapHeight, new Vector2(0, 0));
    }
绘图函数

    public override void Draw(GameTime gameTime)
    {
        base.Draw(gameTime);
        Globals.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);

        //DRAW TILE LAYER
        for (int DrawX = -1; DrawX <= 16; DrawX++)
        {
            for (int DrawY = -1; DrawY <= 15; DrawY++)
            {
                int x = DrawX + MapX;
                int y = DrawY + MapY;

                if (x > 0 & x <= MapWidth & y >= 0 & y <= MapHeight)
                {
                    Globals.spriteBatch.Draw(Map.TileList[x,y].TileGFX, new Rectangle(DrawX * TileSize, DrawY * TileSize, TileSize, TileSize), Map.TileList[x, y].SrcRect, Color.White);
                    // VIEW COORDINATES ON TILE
                    //Globals.SpriteBatch.DrawString(Fonts.Arial_8, "X:" & x & vbCrLf & "Y:" & y, New Vector2(DrawX * TileSize, DrawY * TileSize), Color.Black)
                }
            }
        }
        Globals.spriteBatch.End();
    }
}
当我尝试运行draw void时,它在world screen类中出现了这个错误 此方法不接受此参数的null。 参数名称:纹理


有没有办法解决这个问题,或者我必须重新编写这些类。

您已经获得了自己调试这些类所需的所有信息:

世界屏幕类上有一个纹理为null的方法

进行一步一步的调试并找出是哪一个,除非我们在查看代码时发现这是一个简单的错误,但这通常不是那么容易。你有没有一个不关联的列表

但由于它是一种方法参数。。。接受纹理作为参数的唯一方法是GetTileSource

这么快有什么可以解释它。。。我会检查两件事:

你确定你的循环有正确的界限吗?您可能只是要求该数组中不存在的磁贴,因为它超出了边界。数组以0为基数,循环到
    public override void Draw(GameTime gameTime)
    {
        base.Draw(gameTime);
        Globals.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);

        //DRAW TILE LAYER
        for (int DrawX = -1; DrawX <= 16; DrawX++)
        {
            for (int DrawY = -1; DrawY <= 15; DrawY++)
            {
                int x = DrawX + MapX;
                int y = DrawY + MapY;

                if (x > 0 & x <= MapWidth & y >= 0 & y <= MapHeight)
                {
                    Globals.spriteBatch.Draw(Map.TileList[x,y].TileGFX, new Rectangle(DrawX * TileSize, DrawY * TileSize, TileSize, TileSize), Map.TileList[x, y].SrcRect, Color.White);
                    // VIEW COORDINATES ON TILE
                    //Globals.SpriteBatch.DrawString(Fonts.Arial_8, "X:" & x & vbCrLf & "Y:" & y, New Vector2(DrawX * TileSize, DrawY * TileSize), Color.Black)
                }
            }
        }
        Globals.spriteBatch.End();
    }
}