c# XNA创建列表
本文关键字:列表 创建 XNA | 更新日期: 2023-09-27 18:10:43
我正试图制作一个列表来存储我的Trail
类的所有实例,但它给了我以下错误:
可访问性不一致:字段类型为"System.Collections.Generic.list<Jumper"。Trail>'比' jump . 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()
{
}
}
}
我做错了什么?
private static List<Trail> trails = new List<Trail>();
?
静态类基本上与非静态类相同,但有有一点不同:静态类不能被实例化。在其他类的变量不能使用new关键字创建类类型。
直接引用自:http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.110).aspx
基本上,你只需要删除static标签,就这样。
抱歉,如果这只是有点晚了。div = '