我有這個問題,將單個矩形分配給列表中的每個值。要嘗試使用此我第一次嘗試給一個矩形值5索引超出了矩形陣列的範圍?
snakeBodyRectangleArray[5] = new Rectangle((int)snakeBodyArray[5].X, (int)snakeBodyArray[5].Y, textureSnakeBody.Width, textureSnakeBody.Height);
// above is in update
protected override void Initialize()
{
// TODO: Add your initialization logic here
graphics.PreferredBackBufferWidth = 500;
graphics.PreferredBackBufferHeight = 500;
graphics.IsFullScreen = false;
graphics.ApplyChanges();
Window.Title = "Curvy Snake";
snakeBodyArray = new List<Vector2>();
snakeBodyRectangleArray = new List<Rectangle>();
bodyTimer.Elapsed += new ElapsedEventHandler(updateBodyPositions);
bodyTimer.Interval = 120;
bodyTimer.Enabled = true;
base.Initialize();
}
如果你需要更多的代碼,只問。
在此先感謝
數組基於零。這意味着最後一個元素位於索引4,而不是5 –