c# - "Cannot Implicitly convert type 'float' to 'int'" even when I'm not using any ints -
here's 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 4 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 can see, ints use explicitly casted, i'm confused thinks i'm trying implicitly convert int.
i should mention there 8 identical errors of kind, 2 each of 4 lines. boggles mind.
noise array of type float[,]
you're trying use float values array indexer in code fragments like: noise[x1, y1]
.
array indexers can integers in .net, you've declared them float x1, y1
.
Comments
Post a Comment