我有这个代码在游戏的每一帧运行:
foreach (var repeaterAction in conditionTimes.Keys)
{
if (repeaterAction.Condition() == true)
{
if (conditionTimes[repeaterAction] == TimeSpan.Zero)
{
repeaterAction.Action();
}
else if (conditionTimes[repeaterAction] >= repeaterAction.InitialLapse)
{
repeaterAction.Action();
conditionTimes[repeaterAction] -= repeaterAction.ActionInterval;
}
conditionTimes[repeaterAction] += gameTime.ElapsedGameTime;
}
else
{
conditionTimes[repeaterAction] = TimeSpan.Zero;
}
}
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误:
收集被修改; 枚举操作可能无法执行.
有没有办法修改foreach循环中键值对中的值,而不是每帧都复制Dictionary?
我有一组构成二维多边形的位置顶点。
Vector2[] _chassisConcaveVertices =
{
new Vector2(5.122f, 0.572f),
new Vector2(3.518f, 0.572f),
new Vector2(3.458f, 0.169f),
new Vector2(2.553f, 0.169f),
new Vector2(2.013f, 0.414f),
new Vector2(0.992f, 0.769f),
new Vector2(0.992f, 1.363f),
new Vector2(5.122f, 1.363f),
};
Run Code Online (Sandbox Code Playgroud)
我可以使用什么算法来修改位置以便翻转生成的多边形?我需要水平和垂直翻转多边形。