Hey Guys,
I wrote a little function to destroy landscape in a .png file. It looks like this:
| public void DestroyLandscape() |
| { |
| |
| Color[] pixelLevelData = new Color[landscape.landscapeTex.Width * landscape.landscapeTex.Height]; |
| |
| // Array füllen |
| landscape.landscapeTex.GetData<Color>(pixelLevelData, 0, landscape.landscapeTex.Width * landscape.landscapeTex.Height); |
| |
| for (int x = 0; x < kreisTex.Width; x++) |
| { |
| for (int y = 0; y < kreisTex.Height; y++) |
| { |
| if (((mousePosition.X + x) < (landscape.landscapeTex.Width)) && |
| ((mousePosition.Y + y) < (landscape.landscapeTex.Height))) |
| { |
| if ((mousePosition.X + x) >= 0 && (mousePosition.Y + y) >= 0) |
| { |
| if (pixelDeformData[x + y * kreisTex.Width] != Color.TransparentBlack |
| && pixelLevelData[((int)mousePosition.X + x) + |
| ((int)mousePosition.Y + y) * landscape.landscapeTex.Width] != Color.TransparentBlack) |
| { |
| if (pixelDeformData[x + y * kreisTex.Width] == Color.White) |
| { |
| pixelLevelData[((int)mousePosition.X + x) + ((int)mousePosition.Y + y) |
| * landscape.landscapeTex.Width] = Color.TransparentBlack ; |
| } |
| /* else |
| { |
| pixelLevelData[((int)mousePosition.X + x) + |
| ((int)mousePosition.Y + y) * landscape.landscapeTex.Width] = |
| pixelDeformData[x + y * kreisTex.Width]; |
| }*/ |
| } |
| } |
| } |
| } |
| } |
| |
| landscape.landscapeTex.SetData<Color>(pixelLevelData); |
| } |
This works fine, as the .png is manipulated visually. But when I try to detect collisions in THIS way:
| public bool testCollision(Rectangle boundingRectangle) |
| { |
| |
| for (int x = 0; x < boundingRectangle.Width; x++) |
| { |
| if(pixelLevelData[(boundingRectangle.X + x) + (boundingRectangle.Y) * this.landscapeTex.Width] != Color.TransparentBlack) |
| { |
| return true; |
| } |
| if(pixelLevelData[(boundingRectangle.X + x) + (boundingRectangle.Y + boundingRectangle.Height) * this.landscapeTex.Width] != Color.TransparentBlack) |
| { |
| return true; |
| } |
| |
| } |
| |
| for (int y = 0; y < boundingRectangle.Height; y++) |
| { |
| if (pixelLevelData[(boundingRectangle.X) + (boundingRectangle.Y + y) * this.landscapeTex.Width] != Color.TransparentBlack) |
| { |
| return true; |
| } |
| if (pixelLevelData[(boundingRectangle.X + boundingRectangle.Width) + (boundingRectangle.Y + y) * this.landscapeTex.Width] != Color.TransparentBlack) |
| { |
| return true; |
| } |
| } |
| |
| return false; |
| |
| } |
I end up with a not very fine working collisions. It may seem, that the new pixeldata is just set up visually, but not in the pixelLevelData-Array. Here is a Screenshot, for helping you imagine, what my problem is:
Thank you very much!