[SDL] Cutting images into tiles
Brønnum-Hansen
bronnum-hansen at mail.dk
Sat Apr 3 00:38:43 PST 2004
Okay, now you know my problem.
The graphic is at www.caturn.dk/warrior.png
The code is this:
SDL_Surface *human, *back[10];
SDL_Rect cut, paste;
human = IMG_Load("sprites/warrior.png");
paste.x = 0;
paste.y = 0;
paste.h = 40;
paste.w = 40;
cut.x = 0;
cut.y = 0;
cut.h = 40;
cut.w = 40;
for (int nr = 0 ; nr < 10 ; nr++) {
SDL_BlitSurface(human, &cut, back[nr], &paste);
cut.x += 40;
}
Why does this put a completely transparent picture in all "back" surfaces.
How would you do?
Kind regards,
Christian
Bernhard Bliem <bernhard.bliem at chello.at> wrote:
> Hi
>
> What about this?
>
> struct
> {
> int pos_x,
> pos_y,
> width, /* width of 1 frame */
> height, /* height of 1 frame */
> frame; /* number of current frame */
> } player;
>
> void DrawPlayer(SDL_Surface *surface) /* surface is
> warrior.png */
> {
> SDL_Rect src, dest;
>
> src.x = player.frame * player.width;
> src.y = 0;
> src.w = player.width;
> src.h = player.height;
>
> dest.x = player.pos_x;
> dest.y = player.pos_y;
>
> SDL_BlitSurface(surface, &src, SDL_GetVideoSurface(),
> &dest);
> }
>
> Brønnum-Hansen wrote:
> > Well I don't think it contains the stuff you mention but
> I've uploaded the file to www.caturn.dk/warrior.png
> > Maybe it explains more.
> >
> > David Olofson <david at olofson.net> wrote:
> >
> >>On Monday 29 March 2004 15.17, Brønnum-Hansen wrote:
> >>
> >>>Well, I was in a hurry and did not write what I wanted
> the
> >>
> >>code to
> >>
> >>>do... I declared this:
> >>>SDL_Surface *human *back[10];
> >>>SDL_Rect cut, paste;
> >>>
> >>>Then the code I wrote before which should put the first
> >>
> >>40x40
> >>
> >>>pixels on back[0] then the next 40x40 in back[1] and so
> >>
> >>on. Then
> >>
> >>>later in the program I use back[0] to back [9] for an
> >>
> >>animation.
> >>
> >>>So, contents from human should be blitted into back.
> >>
> >>Ok... That can be a bit more hairy, at least if you want
> to
> >>use alpha
> >>and/or colorkey blitting.
> >>
> >>How did you initialize the back[] array of surfaces? You
> >>have to
> >>create a surface for each index in advance, and you may
> have
> >>to set
> >>up colorkey and/or alpha before and/or after the "cut"
> blit,
> >>to get
> >>the desired final result.
> >>
> >>Check the documentation for SDL_BlitSurface() for details
> on
> >>
> >>blending/colorkeying semantics. (Not always what you'd
> >>expect...)
> >>
> >>
> >>//David Olofson - Programmer, Composer, Open Source
> >>Advocate
> >>
> >>.- Audiality
> >>-----------------------------------------------.
> >>| Free/Open Source audio engine for games and multimedia.
>
> >>|
> >>| MIDI, modular synthesis, real time effects,
> scripting,...
> >>|
> >>`----------------------------------->
> http://audiality.org
> >>-'
> >> --- http://olofson.net --- http://www.reologica.se ---
> >>
> >>
> >>_______________________________________________
> >>SDL mailing list
> >>SDL at libsdl.org
> >>http://www.libsdl.org/mailman/listinfo/sdl
> >
> >
> >
> > _______________________________________________
> > SDL mailing list
> > SDL at libsdl.org
> > http://www.libsdl.org/mailman/listinfo/sdl
> >
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
More information about the SDL
mailing list