使用 XNA 引用命名空间 C#


我一直在我

的第一个主要项目中使用 C#,并一直在尝试引用其他 C# 类文件及其命名空间,所有这些都在同一个解决方案中。

我得到的确切错误是:"找不到类型或命名空间名称'theNamespace'"我环顾四周,没有找到任何可以解决我的问题的东西。以下是我当前代码的删节版本,重点介绍检测到错误的位置。

using TileMap.MapRow.NET;
using tiles.tile.NET;
namespace Project
{
     public class Class1 {
     Tilemap.MapRow.TileMap myMap = new TileMap();
     }
     protected override void LoadContent() {
     tile.tilesettexture=Content.Load<Texture2D>("@textures");
     }
}

我尝试调用的类如下:

namespace TileMap
{
     public class MapRow
    {
        public int TileMap ()
        {
            for (int y=0; y<MapHeight; y++)
            { MapRow thisRow=new MapRow();
                for (int x=0; x<MapWidth; x++){
                     thisRow.Columns.Add(new MapCell(0));
                }
                Row.Add(thisRow);
            }}
        public List<MapCell> Columns = new List<MapCell>();
        public List<MapRow> Rows = new List<MapRow>();
        public int MapWidth = 50;
        public int MapHeight = 50;        
        }
}

namespace tiles
{
    static class tile
    {
        static public Texture2D TileSetTexture;
        static public Rectangle GetSourceRectangle(int tileindex)
        {
             return new Rectangle(tileindex * 32, 0, 32, 32);
         }
    }
}

任何建议都会很棒。

Tilemap.MapRow.TileMap myMap = new TileMap();行没有意义。 TileMap不是一种类型,而是类Tilemap.MapRow的方法。您无法实例化它。此外,它应该TileMap.MapRow而不是Tilemap.MapRow(注意大写字母 M)。

你可以

只使用

using TileMap;
using tiles;

以及何时要访问方法

MapRow myMap = new  MapRow();
int i =  myMap.TileMap();

和对于静态类

Rectangle r =  tile.GetSourceRectangle(1);

最新更新