2011-10-09 87 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

那么好看多了,你只需要删除静态标签,仅此而已。

对不起,如果这不仅仅是晚了一点。 = \