我試圖做一個列表,我的所有實例存儲我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()
{
}
}
}
我在做什麼錯?
您是否檢查過您的列表是否已初始化? – Ucodia
我懷疑您發佈的代碼與您嘗試編譯的代碼不同。那個,或者你有兩個同名的類,並且你還沒有發佈足夠的代碼來澄清造成歧義的原因。不管是什麼原因,你的編譯器都認爲'Trail'類不如包含它的列表可訪問,即列表是一個公共字段,'Trail'是一個私有類。 –