Hi, I am currently using the SDL library for some simple game development. I have run into a problem. Ok here goes:
I have a Sprite class, which holds all info about a Sprite, (position,dimensions etc). I also have a method in the Sprite class that looks like this:
1 2 3 4 5 6 7 8 9
|
void Sprite::Spr_Blit(SDL_Surface* source,SDL_Surface* dest)
{
SDL_Rect dstrect,srcrect;
dstrect.x = getX();
dstrect.y = getY();
srcrect.w = getW();
srcrect.h = getH();
SDL_BlitSurface(source,NULL,dest,&dstrect);
}
|
This works perfectly fine, for my player object and the background image. My problem comes when I try to set the source rectangle.
1 2 3 4 5 6 7 8 9
|
void Sprite::Spr_Blit(SDL_Surface* source,SDL_Surface* dest)
{
SDL_Rect dstrect,srcrect;
dstrect.x = getX();
dstrect.y = getY();
srcrect.w = getW();
srcrect.h = getH();
SDL_BlitSurface(source,&srcrect,dest,&dstrect);
}
|
When I do this, none of my surfaces show up! I read the API for the BlitSurface and it says the srcrect uses only the width and height of the source rectangle, and the dstrect only uses the position.
I have set the x,y,width and height of all my sprites using a setBounds() method that I created.
My understanding is that, srcrect will set the width and height of the surface, and dstrect will set the position of that on the destination surface. Is this wrong?
If you need to see any code just let me know. Thanks.