Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [C] SDL Help  (Read 893 times)

0 Members and 1 Guest are viewing this topic.
[C] SDL Help
« on: January 14, 2007, 02:44:22 pm »
  • Credits to BaB
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Posts: 806
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.
Logged
Re: [C] SDL Help
« Reply #1 on: January 14, 2007, 03:44:33 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
use SDL_BlitSurface
Logged
Re: [C] SDL Help
« Reply #2 on: January 14, 2007, 03:51:26 pm »
  • Credits to BaB
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Posts: 806
How? I want to use this file :



(Credits to MaJoRa, as always)

Logged

Mab

Re: [C] SDL Help
« Reply #3 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...
« Last Edit: January 14, 2007, 05:09:18 pm by Mab »
Logged
Re: [C] SDL Help
« Reply #4 on: January 14, 2007, 05:30:45 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
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
Logged
Re: [C] SDL Help
« Reply #5 on: January 14, 2007, 05:32:53 pm »
  • Credits to BaB
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Posts: 806
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.
Logged
Re: [C] SDL Help
« Reply #6 on: January 14, 2007, 08:15:03 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
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.
Logged
Re: [C] SDL Help
« Reply #7 on: January 15, 2007, 12:05:10 am »
  • If not now, when?
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 520
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.
Logged
Pages: [1]   Go Up

 


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



Page created in 0.136 seconds with 37 queries.