Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Zotoaster

Member Since 10 Jul 2006
Offline Last Active Jan 13 2014 07:13 PM

Posts I've Made

In Topic: Reading (and comparing) pixels in SDL2

12 January 2014 - 05:12 PM

Okay so I tried putting a pixel at 0,0 of the whole image with RGB values 66, 77 and 88. It read them in as 84, 96 and 107, so obviously the colours are either being changed or not read in properly. However, when I try it with a specific alpha value, it reads it in perfectly. I would change my system to only use alpha values but it seems the pixel editor I'm using removes the alpha value once you put in the pixel and blends it in with the rest of the image.


In Topic: Reading (and comparing) pixels in SDL2

12 January 2014 - 04:05 PM

I know for a fact that I'm looping through the correct part of the image because the 'clip' rect is directly taken from the part of my code that renders each sprite frame, which works fine. As for working through all the hex values, each frame is 64x64 pixels, that's 4096 values to look through.

 

I posted the "important" bits in my second post, but in my first post all the relevant code is there.

 

I'll try your idea of testing the known positions of the special pixels and report back.

 

Thanks


In Topic: Reading (and comparing) pixels in SDL2

12 January 2014 - 08:21 AM

I tried it with SDL_MapRGBA but that didn't work either. Here's a condensed version of the code showing only the important bits:

// convert special SDL_Color to Uint32
            Uint32 spec1 = SDL_MapRGBA(_texture->GetSDLSurface()->format, _spec1.r, _spec1.g, _spec1.b, 255);
            Uint32 spec2 = SDL_MapRGBA(_texture->GetSDLSurface()->format, _spec2.r, _spec2.g, _spec2.b, 255);


// ...

// while looping through pixels

                        // get pixel at (x, y)
                        // CODE FOR THIS IN LINK ON FIRST POST
                        Uint32 pix = _texture->GetPixel(x, y);

                        // if pixel is a special value, store it in animation
                        if (pix == spec1)
                        {

                            // breakpoint never reaches here

                            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;
                        }


In Topic: Better sword combat in my 2D platformer

11 January 2014 - 06:10 PM

Thank you for all your replies. I clearly need to learn a bit more about animation.

 

I found on the internet an idea to detect pixels with a designated colour and store their positions in each frame. Using this method, I can put two of them on his hand for each frame, and that should serve to define the sword's position and orientation


In Topic: Better sword combat in my 2D platformer

10 January 2014 - 02:04 PM

Quite right. Here's the frames for the sword stab.

 

Screen_Shot_2014_01_10_at_22_00_00.png


PARTNERS