How I went about it is, when I first load my textures once I've got the texture data for my mask I then read ran a loop where if the pixel colour was bigger then 0x090909 (Red = 9, Blue = 9, Green = 9) then it meant it wasn't black (it could be a dark grey to white) so that is the info i want. Then I workout where about the pixel is in the image (pixels in the first starting from the left have x of 0, pixels in the first row starting from the bottom have y of 0) then I store that x and y value and increase the amount of pixels there are. Then when it's time to check if the pixels collide I have a loop that compares the textures offset + their pixels offset with what they collided with.
Ok I'm not sure if that is how I'm supposed to do pixel collision detection but I thought it should work, so I think there's something wrong with my code.
Here is the part that reads the textures data and creates the pixels offsets. (I know it says outline but that's because originally I was just going to make it store the images outline but then decided to make it all the image)
-(void) createOutline{ int Loop, LoopX, LoopY; VECTOR2D *Temp; for (outlineSize = 0, Loop = 0, LoopX = 0, LoopY = 0; Loop < (int)((texSize[0].width * texSize[0].height) * 3); Loop += 3) { if (LoopX == texSize[0].width) { LoopX = 0; LoopY++; } if (*(unsigned int*)&texBytes[0][Loop] & 0x00ffffff > 592137) { Temp = (VECTOR2D*)realloc(outline, sizeof(VECTOR2D) * (outlineSize + 1)); if (Temp) { outline = Temp; outline[outlineSize].x = (float)LoopX; outline[outlineSize].y = (float)LoopY; outlineSize++; } } LoopX++; }}
Here is the part that detects if the pixels have collided.
-(_Bool) pixelCollide: (VECTOR2D *)outline WithSize: (int)outlineSize AtPosition: (VECTOR2D)pos{ int Loop, Loop2; switch (facing) { case Left: for (Loop = 0; Loop < textureLeft[0].Sprite[CurrentTexture][0].outlineSize; Loop++) { for (Loop2 = 0; Loop2 < outlineSize; Loop2++) { if ((textureLeft[0].Sprite[CurrentTexture][0].outline[Loop].x + position.x == outline[Loop2].x + pos.x) && (textureLeft[0].Sprite[CurrentTexture][0].outline[Loop].y + position.y == outline[Loop2].y + pos.y)) { m.x = outline[Loop2].x + pos.x; m.y = outline[Loop2].y + pos.y; return TRUE; } } } break; case Up: for (Loop = 0; Loop < textureUp[0].Sprite[CurrentTexture][0].outlineSize; Loop++) { for (Loop2 = 0; Loop2 < outlineSize; Loop2++) { if ((textureUp[0].Sprite[CurrentTexture][0].outline[Loop].x + position.x == outline[Loop2].x + pos.x) && (textureUp[0].Sprite[CurrentTexture][0].outline[Loop].y + position.y == outline[Loop2].y + pos.y)) { m.x = outline[Loop2].x + pos.x; m.y = outline[Loop2].y + pos.y; return TRUE; } } } break; case Right: for (Loop = 0; Loop < textureRight[0].Sprite[CurrentTexture][0].outlineSize; Loop++) { for (Loop2 = 0; Loop2 < outlineSize; Loop2++) { if ((textureRight[0].Sprite[CurrentTexture][0].outline[Loop].x + position.x == outline[Loop2].x + pos.x) && (textureRight[0].Sprite[CurrentTexture][0].outline[Loop].y + position.y == outline[Loop2].y + pos.y)) { m.x = outline[Loop2].x + pos.x; m.y = outline[Loop2].y + pos.y; return TRUE; } } } break; case Down: for (Loop = 0; Loop < textureDown[0].Sprite[CurrentTexture][0].outlineSize; Loop++) { for (Loop2 = 0; Loop2 < outlineSize; Loop2++) { if ((textureDown[0].Sprite[CurrentTexture][0].outline[Loop].x + position.x == outline[Loop2].x + pos.x) && (textureDown[0].Sprite[CurrentTexture][0].outline[Loop].y + position.y == outline[Loop2].y + pos.y)) { m.x = outline[Loop2].x + pos.x; m.y = outline[Loop2].y + pos.y; return TRUE; } } } break; } return FALSE;}
Here is three examples of what's happening, for the test I'm using link texture which is the player and my badly drawn pot which is an object. The orange pixel is the pixel that has been hit. But as you can see in most cases that's wrong (well all in these examples), the player texture becomes green when it's collided too. So you can see sometimes it's saying there's a collision when there shouldn't be and sometimes and vice versa. What I've noticed is the bottom left and top right of the pot can be collided with outside of where it actually should be, and the bottom right and top left of the pot aren't colliding where they should be the player can move further inside the texture before it detects it. So yeh there's some clearly wrong going on here.
Hmm images not showing, I think I did it wrong so here's the links
Picture 1
Picture 2
Picture 3