简体   繁体   English

从列表中绘制矩形

[英]Drawing Rectangles from a List

I am trying to create some basic rectangles on my map.我正在尝试在我的地图上创建一些基本的矩形。

This is my MapBounderies class:这是我的 MapBounderies 类:

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);
        }
    }

And this is the error I am getting in my main game code when I try to create a new "MapBounderies":这是我在尝试创建新的“MapBounderies”时在主游戏代码中遇到的错误:

MapBounderies mapBounderies = new MapBounderies();

There is no argument given that corresponds to the required formal parameter 'bRectangle' of 'MapBounderies.MapBounderies(Rectangle, int, int, int, int)'没有给出对应于“MapBounderies.MapBounderies(Rectangle, int, int, int, int)”的所需形式参数“bRectangle”的参数

I am new to xna and any help would be appreciated.我是 xna 的新手,任何帮助将不胜感激。

And this is the error I am getting in my main game code when I try to create a new "MapBounderies"这是我在尝试创建新的“MapBounderies”时在主游戏代码中遇到的错误

There is no argument given that corresponds to the required formal parameter 'bRectangle' of 'MapBounderies.MapBounderies(Rectangle, int, int, int, int)'没有给出对应于“MapBounderies.MapBounderies(Rectangle, int, int, int, int)”的所需形式参数“bRectangle”的参数


The reason for this error is because you don't have a default constructor, the only signature you have from the code you provided is:此错误的原因是因为您没有默认构造函数,您提供的代码的唯一签名是:

 public MapBounderies(Rectangle bRectangle, int intX, int intY, int intWidth, int intLength)

As you can see, it takes 5 parameters and you don't have another one that is empty.如您所见,它需要 5 个参数,并且您没有另一个为空的参数。 So to fix, just create another constructor with no parameters.所以要修复,只需创建另一个没有参数的构造函数。

 public MapBoundaries(){}

Now you can create an instance of MapBoundaries that doesn't take any parameters.现在您可以创建一个不带任何参数的MapBoundaries实例。

 MapBounderies mapBounderies = new MapBounderies();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM