[SDL] Best way to rotate a sprite?
chris at luethy.net
Sun Jan 26 15:07:01 PST 2003
This is something I have to do in my game right now, software-based
SDL_Surface rotation. SDL_gfx has a pretty fast method of rotating. If
you're into the math of it, you can take your hand at writing a
Bresenham-line based method of rotating, which from what I read is the
fastest way to do it. Anyway, I do have a GPL-licensed function that
from my testing and the testing of a friend works a little faster than
SDL_gfx and any other software-based solution I could find. If you want
to check it out:
it's the SDL_Surface *rotate( SDL_Surface *s, float ang ); function in
that file. But yeah, I agree with everybody else, you should cache all
the rotations you'll need or use hardware accelerated rotations.
On Sun, 2003-01-26 at 10:34, Tane Piper wrote:
> Hey everyone,
> At the moment, I am using a rather dodgy control method in my game
> where the direction button changes the sprite on screen to face that
> direction, but each direction has its own bitmap:
> Up button loads bitmap 0,
> Right button load bitmap 1, etc.
> What I want to do is change this so there is only one bitmap needed
> for the sprite and the buttons rotate the sprite, or make it go
> backwards or forwards along the angle it's facing - the same control
> system used in the original Grand Theft Auto. I don't see anything in
> the SDL docs that directly allow you to control the rotation of a
> SDL_surface (and from this I can do the forward and backward motion
> along the vector of the sprite direction). Is there any libraries
> that allow you to do this directly to the surface, or can anybody help
> with code for this problem?
> Tane Piper: http://tane.cream.org
Chris Thielen <chris at luethy.net>
More information about the SDL