locked
Pixel Perfect Collision, working...kinda RRS feed

  • Question

  • So I spent the night working up a way to do pixel perfect. Here is what I'm doing.

    Sudo.
    Init spite with texture
    Int32[,] = new Int32[texture.width,texture.height];

    I then scan the texture data using GetData<Int32> and load in into the two-dimensional array above.

    So now I have these two arrays filled with the values from the texture, they come out like
    16777215, -16711936 which is where my first question comes in.  If i'm grabbing this data from GetData as an Int32(any other thing I can grab it as?) how can I tell what this color is, what do these numbers mean?

    Anyways, from trial and error I figured out 16777215 was transparent so now I made a big *** loop to go through the two sprites and check to see if any pixels are both not transparent...causing a collision.  So, this works in theory and I have kinda have it working but it stops a little short of when it should hit. Also, it's slow as hell. Second question.  Since I have these two arrays above of the image data, is there a way I can do a simple AND or XOR on the data to get these same results without running a 4-deep nested loop?

    Thanks.
    Saturday, September 2, 2006 2:14 AM

Answers

  • Yes!
    Ok, after seeing that I get it now, here is the code incase someone else needs it

    You need an Int32 value, this comes from GetData from texture/surface.

    int32 ARGB = texture_data[1];
    int32 Alpha = ARGB >> 24 & 0xFF;
    int32 Red = ARGB >> 16 & 0xFF;
    int32 Greed = ARGB >> 8 & 0xFF;
    int32 Blue = ARGB & 0xFF;
    Saturday, September 2, 2006 2:10 PM

All replies

  • Since you are dealing with sprites, I would say look here for an idea.
    http://lazyfooproductions.com/SDL_tutorials/lesson14/index.php
    Saturday, September 2, 2006 6:35 AM
  • Anyone know what the numbers mean, anyway to convert those to actualy RGBA values or comthing?  Also, when I'm creating the texture do you think it matters what type I do it in?
    Saturday, September 2, 2006 11:59 AM
  • Those numbers are 32bit integer representation of the pixel color.
    You should be able to extract the ARGB format from those numbers.

    Im not sure how you would do this in XNA, but it should be something
    like this:

    argb = integer color (a=alpha)
    a = (ARGB Shr 24) And $ff
    r = (ARGB Shr 16) And $ff
    g = (ARGB Shr 8) And $ff
    b = ARGB And $ff

    Hope this helps
    Saturday, September 2, 2006 12:56 PM
  • Yes!
    Ok, after seeing that I get it now, here is the code incase someone else needs it

    You need an Int32 value, this comes from GetData from texture/surface.

    int32 ARGB = texture_data[1];
    int32 Alpha = ARGB >> 24 & 0xFF;
    int32 Red = ARGB >> 16 & 0xFF;
    int32 Greed = ARGB >> 8 & 0xFF;
    int32 Blue = ARGB & 0xFF;
    Saturday, September 2, 2006 2:10 PM
  • Glad to see you could use my Blitz3D code :)

    I see you changed 32  to 24 for alpha, which of course is correct, sorry bout that.

    Cheers
    Saturday, September 2, 2006 3:37 PM