# What are offsets in SDL?

## Recommended Posts

hi im teaching myself SDL via lazyfoos website and i keep coming across "offset"

void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
//Make a temporary rectangle to hold the offsets
SDL_Rect offset;

//Give the offsets to the rectangle
offset.x = x; offset.y = y;
}


im obviously new to all this so please be gentle, im not sure what these actually mean or do? what am i offsetting? is it something to do with where its going to appear on the screen?

thanks in advance Edited by JTippetts
Obnoxious font coloration; please use code tags for source code.

##### Share on other sites
ultramailman    1720

don't forget what comes after it:

SDL_BlitSurface( source, NULL, destination, &offset );

[url]http://www.libsdl.org/docs/html/sdlblitsurface.html[/url]

you will see that the rectangle named "offset" is used to pass the position of the surface you want to blit.

edit: so it is simply the position of the surface you want to draw. if i was lazyfoo, i'd have called it "position" instead, haha.

edit: offset makes sense too. it is an offset to the upper left corner of the background surface you want to draw on.

Edited by ultramailman

##### Share on other sites

As ultramailman explains, it's the position on the screen where you want to draw the image.

However, since 'destination' doesn't have to be the screen (it could be another non-screen SDL_Surface), so it would be the position in 'destination' where you want to draw 'source'.

##### Share on other sites

i love this forum, cheers people