Sprites

i am making a game, and i have a map which is made from little square
bitmaps,
now i want to put a sprite on this map and it must be able to move,
what is the best way to do this? i tried to use SDLSprite library, but the
square with
the sprite is black and i want it to be in the color of the map (i want to
have sth like another layer)
how to do this?

where can i find any rts made in STL with sources?

TIA
Przemek

Hi, maybe you need to learn a bit more about game programming with SDL. You
can look at this tutorial page which seems to be good since it comes back on
the list regularly.

Bye

Julien> ----- Original Message -----

From: askywalker@wp.pl (przemek)
To:
Sent: Monday, July 07, 2003 8:24 PM
Subject: [SDL] sprites

i am making a game, and i have a map which is made from little square
bitmaps,
now i want to put a sprite on this map and it must be able to move,
what is the best way to do this? i tried to use SDLSprite library, but the
square with
the sprite is black and i want it to be in the color of the map (i want to
have sth like another layer)
how to do this?

where can i find any rts made in STL with sources?

TIA
Przemek


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Sorry, here is the URL
http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/index

Julien> ----- Original Message -----

From: julien.pauty@irisa.fr (Julien Pauty)
To:
Sent: Wednesday, July 09, 2003 10:33 AM
Subject: Re: [SDL] sprites

Hi, maybe you need to learn a bit more about game programming with SDL.
You
can look at this tutorial page which seems to be good since it comes back
on
the list regularly.

Bye

Julien
----- Original Message -----
From: “przemek”
To:
Sent: Monday, July 07, 2003 8:24 PM
Subject: [SDL] sprites

i am making a game, and i have a map which is made from little square
bitmaps,
now i want to put a sprite on this map and it must be able to move,
what is the best way to do this? i tried to use SDLSprite library, but
the

square with
the sprite is black and i want it to be in the color of the map (i want
to

have sth like another layer)
how to do this?

where can i find any rts made in STL with sources?

TIA
Przemek


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

Hi,

I’ve got a PNG image containing 5 sprites. Like that (the “0” represents a single sprite):----------------

0 0 0 0 0

How can I create an array of SDL_Surface from the PNG?
So far I’ve got:

SDL_Surface spriteMap = IMG_Load(file);
if (spriteMap == NULL) {
return;
}
SDL_Surface sprites[5
1];

int spriteWidth = spriteMap->w / 5;
int spriteHeight = spriteMap->h / 1;
SDL_Rect spriteRect;
spriteRect.x = 0;
spriteRect.y = 0;
spriteRect.w = spriteWidth;
spriteRect.h = spriteHeight;

for (int i=0; i<5; i++) {
spriteRect.x = ispriteWidth;
for (int j=0; j<1; j++) {
spriteRect.y = j
spriteHeight;
SDL_BlitSurface(spriteMap, &spriteRect, &(sprites[i+j]), NULL);
}
}

SDL_FreeSurface(spriteMap);

I think the problem is each value from the array is NULL, but how can I create an empty SDL_Surface? Should I use SDL_CreateRGBSurface?

Ced.

Cedric Bompart: “[SDL] sprites” (2004-05-20 12:51)

#Hi,#
#I’ve got a PNG image containing 5 sprites. Like that (the “0” represents a single sprite):
#----------------
#| 0 0 0 0 0 |
#----------------

#How can I create an array of SDL_Surface from the PNG?
#So far I’ve got:

SDL_Surface *spriteMap = IMG_Load(file);

if (spriteMap == NULL) {

return;

}

SDL_Surface sprites[5*1];

int spriteWidth = spriteMap->w / 5;

int spriteHeight = spriteMap->h / 1;

SDL_Rect spriteRect;

spriteRect.x = 0;

spriteRect.y = 0;

spriteRect.w = spriteWidth;

spriteRect.h = spriteHeight;

for (int i=0; i<5; i++) {

spriteRect.x = i*spriteWidth;

for (int j=0; j<1; j++) {

spriteRect.y = j*spriteHeight;

SDL_BlitSurface(spriteMap, &spriteRect, &(sprites[i+j]), NULL);

}

}

SDL_FreeSurface(spriteMap);

#I think the problem is each value from the array is NULL, but how can I create an empty SDL_Surface? Should I use SDL_CreateRGBSurface?

Yes. Also, you should use a SDL_Surface* array instead of object array:

SDL_Surface* sprites[5];

(I really don’t know what happens if you do it the way you’ve written… consult
SDL_CreateRGBSurface docs)

hope it helps,

/Olof

#Ced.

Cedric Bompart wrote:

Hi,

I’ve got a PNG image containing 5 sprites. Like that (the "0"
represents a single sprite):

0 0 0 0 0

How can I create an array of SDL_Surface from the PNG?
So far I’ve got:

SDL_Surface spriteMap = IMG_Load(file);
if (spriteMap == NULL) {
return;
}
SDL_Surface sprites[5
1];

You’d better use an array of pointers to surfaces here :
SDL_Surface* sprites[5*1];

int spriteWidth = spriteMap->w / 5;
int spriteHeight = spriteMap->h / 1;
SDL_Rect spriteRect;
spriteRect.x = 0;
spriteRect.y = 0;
spriteRect.w = spriteWidth;
spriteRect.h = spriteHeight;

for (int i=0; i<5; i++) {
spriteRect.x = ispriteWidth;
for (int j=0; j<1; j++) {
spriteRect.y = j
spriteHeight;

here add surface creation :
sprites[i+j*width]=SDL_CreateRGBSurface(some nice surface format);

  SDL_BlitSurface(spriteMap, &spriteRect, &(sprites[i+j]), NULL);

Hey, you should also fix that “i+j”. That should be i+j*width

}     

}

SDL_FreeSurface(spriteMap);

I think the problem is each value from the array is NULL, but how can
I create an empty SDL_Surface? Should I use SDL_CreateRGBSurface?

Hey, if you know the answer, why do you ask ? :slight_smile:
Seriously, the trick is to have an array of pointers to surfaces so that
you can use SDL_CreateRGBSurface to return pointers to fill this array.
The rest of the code seems correct.
And don’t forget to free the sprites[] array once you don’t use these
anymore !

Stephane

Cool it works… I’ve asked about “CreateRGBSurface” because I didn’t know if it’ll be the best solution.

Another thing how can I mirror an image based on the Y axis? Can SDL do that or do I need to implement my own algo? Can someone post the algo please? :slight_smile:

Ced.> ----- Original Message -----

From: sdl-bounces+cedric.bompart=morse.com@libsdl.org [mailto:sdl-bounces+cedric.bompart=morse.com at libsdl.org] On Behalf Of Stephane Marchesin
Sent: 20 May 2004 13:06
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: Re: [SDL] sprites

Cedric Bompart wrote:

Hi,

I’ve got a PNG image containing 5 sprites. Like that (the "0"
represents a single sprite):

0 0 0 0 0

How can I create an array of SDL_Surface from the PNG?
So far I’ve got:

SDL_Surface spriteMap = IMG_Load(file);
if (spriteMap == NULL) {
return;
}
SDL_Surface sprites[5
1];

You’d better use an array of pointers to surfaces here :
SDL_Surface* sprites[5*1];

int spriteWidth = spriteMap->w / 5;
int spriteHeight = spriteMap->h / 1;
SDL_Rect spriteRect;
spriteRect.x = 0;
spriteRect.y = 0;
spriteRect.w = spriteWidth;
spriteRect.h = spriteHeight;

for (int i=0; i<5; i++) {
spriteRect.x = ispriteWidth;
for (int j=0; j<1; j++) {
spriteRect.y = j
spriteHeight;

here add surface creation :
sprites[i+j*width]=SDL_CreateRGBSurface(some nice surface format);

  SDL_BlitSurface(spriteMap, &spriteRect, &(sprites[i+j]), NULL);

Hey, you should also fix that “i+j”. That should be i+j*width

}     

}

SDL_FreeSurface(spriteMap);

I think the problem is each value from the array is NULL, but how can
I create an empty SDL_Surface? Should I use SDL_CreateRGBSurface?

Hey, if you know the answer, why do you ask ? :slight_smile: Seriously, the trick is to have an array of pointers to surfaces so that you can use SDL_CreateRGBSurface to return pointers to fill this array.
The rest of the code seems correct.
And don’t forget to free the sprites[] array once you don’t use these anymore !

Stephane


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Not sure what you mean by “based on the Y axis”, but either way, you
could just blit 1 pixel strips flipping the coordinates of the loop
axis for either the source or the target blits.

//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.nethttp://www.reologica.se —On Thursday 20 May 2004 15.48, Cedric Bompart wrote:

Cool it works… I’ve asked about “CreateRGBSurface” because I
didn’t know if it’ll be the best solution.

Another thing how can I mirror an image based on the Y axis? Can
SDL do that or do I need to implement my own algo? Can someone post
the algo please? :slight_smile:

Can you show me a code example to do the mirror?> ----- Original Message -----

From: sdl-bounces+cedric.bompart=morse.com@libsdl.org [mailto:sdl-bounces+cedric.bompart=morse.com at libsdl.org] On Behalf Of David Olofson
Sent: 20 May 2004 16:28
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: Re: [SDL] sprites

On Thursday 20 May 2004 15.48, Cedric Bompart wrote:

Cool it works… I’ve asked about “CreateRGBSurface” because I didn’t
know if it’ll be the best solution.

Another thing how can I mirror an image based on the Y axis? Can SDL
do that or do I need to implement my own algo? Can someone post the
algo please? :slight_smile:

Not sure what you mean by “based on the Y axis”, but either way, you could just blit 1 pixel strips flipping the coordinates of the loop axis for either the source or the target blits.

//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.nethttp://www.reologica.se


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

SDL_BlitSurface() takes an SDL_Rect for the source and one for the
destination. The source rect describes the area in the source surface
to blit from, and the destination rect holds the destination
coordinates. (Note: The w and h fields in the destination rect are
ignored!)

Some pseudo code:

Vertical flip:
for y = (each line in the source surface)
blit a single pixel row from y to (h - y)

Horizontal flip:
for x = (each column in the source surface)
blit a single pixel column from x to (w - x)

Unfortunately, I don’t have code lying around to do that (I think…),
and I have a scripting engine to finish, so you figure out the
implementation part. :wink:

//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.nethttp://www.reologica.se —On Monday 24 May 2004 15.05, Cedric Bompart wrote:

Can you show me a code example to do the mirror?

http://www.ferzkopp.net/~aschiffler/Software/SDL_gfx-2.0/index.html does
flipping, zooming and much more afaik.

David Olofson wrote:>On Monday 24 May 2004 15.05, Cedric Bompart wrote:

Can you show me a code example to do the mirror?

SDL_BlitSurface() takes an SDL_Rect for the source and one for the
destination. The source rect describes the area in the source surface
to blit from, and the destination rect holds the destination
coordinates. (Note: The w and h fields in the destination rect are
ignored!)

Some pseudo code:

Vertical flip:
for y = (each line in the source surface)
blit a single pixel row from y to (h - y)

Horizontal flip:
for x = (each column in the source surface)
blit a single pixel column from x to (w - x)

Unfortunately, I don’t have code lying around to do that (I think…),
and I have a scripting engine to finish, so you figure out the
implementation part. :wink:

//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.nethttp://www.reologica.se


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl