ZFGC

Resources => Coding => Topic started by: AleX_XelA on January 14, 2007, 02:44:22 pm

Title: [C] SDL Help
Post 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.
Quote

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.
Title: Re: [C] SDL Help
Post by: Windy on January 14, 2007, 03:44:33 pm
use SDL_BlitSurface
Title: Re: [C] SDL Help
Post by: AleX_XelA on January 14, 2007, 03:51:26 pm
How? I want to use this file :

(http://img411.imageshack.us/img411/4411/linksheetlx7.png)

(Credits to MaJoRa, as always)

Title: Re: [C] SDL Help
Post by: Mab on January 14, 2007, 04:29:00 pm
Here is how (I think, if I remember well) it works:

Code: [Select]
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.

Code: [Select]
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...
Title: Re: [C] SDL Help
Post by: Infinitus on January 14, 2007, 05:30:45 pm
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.

Code: [Select]
frameX = (frameIndex % horizontalFrameCount) * frameWidth
frameY = (frameIndex / verticalFrameCount * frameHeight
Title: Re: [C] SDL Help
Post by: AleX_XelA on January 14, 2007, 05:32:53 pm
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.
Title: Re: [C] SDL Help
Post by: Infinitus on January 14, 2007, 08:15:03 pm
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.
Title: Re: [C] SDL Help
Post by: AcidGame on January 15, 2007, 12:05:10 am
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.

Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved