2011-10-09 86 views
0

我試圖做一個列表,我的所有實例存儲我Trail類的,但它給我這個以下錯誤:C#XNA創建列表?

Inconsistent accessibility: field type 'System.Collections.Generic.list<Jumper.Trail>' is less accessible than field 'Jumper.Main.trails'

我用這下面的代碼行(在那裏示數):

public static List<Trail> trails = new List<Trail>(); 

這裏是我的Trail.cs代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Audio; 
using Microsoft.Xna.Framework.Content; 
using Microsoft.Xna.Framework.GamerServices; 
using Microsoft.Xna.Framework.Graphics; 
using Microsoft.Xna.Framework.Input; 
using Microsoft.Xna.Framework.Media; 

namespace Jumper 
{ 
    public class Trail 
    { 
     public int width; 
     public static float angle; 
     //The current position of the Sprite 
     public Vector2 pos = Vector2.Zero; 
     //The texture object used when drawing the sprite 
     public Texture2D trail; 

     public Trail() 
     { 
      angle = Player.rotation; 
      pos.X = Player.pos.X; 
      pos.Y = Player.pos.Y; 
     } 

     //Load the texture for the sprite using the Content Pipeline 
     public void LoadContent(ContentManager theContentManager, string theAssetName) 
     { 
      trail = theContentManager.Load<Texture2D>(theAssetName); 
     } 

     //Draw the sprite to the screen 
     public void Draw(SpriteBatch theSpriteBatch) 
     { 
      theSpriteBatch.Draw(trail, new Vector2(pos.X, pos.Y), Color.White); 
     } 

     public void updateTrail() 
     { 
     } 
    } 
} 

我在做什麼錯?

+0

您是否檢查過您的列表是否已初始化? – Ucodia

+0

我懷疑您發佈的代碼與您嘗試編譯的代碼不同。那個,或者你有兩個同名的類,並且你還沒有發佈足夠的代碼來澄清造成歧義的原因。不管是什麼原因,你的編譯器都認爲'Trail'類不如包含它的列表可訪問,即列表是一個公共字段,'Trail'是一個私有類。 –

回答

1

private static List<Trail> trails = new List<Trail>();

0

A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, you cannot use the new keyword to create a variable of the class type.

直接引自:http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.110).aspx

那麼好看多了,你只需要刪除靜態標籤,僅此而已。

對不起,如果這不僅僅是晚了一點。 = \