void drawtile(int x, int y, int tile)
{
// Lock surface if needed
if (SDL_MUSTLOCK(gTiles))
if (SDL_LockSurface(gTiles) < 0)
return;
int i, j;
for (i = 0; i < TILESIZE; i++)
{
int screenofs = x + (y + i) * PITCH;
int tileofs = (i + tile * TILESIZE) * (gTiles->pitch / 4);
for (j = 0; j < TILESIZE; j++)
{
((unsigned int*)gScreen->pixels)[screenofs] =
((unsigned int*)gTiles->pixels)[tileofs];
screenofs++;
tileofs++;
}
}
// Unlock if needed
if (SDL_MUSTLOCK(gTiles))
SDL_UnlockSurface(gTiles);
}
I call this function once with the 2nd tile, then again with the first one. So the overlap i should see the first tile and then the 2nd through the hole of the first one.
But im getting only a white hole where the tile was supposed to be transparent. I do realize i must be doing something horribly wrong but im just starting out so…halp?
I call this function once with the 2nd tile, then again with the first one.
So the overlap i should see the first tile and then the 2nd through the hole
of the first one.
As far as I can see, you simply copy the pixels. So the pixeldata of the
second one simply overwrites the first data. They are not merged in your
code.
Use SDL_BlitSurface. That should handle the Alpha channel…Am Donnerstag, dem 19. Nov 2009 schrieb Tabris:
Thanks for the help list, it worked wonder! I got a prb tho. From SDL_BlitSurface documentation:
int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);
Description
This performs a fast blit from the source surface to the destination surface.
The width and height in srcrect determine the size of the copied rectangle. Only the position is used in the dstrect (the width and height are ignored).
If srcrect is NULL, the entire surface is copied. If dstrect is NULL, then the destination position (upper left corner) is (0, 0).
So my prb is that im using 32 x 32 tiles. If i wanna draw, say, the 2nd time i would create a SDL_Rect with x = 0 and y = 32. If i give that SDL_Rect as a second argument to SDL_BlitSurface, its gonna draw everything y>32. How can i make it stop at y> 64 (so i get only one tile)?
Nevermind, found out how to solve it. Apperantly the width and height are NOT! ignored, and they are used to crop the images…So yeah…Thanks everyone =D
Jonny DOn Sat, Nov 21, 2009 at 4:41 PM, Tabris wrote:
Thanks for the help list, it worked wonder! I got a prb tho. From
SDL_BlitSurface documentation:
Quote:
int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
SDL_Rect *dstrect);
Description
This performs a fast blit from the source surface to the destination
surface.
The width and height in srcrect determine the size of the copied rectangle.
Only the position is used in the dstrect (the width and height are ignored).
If srcrect is NULL, the entire surface is copied. If dstrect is NULL, then
the destination position (upper left corner) is (0, 0).
So my prb is that im using 32 x 32 tiles. If i wanna draw, say, the 2nd
time i would create a SDL_Rect with x = 0 and y = 32. If i give that
SDL_Rect as a second argument to SDL_BlitSurface, its gonna draw everything
y>32. How can i make it stop at y> 64 (so i get only one tile)?
Jonny DOn Sat, Nov 21, 2009 at 4:49 PM, Tabris wrote:
Nevermind, found out how to solve it. Apperantly the width and height are
NOT! ignored, and they are used to crop the images…So yeah…Thanks
everyone =D