当我试图制作一个游戏引擎时,我的级别类(用于级别创建的类)出现了一个错误。
Level.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;
}
}
}
}
}
}错误:
System.IndexOutOfRangeException类型的未处理异常发生在2dgame.exe中
发布于 2015-12-04 15:23:44
Y检查的for循环是错误的:
for(int y = 0; x < LEVEL_HEIGHT; y++)应:
for(int y = 0; y < LEVEL_HEIGHT; y++)发布于 2015-12-04 15:23:48
您的内部(y)循环中有一个错误。
for(int y = 0; x < LEVEL_HEIGHT; y++)应:
for(int y = 0; y < LEVEL_HEIGHT; y++)https://stackoverflow.com/questions/34091594
复制相似问题