SDL_Blit question

Hi guys,
I’ve a little problem to blit some tiles in the screen, this is the code:

t = TimeLeft();
for (i = 0; i < n; i++)
{
  if (SwapTile(&tiles.Anim[i], &tiles.Anim[i].FrameNow, t))
    SDL_BlitSurface(tiles.Imgs->Frms[tiles.Anim[i].FrameNow],

NULL, scr, &tiles.Anim[i].Rect);
}

SDL_Flip(scr);

The swap function just changes the FrameNow number so I can blit the
appropriate tile.
But I have not changes in my scr.

If I write the samething but in this way:

for (i = 0; i < n; i++)
SwapTile(&tiles.Anim[i], &tiles.Anim[i].FrameNow, t);

SDL_BlitSurface(tiles.Imgs->Frms[tiles.Anim[0].FrameNow], NULL, 		scr,

&tiles.Anim[0].Rect);
SDL_BlitSurface(tiles.Imgs->Frms[tiles.Anim[1].FrameNow],
NULL, scr, &tiles.Anim[1].Rect);
SDL_BlitSurface(tiles.Imgs->Frms[tiles.Anim[N].FrameNow],
NULL, scr, &tiles.Anim[N].Rect);

SDL_Flip(scr);

the animation works.

Why?

Hi guys,
I’ve a little problem to blit some tiles in the screen, this is the code:

In pseudo-code you do, in case 1:

for everything in array
if (swap) then blit
end for

In case 2:

for everything in array
swap
end for
blit1
blit2

blitN

There’s a difference here: if ‘swap’ returns false, then nothing is blitted.

The swap function just changes the FrameNow number so I can blit the
appropriate tile.
And does it return true ?

If I write the samething but in this way:

see above, it’s not the same thing.On 16/06/2006 20:52, Salvatore Di Fazio wrote:

Julien Lecomte ha scritto:> On 16/06/2006 20:52, Salvatore Di Fazio wrote:

In pseudo-code you do, in case 1:

for everything in array
if (swap) then blit
end for

In case 2:

for everything in array
swap
end for
blit1
blit2

blitN

There’s a difference here: if ‘swap’ returns false, then nothing is blitted.

Yes it’s right.

Why is it difference?
If the swap function return false I don’t swap anything so I’ve the last
image in the screen?
is it incorrect?

Tnx

Julien Lecomte ha scritto:

There’s a difference here: if ‘swap’ returns false, then nothing is blitted.

Yes it’s right.

Why is it difference?
If the swap function return false I don’t swap anything so I’ve the last
image in the screen?
is it incorrect?

After you present to backbuffer to the user, don’t count on the
backbuffer staying in it’s previous state. By experience, starting from
a clean slate is less error prone.

After a SDL_Flip, IMHO, it is best to clear (via SDL_FillRect), then
redraw every element you wish to show on the backbuffer again before
representing it.On 17/06/2006 07:54, Salvatore Di Fazio wrote:

On 16/06/2006 20:52, Salvatore Di Fazio wrote: