Home Ask Login Register

Developers Planet

Your answer is one click away!

user1920556 February 2016

"Cannot Implicitly convert type 'float' to 'int'" even when I'm not using any ints

Here's my code:

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;
}

The errors occur on these four lines:

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];

As you can see, the only ints I use are explicitly casted, so I'm just really confused as to where it thinks I'm trying to implicitly convert anything to an int.

I should mention there are 8 identical errors of this kind, 2 for each of the four lines. It boggles my mind.

noise is an array of type float[,]

Answers


Andy Korneyev February 2016

You're trying to use float values as array indexer in the code fragments like: noise[x1, y1].

Array indexers can be only integers in .NET, but you've declared them as float x1, y1.

Post Status

Asked in February 2016
Viewed 3,928 times
Voted 5
Answered 1 times

Search




Leave an answer


Quote of the day: live life