🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
(SDL) Rotating Surfaces
Not with just the base SDL library, but there's probably and auxiliary library that will. I looked around, SDL_gfx seems like what you want.
I looked at that and read the documentation, and I have one more question. Say I already have a surface I want to rotate, the documentation seems to say that you have to rotate the surface when you initialize it.
Quote: SDL_Surface * rotozoomSurface (SDL_Surface *src, double angle, double zoom, int smooth);
Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface.
'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1
then the destination 32bit surface is anti-aliased. If the surface is not 8bit
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
That function creates a new surface from the surface src that is rotated and zoomed by the amounts specified. You just use it like this
Note the SDL_FreeSurface at the end, rotozoomsurface creates a new surface every time and thus you need to free it once you're done with the rotated surface (prehaps you should crate a new one and free the old one every time the sprites rotation angle changes, rather than every frame so it runs faster).
The smooth argument at the end just specifies wheather you want it to by anti-aliased, which will make things look nicer, but it'll slow things down.
SDL_Surface* Sprite = SDL_LoadBMP("Sprite.bmp");....SDL_Surface* RotatedSprite = rotozoomsurface(Sprite, 45.0, 0.0, 1);DrawSprite(RotatedSprite);SDL_FreeSurface(RotatedSprite);
Note the SDL_FreeSurface at the end, rotozoomsurface creates a new surface every time and thus you need to free it once you're done with the rotated surface (prehaps you should crate a new one and free the old one every time the sprites rotation angle changes, rather than every frame so it runs faster).
The smooth argument at the end just specifies wheather you want it to by anti-aliased, which will make things look nicer, but it'll slow things down.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement