# SDL_BlitSurface() setting the dest Rect's coords to 0...

## Recommended Posts

nsto119    103
I've been having this problem for a while now. For some reason, when I blit a surface, if the X- or Y- coordinates are less than zero, the SDL_BlitSurface() function is setting them back to zero... this means that if, for example, the player fires a missile from the ship, it just stops dead at the top of the screen. I can't figure this out for the life of me, and I haven't seen any other games that are having this problem... any ideas?

##### Share on other sites
Guest Anonymous Poster
post your code and let us take a look

##### Share on other sites
Guest Anonymous Poster
just to make sure...

make a function to blit like this

void apply(int x,int y,SDL_Surface* source, SDL_Surface* destination)
(
SDL_Rect offset;

offset.x = x;
offset.y = y;

SDL_BlitSurface(source,NULL,destination,&ofset);
}

##### Share on other sites
rip-off    10976
SDL_Rect offset;offset.x = x;offset.y = y;SDL_BlitSurface(source,NULL,destination,&offset);

SDL_BlitSurface stores the *clipped* rectangle in offset...
is that what you mean?

or is the image actaully stopping at the top left? (it doesnt on my SDL programs)

##### Share on other sites
nsto119    103
Well... I got it working, but I'm not sure WHY.

In the Sprite's Render() function, instead of blitting using the Sprite class's private Rect member for the dst, I dereferenced it and created a copy and used the copy for blitting... I don't really see why this would make a difference, though.

EDIT: Nevermind, it all made sense after I gave it a little thought.