XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

perPixel Collision .setData() doesn't work fine

Last post 04/11/2009 10:28 AM by jadephoenix1988. 2 replies.
  • 04/11/2009 9:57 AM

    perPixel Collision .setData() doesn't work fine

    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!
  • 04/11/2009 10:13 AM In reply to

    Re: perPixel Collision .setData() doesn't work fine

    Answer
    Reply Quote

    Color[] pixelLevelData = new Color[landscape.landscapeTex.Width * landscape.landscapeTex.Height]; 

    Is LOCAL to DestroyLandscape()

    Where does testCollision(...) get it's pixelLevelData[] from?

    **

    Well on the way to creating a First Person Shooter with Over the Shoulder view...

    Another few years and it'll be done!

    http://games.discoverthat.co.uk/ - Skinning Sample Dude for Blender and XNA Parallel Spilt Shadow Maps plus other stuff...
  • 04/11/2009 10:28 AM In reply to

    Re: perPixel Collision .setData() doesn't work fine

    Aauuuuuuuuuuuuu xD... I'm such a dumbass :P.

    thank you very much^^.



Page 1 of 1 (3 items) Previous Next