[SDL] Best way to rotate a sprite?

Tane Piper tane.piper at ukonline.co.uk
Sun Jan 26 14:29:01 PST 2003

>There are a few solutions for this, but there are some things I think
>you should consider first:

>* Rotating surfaces is *expensive*, unless you do it in
>  hardware - and SDL doesn't support that. (Nor does glSDL,
>  BTW, as it's not part of the SDL API.)
>* Rotating in software is doable, but gets *very* expensive
>  if you want to do it with reasonable image quality.
>  (Linear interpolation is a minimum requirement, IMHO.)

Really?  This is a pity, because I want my game to run on min specs (166,
32mb ram).  I wonder if we are on the same "level" because I have seen what
I want done before quite easily in games like Grand Theft Auto and Micro
Machines.  Basicly when I press the Up arrow, I want the vehicle to travel
along the vector it is facing, accelerating, and when you press the Left
arrow it starts to turn left (both the sprite and the vector it is traveling
along) until the player lets go the button.  Keep holding it down, and the
car will just spin and spin.

>* Just rotating a sprite won't change the lighting of the
>  image (obviously), so unless the sprite is created with
>  the ligh right from top (rather unusual), it will look
>  plain wrong.
>If you don't cane about "realistic" ligthing, I'd recommend you grab
>SGE or some other lib (I'm too lazy to find the URLs for you right
>now ;-) and do the rotation load time, creating an array of surfaces
>indexed by the direction of the object. This is fast and simple, and
>lets you test different numbers of images very easilly.
>Later on, you can either ditch the rotation code and load a set of
>prerendered images, or combine the methods; have 8 or 16 prerendered
>images with correct lighting, and rotate at load time to generate
>intermediate images if you want more.

I do kind of care about lighting, but I don't want to have pre-rendered turn
sequences, or 4-8 direction sprites I interpolate between, because the car
needs to be able to travel in any direction on a 360-degree turning circle.
Also, there will be more than just car vehicles, there will be bikes, boats,
planes - and I don't want to have a lot of resources.  Also, I want to have
people be able to add their own vehicles, so I don't want too much work for
people to do.  As I said, I've seen many other games do this, so there has
to be a simple way to do it, it's probably staring me right in the face.

Tane Piper

More information about the SDL mailing list