我总是在以下行中收到此错误消息:
posDiffRectFList.Add(posDiff_Float, Backgrounds.levellistshapes[j]);
ArgumentException:已存在具有相同密钥的条目。
有什么问题?我应该改变什么?
例如:
是否可以将其添加到SortedList
?或者这是不可能的,因为它是相同键的两倍(1.5f)?
posDiffRectFList.Add(1.5f, (10,20,100,100));
posDiffRectFList.Add(1.5f, (50,70,60,60));
SortedList<float, System.Drawing.RectangleF> posDiffRectFList = new SortedList<float, System.Drawing.RectangleF>();
for (int j = 0; j <= Backgrounds.LevelListTiles.Count - 1; j++)
{
posDiff = new Vector2((int)((Backgrounds.LevelListTiles[j].X + Backgrounds.LevelListTiles[j].Width * 0.5) - (Basketball_Rect.X + Basketball_Rect.Width * 0.5)), (int)((Backgrounds.LevelListTiles[j].Y + Backgrounds.LevelListTiles[j].Height * 0.5) - (Basketball_Rect.Y + Basketball_Rect.Height * 0.5)));
posDiff_Float = posDiff.Length();
posDiffRectFList.Add(posDiff_Float, Backgrounds.LevelListTiles[j]);
}
//check for collision between tiles and basketball, beginning with the lowest posDiff_Float and his corresponding RectangleF
for (int j = 0; j <= posDiffRectFList.Count - 1; j++)
{
if (kugelNewRect.IntersectsWith(posDiffRectFList.Values[j]))