(SDL) Rotating Surfaces
Is it possible to rotate a surface in SDL?
My Current Project Angels 22 (4E5)
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.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
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.
My Current Project Angels 22 (4E5)
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