当我的关卡类(用于创建关卡的类)出错时,我正在尝试制作游戏引擎
级别.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _2dgame
{
class Level
{
public const int LEVEL_WIDTH = 12;
public const int LEVEL_HEIGHT = 8;
private static TextureID[,] blocks = new TextureID[LEVEL_WIDTH, LEVEL_HEIGHT];
public static TextureID[,] Blocks
{
get { return blocks; }
set { blocks = value; }
}
public static void initLevel()
{
for (int x = 0; x < LEVEL_WIDTH; x++)
{
for(int y = 0; x < LEVEL_HEIGHT; y++)
{
if (y >= 12)
{
blocks[x, y] = TextureID.dirt; //ERROR
}
else
{
blocks[x, y] = TextureID.air;
}
}
}
}
}
}
错误:
2dgame.exe 中发生了“System.IndexOutOfRangeException”类型的未处理异常