"即使我没有使用任何整数,也不能隐式地将类型'float'转换为'int'

use*_*556 -3 .net c# arrays

这是我的代码:

float SmoothNoise(float x, float y)
{
    float fractX = x - (int)x;
    float fractY = y - (int)y;

    float x1 = ((int)x + noiseWidth) % noiseWidth;
    float y1 = ((int)y + noiseHeight) % noiseHeight;

    float x2 = ((int)x + noiseWidth - 1f) % noiseWidth;
    float y2 = ((int)y + noiseHeight - 1f) % noiseHeight;

    float value = 0f;

    value += fractX * fractY * noise[x1, y1];
    value += fractX * (1f - fractY) * noise[x1, y2];
    value += (1f - fractX) * fractY * noise[x2, y1];
    value += (1f - fractX) * (1f - fractY) * noise[x2, y2];

    return value;
}
Run Code Online (Sandbox Code Playgroud)

错误发生在以下四行:

value += fractX * fractY * noise[x1, y1];
value += fractX * (1f - fractY) * noise[x1, y2];
value += (1f - fractX) * fractY * noise[x2, y1];
value += (1f - fractX) * (1f - fractY) * noise[x2, y2];
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我使用的唯一的int是明确的,所以我真的很困惑,它认为我试图隐式地将任何东西转换为int.

我应该提到这种类型的8个相同的错误,四个行中的每个错误都有2个.这令我难以置信.

noise是float [,]类型的数组

And*_*yev 12

您试图在代码片段中使用float值作为数组索引器,如:noise[x1, y1].

数组索引器在.NET中只能是整数,但您已将它们声明为float x1, y1.