I just tried moving a class I wrote in a main function onto a header file(It worked in the main) which includes using of SDL for graphic management.
This is the code I use to load the sprite from "Hero.cpp", having all the variables defined in "Hero.cpp" and in the main program code file, passed as arguments of the function(The SDL_Surfaces):
void Hero::printSpriteset(SDL_Surface *screen, SDL_Surface *head, SDL_Surface *body, SDL_Surface *legR,
SDL_Surface *handR, SDL_Surface *legL, SDL_Surface *handL){
SDL_Rect source1;
source1.x = 0;
source1.y = 0;
source1.w = 16;
source1.h = 16;
SDL_Rect destination1;
destination1.x = (heroX+((headW-bodyW)/2)+1);
destination1.y = (heroY+headH-2);
destination1.w = 16;
destination1.h = 16;
SDL_BlitSurface(body, &source1, screen, &destination1);
...
}
This is repeated for 6 sprites but I cut it down as they're all similiar.
The heroX, headW, etc. variables are members of this class so they didn't need forwarding, as far as I know.
And the surfaces for the sprites have been filled in a different function in the same class.
An extract from the function:
else if(weightM || weightF){
head = IMG_Load("HeadLV10Weight.png");
body = IMG_Load("BodyLV10WeightAll.png");
legR = IMG_Load("LegLV10WeightAllR.png");
handR = IMG_Load("HandLV10WeightAllR.png");
legL = IMG_Load("LegLV10WeightAllL.png");
handL = IMG_Load("HandLV10WeightAllL.png");
handW = 4; handH = 6; headW = 11; headH = 9; bodyW = 7; bodyH = 6; legW = 6; legH = 5;
}
So as you can see, it should, and did until I moved it onto a header file, load fine.
It compiles fine and all with no errors and the variables inside the class that's in the header work fine as well(Monitoring through the console box), the only problem is that when it comes to printing the graphics, it just ignores it and the sprites aren't shown even though the program goes on.
Any help you can offer?
Thanks in advance.