Hi guys,
I want show you a little “trouble (?!)” that I’ve with a blit…
SDL_Surface *grabframe(SDL_Surface *source, SDL_Rect *grabr, int cols,
int frm)
{
SDL_Surface *temp = SDL_ConvertSurface(source, source->format,
SDL_SWSURFACE);
grabr->x = grabr->x + (frm % cols) * grabr->w;
grabr->y = grabr->y + (frm / cols) * grabr->h;
SDL_BlitSurface(source, grabr, temp, NULL);
return temp;
}
I use this function to get my tiles from a surface and:
if ((tiles = IMG_Load(“files/images/tiles.png”)) == NULL)
{
fprintf(stderr, “\n%s\n”, SDL_GetError());
return -1;
}
tr.x = 0;
tr.y = 0;
tr.w = TILEW+1;
tr.h = TILEH+1;
vs = SDL_DisplayFormat(scr);
SDL_GetClipRect(vs, &sr);
pr.w = TILEW;
pr.h = TILEH;
srand(time(NULL));
for (tiley=0; tiley < sr.h; tiley+=TILEH)
{
for (tilex=0; tilex < sr.w; tilex+=TILEW)
{
n = rand() % TILES;
pr.x = tilex;
pr.y = tiley;
SDL_BlitSurface(grabframe(tiles, &tr, COLS, n), &tr, vs, &pr);
}
}
I do that just like a little tutorial.
In teory I will have the screen fill of random tiles but, after the
third tile, I’ve only, I think, NULL image
I tried without the two “for” just for try:
pr.w = TILEW;
pr.h = TILEH;
pr.y = 0;
SDL_BlitSurface(grabframe(tiles, &tr, COLS, 1), &tr, vs, &pr);
pr.x = 32;
pr.y = 0;
SDL_BlitSurface(grabframe(tiles, &tr, COLS, 2), &tr, vs, &pr);
pr.x = 64;
pr.y = 0;
SDL_BlitSurface(grabframe(tiles, &tr, COLS, 3), &tr, vs, &pr);
// the function doesn’t draw anymore
pr.x = 96;
pr.y = 0;
SDL_BlitSurface(grabframe(tiles, &tr, COLS, 4), &tr, vs, &pr);
pr.x = 128;
pr.y = 0;
SDL_BlitSurface(grabframe(tiles, &tr, COLS, 5), &tr, vs, &pr);
but after the third tile, the SDL (I think) doesn’t blit anymore…
Can anybody say me why or have anyidea about that?
tnx