从列表中绘制矩形
Drawing Rectangles from a List
我正在尝试在我的地图上创建一些基本的矩形。
这是我的 MapBounderies class:
public int boundY, boundX, boundWidth, boundLength;
public Texture2D rectTexture;
public Rectangle boundRectangle;
List<MapBounderies> boundsList = new List<MapBounderies>();
public MapBounderies(Rectangle bRectangle, int intX, int intY, int intWidth, int intLength)
{
boundY = intY;
boundX = intX;
boundWidth = intWidth;
boundLength = intLength;
}
public void Load(ContentManager Content)
{
rectTexture = Content.Load<Texture2D>("black colour");
}
public void AddToList(SpriteBatch spriteBatch)
{
boundsList.Add(new MapBounderies(new Rectangle(), 100, 100, 100, 100));
}
public void Draw(SpriteBatch spriteBatch)
{
foreach (MapBounderies boundries in boundsList)
{
spriteBatch.Draw(rectTexture, new Rectangle(boundries.boundX, boundries.boundY, boundries.boundWidth, boundries.boundLength), Color.White);
}
}
这是我在尝试创建新游戏时在主游戏代码中遇到的错误 "MapBounderies":
MapBounderies mapBounderies = new MapBounderies();
没有给定的参数对应于 'MapBounderies.MapBounderies(Rectangle, int, int, int, int)'
的所需形式参数 'bRectangle'
我是 xna 的新手,如有任何帮助,我们将不胜感激。
And this is the error I am getting in my main game code when I try to create a new "MapBounderies"
There is no argument given that corresponds to the required formal parameter 'bRectangle' of 'MapBounderies.MapBounderies(Rectangle, int, int, int, int)'
出现此错误的原因是您没有默认构造函数,您提供的代码的唯一签名是:
public MapBounderies(Rectangle bRectangle, int intX, int intY, int intWidth, int intLength)
如您所见,它有 5 个参数,并且您没有另一个为空的参数。所以要修复,只需创建另一个没有参数的构造函数。
public MapBoundaries(){}
现在您可以创建一个不带任何参数的 MapBoundaries
实例。
MapBounderies mapBounderies = new MapBounderies();
我正在尝试在我的地图上创建一些基本的矩形。
这是我的 MapBounderies class:
public int boundY, boundX, boundWidth, boundLength;
public Texture2D rectTexture;
public Rectangle boundRectangle;
List<MapBounderies> boundsList = new List<MapBounderies>();
public MapBounderies(Rectangle bRectangle, int intX, int intY, int intWidth, int intLength)
{
boundY = intY;
boundX = intX;
boundWidth = intWidth;
boundLength = intLength;
}
public void Load(ContentManager Content)
{
rectTexture = Content.Load<Texture2D>("black colour");
}
public void AddToList(SpriteBatch spriteBatch)
{
boundsList.Add(new MapBounderies(new Rectangle(), 100, 100, 100, 100));
}
public void Draw(SpriteBatch spriteBatch)
{
foreach (MapBounderies boundries in boundsList)
{
spriteBatch.Draw(rectTexture, new Rectangle(boundries.boundX, boundries.boundY, boundries.boundWidth, boundries.boundLength), Color.White);
}
}
这是我在尝试创建新游戏时在主游戏代码中遇到的错误 "MapBounderies":
MapBounderies mapBounderies = new MapBounderies();
没有给定的参数对应于 'MapBounderies.MapBounderies(Rectangle, int, int, int, int)'
的所需形式参数 'bRectangle'我是 xna 的新手,如有任何帮助,我们将不胜感激。
And this is the error I am getting in my main game code when I try to create a new "MapBounderies"
There is no argument given that corresponds to the required formal parameter 'bRectangle' of 'MapBounderies.MapBounderies(Rectangle, int, int, int, int)'
出现此错误的原因是您没有默认构造函数,您提供的代码的唯一签名是:
public MapBounderies(Rectangle bRectangle, int intX, int intY, int intWidth, int intLength)
如您所见,它有 5 个参数,并且您没有另一个为空的参数。所以要修复,只需创建另一个没有参数的构造函数。
public MapBoundaries(){}
现在您可以创建一个不带任何参数的 MapBoundaries
实例。
MapBounderies mapBounderies = new MapBounderies();