Character animation with SDL

Hi

I’m currently working on a game that is quit similar to "Prince of Persia 1/2"
when it comes to character movement & level design. Unfortunately, I’ve got
some questions that I can’t figure out my self:

  • How can I best store an character animation?
    One animated gif for walking, one for running, one for jumping…
    or should I use one large image and blit out the rects for each frame to
    display?
    or should I …

If I should use one large image, what is the most efficient way:
1. Make an SDL_Rect-array and blit from the large image to the screen
2. Make one SDL_Surface for each frame and then blit each frame to
screen?

  • A friend once told me that modern pc’s have a special memory in the
    graphic hardware that automaticly pasted sprite graphics to the screen.
    This means that if I want to move a sprite - I only need to change the
    coordinates to it (don’t need to care about refreshing background etc.).
    It made it extra easy for spritecollision-dection too. Is this correct?

  • Any advice on how to make a nice & powerful level editor? Basic
    concepts I should know about? Source code to read?

I should probably spend some more time one Abuse’s source code, but it’s
written in C++ (and I use C) …

If anyone take the time to share some ideas it would be great!
H?kon Skjelten
Norway

I’m currently working on a game that is quit similar to "Prince of Persia 1/2"
when it comes to character movement & level design. Unfortunately, I’ve got
some questions that I can’t figure out my self:

this is the sort of thing I would like a separate sdl-game list for.
This has been discussed many times before so I’d like to say “read
the archives”, but since the archives don’t work very well (the index
is on one huge page and the search function is b0rken), I’ll answer it:

  • How can I best store an character animation?
    One animated gif for walking, one for running, one for jumping…
    or should I use one large image and blit out the rects for each frame to
    display?

store it as you like, as long as you can read it back. SDL_image doesn’t
support multi-frame gifs and won’t for some time. Either store individual
images or one large, doesn’t matter

If I should use one large image, what is the most efficient way:

  1. Make an SDL_Rect-array and blit from the large image to the screen
  2. Make one SDL_Surface for each frame and then blit each frame to
    screen?

For RLE (which you want to use for software surfaces), use one surface
for each frame. For hardware surfaces, both work equally well

  • A friend once told me that modern pc’s have a special memory in the
    graphic hardware that automaticly pasted sprite graphics to the screen.
    This means that if I want to move a sprite - I only need to change the
    coordinates to it (don’t need to care about refreshing background etc.).

yes it’s used for the mouse pointer. it’s cannot be used for anything
else in practice

  • Any advice on how to make a nice & powerful level editor? Basic
    concepts I should know about? Source code to read?

learn programming in general. a common trick is to encode your levels
in ascii so you can use an ordinary text editor

or should I use one large image and blit out the rects for each frame to
display?

This is the approach I use. Simply use the frame number to compute the
offset into the source image when performing the blit.

If I should use one large image, what is the most efficient way:

  1. Make an SDL_Rect-array and blit from the large image to the screen
  2. Make one SDL_Surface for each frame and then blit each frame to
    screen?

Again, I recommend option one… use the frame number to compute the
source position of the frame. I’m not certain, but I suspect there is a
slight performance edge to using one big offscreen surface instead of
a bunch of smaller ones (depending on hardware of course).

  • A friend once told me that modern pc’s have a special memory in the
    graphic hardware that automaticly pasted sprite graphics to the screen.
    This means that if I want to move a sprite - I only need to change the
    coordinates to it (don’t need to care about refreshing background etc.).
    It made it extra easy for spritecollision-dection too. Is this correct?

Perhaps some hardware has this, but I do not think it is the norm. Most
modern graphics cards support hardware accelerated copy of images
between offscreen and onscreen video ram (blitting).

  • Any advice on how to make a nice & powerful level editor? Basic
    concepts I should know about? Source code to read?

I should probably spend some more time one Abuse’s source code, but it’s
written in C++ (and I use C) …

I personally think there are many great reasons to use C++ when
programming a video game. I take advantage of object oriented
concepts quite a bit in my GridSlammer game engine. For example,
All interactive objects in the game (creatures, missiles, food packs…)
are derived from the base class GridObj or one of its children (such as
GridActor). To create a new monster that is very similar to another
but simply has some additional capabilities, derive your new monster
from the existing one and add the additional methods, member vars,
and such.

Key functionality (such as collision detection) that is needed by all
objects is already implemented in the base classes, so there is no
need to reimplement it for new creatures.

I guess what I am really trying to say is: it is worth learning C++.
It can really streamline the writing and eventual expansion of your
game. Feel free to check out GridSlammer at
http://www.gridslammer.org. The class descriptions are a little out
of date, but it will give you a basic idea of how I used object oriented
concepts in designing the game engine.

I hope this was helpful,

Thad Phetteplace

One way we do it, is to surround the charater with a rectangle of a
spacific colour. This way when the artist gives me a charater alls my
program does is open the file, map out the x, y, w, h of each charater
animation. This makes it a little more dynamic, the other way would be
for the artist to give me the x,y,w,h which I could store in a conf file
for charaters. If you like I can post a sample source for this.

Thanks
Dean

H?kon Skjelten wrote:> Hi

I’m currently working on a game that is quit similar to "Prince of Persia 1/2"
when it comes to character movement & level design. Unfortunately, I’ve got
some questions that I can’t figure out my self:

  • How can I best store an character animation?
    One animated gif for walking, one for running, one for jumping…
    or should I use one large image and blit out the rects for each frame to
    display?
    or should I …

If I should use one large image, what is the most efficient way:

  1. Make an SDL_Rect-array and blit from the large image to the screen
  2. Make one SDL_Surface for each frame and then blit each frame to
    screen?
  • A friend once told me that modern pc’s have a special memory in the
    graphic hardware that automaticly pasted sprite graphics to the screen.
    This means that if I want to move a sprite - I only need to change the
    coordinates to it (don’t need to care about refreshing background etc.).
    It made it extra easy for spritecollision-dection too. Is this correct?

  • Any advice on how to make a nice & powerful level editor? Basic
    concepts I should know about? Source code to read?

I should probably spend some more time one Abuse’s source code, but it’s
written in C++ (and I use C) …

If anyone take the time to share some ideas it would be great!
H?kon Skjelten
Norway

Shameless plug for my open source project:

You could use a sprite engine…may I suggest:

www.grinninglizard.com/kyra?

lee

  • How can I best store an character animation?
    One animated gif for walking, one for running, one for jumping…

I’m not sure there’s a way to load frames from an animated GIF (or any
other multiframed- or layered- image file)

Of course, you could build the animated GIF and then use tools like
multigif and netpbm to convert it to split files or one big file.

or should I use one large image and blit out the rects for each frame to

This is resonable.

  display?

or should I …

I’m naughty and create separate image files from each frame of animation.

If I should use one large image, what is the most efficient way:

  1. Make an SDL_Rect-array and blit from the large image to the screen
  2. Make one SDL_Surface for each frame and then blit each frame to
    screen?

Good question. Those more familiar with the internals of SDL (and
video cards) would know which is more efficient (if one even is)

  • A friend once told me that modern pc’s have a special memory in the
    graphic hardware that automaticly pasted sprite graphics to the screen.
    This means that if I want to move a sprite - I only need to change the
    coordinates to it (don’t need to care about refreshing background etc.).
    It made it extra easy for spritecollision-dection too. Is this correct?

Uhhhh… old computers (Commodore 64, Atari 8-bit, Amiga) had these
(including sprite collision detection! :slight_smile: )

Newer graphics cards may finally have this, but you cannot assume
someone’s particular video card has it or not. If they don’t, it
needs to be emulated.

In this case, you’d have to handle all this API stuff either within SDL
or directly within your code.

Either way - ick.

  • Any advice on how to make a nice & powerful level editor? Basic
    concepts I should know about? Source code to read?

I use Emacs and ASCII files. :wink:

Good luck, and welcome to the world of SDL!

-bill!

If I should use one large image, what is the most efficient way:
1. Make an SDL_Rect-array and blit from the large image to the screen
2. Make one SDL_Surface for each frame and then blit each frame to
screen?

Good question. Those more familiar with the internals of SDL (and
video cards) would know which is more efficient (if one even is)

With my experience I have found that, atleast with the software only I get on my
video card, doing an SDL_Rects with an Array of areas that need to be updated is
MUCH more efficient. I always still blit to the big image all the time. But I
only display parts that are changed using a SDL_Rects( ) call. In my game it has
increased fps by x10 with only this change.

But don’t take my word for it :slight_smile:
I’m just a newbie too!
Jaren Peterson

  • How can I best store an character animation?
    One animated gif for walking, one for running, one for jumping…

I’m not sure there’s a way to load frames from an animated GIF (or any
other multiframed- or layered- image file)

There isn’t anything in SDL to do this, nor am I aware of any libraries that
can handle this. Of course, anything is possible. It just means you would
have to write the code to load an animated GIF file and create an array of
surfaces for them all. Sounds like more than you could probably tackle at
this point in time, though.

So you probably want to go another route. Basically you could use individual
images, or one big image. You should consider which one is going to be
easier to work with for the artist (or yourself if you are going to do the
art). Then also look at how blitting is done, what the overhead is between
one big image and many little images, etc. Essentially you probably want to
design your system of doing things around the tools you have to work with SDL
and the artist.

Of course, you could build the animated GIF and then use tools like
multigif and netpbm to convert it to split files or one big file.

Right, but check with the artist. Find out what would work best for him. If
doing an animated gif would be a pain for him, and decoding them in your code
would be a pain, then there’s not much point in going that route, is there?
But if each of you are under the assumption it’s easier for the other guy so
you deal with it, then you are using an inefficient system.

or should I use one large image and blit out the rects for each frame to

This is resonable.

  display?
or should I ........

I’m naughty and create separate image files from each frame of animation.

It’s mainly up to you. It can be done either way, easy to use either way
really, just as fast either way really. So if you prefer one method, you
should use that method.

If I should use one large image, what is the most efficient way:
1. Make an SDL_Rect-array and blit from the large image to the screen
2. Make one SDL_Surface for each frame and then blit each frame to
screen?

#2 sounds like it’s defeating the purpose of using one large image. If you
have a bunch of little images, why not blit those directly, instead of to the
larger image and then that directly?

Good question. Those more familiar with the internals of SDL (and
video cards) would know which is more efficient (if one even is)

I haven’t really looked into it, but having looked at some of the code, it
looks like well written code, so I’m sure there wouldn’t be a difference
really. It would mainly come down to where your surfaces are located:
hardware or software. Hardware surfaces will be faster than software ones.

  • A friend once told me that modern pc’s have a special memory in the
    graphic hardware that automaticly pasted sprite graphics to the screen.
    This means that if I want to move a sprite - I only need to change the
    coordinates to it (don’t need to care about refreshing background etc.).
    It made it extra easy for spritecollision-dection too. Is this correct?

No. There’s a lot of different video cards out there, though, so some cards
might support this. It isn’t anything standardized, though, like SVGA. So
if you are writing for a general audience, best to avoid using anything like
that.

  • Any advice on how to make a nice & powerful level editor? Basic
    concepts I should know about? Source code to read?

Ya. Figure out what you need first (try and consider all possibilities and
break them down into cases), then design your editor to meet those needs, and
then start implementing it. Pretty much the way any editor should be done
really. You could use other methods, like a text editor. If that seems like
it would be even harder than making an editor (does to me unless maps are
pretty simple), then you might be better off making an editor.

One thing about editors I’ve learned, though, is keeping editor code and game
code in sync can be challanging. Some people think it better to keep the 2
as seperate programs, while others think it better to combine them into one
program. All kinds of interesting issues with them. :slight_smile: The best way to
discover these for yourself of course, is to jump in and write one yourself.
So it’ll be educational at the very least.

So I wouldn’t worry so much about reading source code or anything. You might
want to look at other people’s editors for their games, though, and see what
you like and dislike about them. You’re almost sure to get new ideas you
never though of before, which can be useful.On Friday 16 March 2001 11:10, you wrote:

Hi

Hiya :wink:

  • Any advice on how to make a nice & powerful level editor? Basic
    concepts I should know about? Source code to read?

(since no one else mentionned this yet, I thought I’d chime in… :wink:

One thing to remember…

Always be prepared to throw away your code and start from scratch if needs be!

A good programmer knows when to reuse code… a great one knows when to throw
it away and start again! (I think that was an ESR quote… and I’m certain I
munged it ;-)On Fri, 16 Mar 2001, you wrote:


Sam “Criswell” Hart <@Sam_Hart> AIM, Yahoo!:
Homepage: < http://www.geekcomix.com/snh/ >
PGP Info: < http://www.geekcomix.com/snh/contact/ >
Advogato: < http://advogato.org/person/criswell/ >

I’m naughty and create separate image files from each frame of animation.

It’s mainly up to you. It can be done either way, easy to use either way
really, just as fast either way really. So if you prefer one method, you
should use that method.

RLE blits are slower from subrectangles

From the questions you are asking, you might be
interested in the AutoManga engine that I’m
writing. Unfortunately, I’m probably at least
as clueless as you about the application of SDL
to this problem (as will be evident from my
other thread on this list :slight_smile: ), but I am
working on more or less the same issues.

AutoManga is based on emulating the abstractions
of traditional cel animation, using SDL to
“stack and photograph” the “cels” which are to
be stored as PNG, JPG, or SVG resources embedded
or linked into an XML animation resource file.

Once that presentation code works, it will be
integrated with an existing interactive fiction
engine written in Python.

Right now, though I’m just trying to get the
display methods to work, so the code itself is
very primitive (I just started coding a little
over a week ago on it, and I still have a lot
to learn about SDL).

See:

for information. The demo I’m working on is in
the CVS, and the home page links into a description
of AutoManga on the Light Princess website (the
game for which I’m writing it).

“H?kon Skjelten” wrote:

I’m currently working on a game that is quit similar to “Prince of Persia 1/2”
when it comes to character movement & level design

  • How can I best store an character animation?
    One animated gif for walking, one for running, one for jumping…
    or should I use one large image and blit out the rects for each […]
    or should I …
  • Any advice on how to make a nice & powerful level editor? Basic
    concepts I should know about? Source code to read?

I’m not familiar with the type of game design you are working with,
but for my project I prototyped using the Xcircuit program (which
is designed for schematic drawing and capture) to layout rooms for
adventure games (it’s pretty much immaterial whether they are
text or graphic). Basically, you define “room” as if it where an
electronic component, and use the wire connections to indicate
door connections. Then, it’s possible to use the netlister (which
is design to extract electrical connections for circuit simulation)
to automatically generate an XML description of the room layout,
or code for creating it. The prototype used “XML” with no formally
specified DTD, but once we’ve designed the DTD, it should be
trivial to modify the netlister output to conform to it. There
may need to be an additional pass with an editing script to
clean the output up a bit, but basically it works.

You need a recent version of Xcircuit (>~ September 2000?)
for this to work, because some of the netlister and parameter
code that I use wasn’t working before that.

If anyone take the time to share some ideas it would be great!

Likewise!

Terry–
Terry Hancock
@Terry_Hancock