ZFGC
Resources => Coding => Topic started by: AleX_XelA on January 14, 2007, 02:44:22 pm
-
The problem is very easy, I'm making a small Zelda game (just to see what I'm capable of...), and currently everything is going pretty well, except for one thing. When I started, I decided to cut all of Link's frames, but that makes my objects directory pretty big in number of files. On top of that, I have to load all the frames if I want the game to work correctly. What I'm asking is, how can I use a simple sheet that I would have created and determined the space between the frames, and load the whole image once, instead of having to load all the different frames.
personnage chargerImage(personnage link)
{
link.marcher.bas[0] = IMG_Load("objets/link_marcher_bas0.png");
SDL_SetColorKey(link.marcher.bas[0], SDL_SRCCOLORKEY, SDL_MapRGB(link.marcher.bas[0]->format, 0, 255, 0));
link.marcher.bas[1] = IMG_Load("objets/link_marcher_bas1.png");
SDL_SetColorKey(link.marcher.bas[1]], SDL_SRCCOLORKEY, SDL_MapRGB(link.marcher.bas[1]->format, 0, 255, 0));
etc. etc.
I know it's in French, but surely you won't have any problem reading that. "personnage" is the structure I have created for Link, "chargerImage" is a function I've created to load all the images. I want it to make it easier and have one sheet.
-
use SDL_BlitSurface
-
How? I want to use this file :
(http://img411.imageshack.us/img411/4411/linksheetlx7.png)
(Credits to MaJoRa, as always)
-
Here is how (I think, if I remember well) it works:
int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);
You have to create a SDL_Rect and specify the x and y position and the width and height of the sprite on the sheet.
SDL_BlitSurface(thespritesheet, &theRect, thescreen, NULL);
(NULL is for another SDL_Rect, which indicates the position of the sprite on the screen)
etc.
I don't remember if it works like that but I think so, hope it helps you...
-
I think Mab has it more or less. All you need to do is work out the position of the frame on the image (I'll give you an algorithem in a sec) and use the BlitSurface function to blit only that frame of the image.
You can get the position of a frame (on a uniform sprite strip) using the following formula.
frameX = (frameIndex % horizontalFrameCount) * frameWidth
frameY = (frameIndex / verticalFrameCount * frameHeight
-
Thanks a lot guys, I'll try to put it to work in a sec. I was also wondering, is it worth to encrypt/decrypt the graphics? I've tried Google and haven't found a nice way of doing it, and thought I could write my own algorithm.
-
Thanks a lot guys, I'll try to put it to work in a sec. I was also wondering, is it worth to encrypt/decrypt the graphics? I've tried Google and haven't found a nice way of doing it, and thought I could write my own algorithm.
Not really, try packing them together into 1 file, that tends to be more secure.
-
There's really no point in doing that. It is SO easy to reverse it. Just do as Infinitus suggested, and pack them into a single file.