簡體   English   中英

使用XNA引用命名空間C#

[英]referencing a namespace C# using XNA

我一直在第一個大型項目中使用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);
         }
    }
}

任何建議都會很棒。

你可以用

using TileMap;
using tiles;

以及何時要訪問方法

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

和對於靜態類

Rectangle r =  tile.GetSourceRectangle(1);

這行Tilemap.MapRow.TileMap myMap = new TileMap(); 沒有道理。 TileMap不是類型,而是Tilemap.MapRow類的方法。 您無法實例化它。 此外,它應該是TileMap.MapRow而不是Tilemap.MapRow (注意大寫M)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM