Okay so let me explain roughly what I'm trying to do. I've got a spritesheet of a character, and I wish to attach a sword to his hand. To achieve this I'm putting two pixels on his hand per frame, one being RGB (1, 2, 3) and the other being (3, 2, 1). If I can read in and store the positions of these pixels, I should be able to position the sword as the player animates.
So, I've got a Texture class (which keeps a reference to the SDL surface), and I'm using this code to read pixels: http://sdl.beuc.net/sdl.wiki/Pixel_Access
Now, I'm going through each frame, and for each frame, going through each pixel, and comparing it to 'spec1' and 'spec2', which are Uint32 values which define the pixel colour. Here's the code:
// read special pixels
if (_readSpecial)
{
SDL_LockSurface(_texture->GetSDLSurface());
// convert special SDL_Color to Uint32
Uint32 spec1 = SDL_MapRGB(_texture->GetSDLSurface()->format, _spec1.r, _spec1.g, _spec1.b);
Uint32 spec2 = SDL_MapRGB(_texture->GetSDLSurface()->format, _spec2.r, _spec2.g, _spec2.b);
// start looping through frames
for (int f = start; f < end; f++)
{
int frmx = f % _cols;
int frmy = f / _cols;
// get rectangle around frame
SDL_Rect clip;
clip.x = frmx * _frmWidth;
clip.y = frmy * _frmHeight;
clip.w = _frmWidth;
clip.h = _frmHeight;
bool found1 = false;
bool found2 = false;
// loop through all pixels in frame
for (int y = clip.y; y < clip.y + clip.h; y++)
{
if (found1 && found2) break;
for (int x = clip.x; x < clip.x + clip.w; x++)
{
// get pixel at (x, y)
Uint32 pix = _texture->GetPixel(x, y);
// if pixel is a special value, store it in animation
if (pix == spec1)
{
SDL_Point pt = {x, y};
anim->Special1.push_back(pt);
found1 = true;
}
else if (pix == spec2)
{
SDL_Point pt = {x, y};
anim->Special2.push_back(pt);
found2 = true;
}
}
}
// if not found special value, add dummy value
SDL_Point none = {-1, -1};
if (!found1) anim->Special1.push_back(none);
if (!found2) anim->Special2.push_back(none);
}
SDL_UnlockSurface(_texture->GetSDLSurface());
}
Now, I'm putting breakpoints in the "if (pix == spec1)" statements, to check if the pixels have been found, but that breakpoint never gets reached. I'm trying to figure out why this is. Does anyone have any clues?
Thanks
[Edit]
Forgot to mention, I'm using a PNG image, not sure if that's part of the problem...