【发布时间】:2020-11-26 14:23:48
【问题描述】:
您好,我正在尝试将坐标集添加到列表的单行(因此 x,y 作为单行列表)。当我分解图像并在网格中显示块时,我目前正在生成 x 和 y 坐标。能够将 x 和 y 添加到同一 List 行中,我遇到了障碍。这是我到目前为止的代码 -
float sf = 1f;
int x = 0;
int y = 0;
int width = tileImage.Width / tileNumber;
int height = tileImage.Height / tileNumber;
int placeXValue = (width / 10);
int placeYValue = (height / 10);
int placeX = placeXValue;
int placeY = placeYValue;
Rectangle tileRect = tileImage.Bounds;
tileRect.Width = width;
tileRect.Height = height;
coordinates = new List<int>();
for (int i = 0; i < tileNumber; i++)
{
for (int j = 0; j < tileNumber; j++)
{
tileRect.X = x;
tileRect.Y = y;
_spriteBatch.Draw(tileImage, new Vector2((x + placeX) * sf, (y + placeY) * sf), tileRect, Color.White, 0, new Vector2(0, 0), sf, SpriteEffects.None, 0);
placeX += placeXValue;
x += width;
coordinates.Add(x,y);
}
x = 0;
y += height;
placeX = placeXValue;
placeY += placeYValue;
}
【问题讨论】:
-
您可能需要
coordinates.Add(new Coordinate(x, y))之类的东西,但在不知道您的坐标列表是什么的情况下,我们无法确定。请edit您的问题包括坐标列表的声明。主要问题是您试图为仅接受 1 的方法提供 2 个参数 -
使用坐标 = new List
(); -
添加了我如何解决我遇到的问题的答案