Jump to content
  • Advertisement
Sign in to follow this  
Diton9000

rotozoom with sprite sheet

This topic is 4909 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I use the rotozoom function from SDL_gfx with a sprite sheet? Does the source rectangle change, or can I use the x, y, w, and h values in the unrotated sheet?

Share this post


Link to post
Share on other sites
Advertisement
This is what I've done in my sprite class in the engine I was working on a while ago:


SDL_Surface* pImageTile = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCCOLORKEY, m_TileWidth, m_TileHeight, pImageSource->format->BitsPerPixel,
pImageSource->format->Rmask, pImageSource->format->Gmask, pImageSource->format->Bmask, pImageSource->format->Amask);
if(pImageTile){

SDL_Rect source;
source.x = m_TileX * m_TileWidth;
source.y = m_TileY * m_TileHeight;
source.w = m_TileWidth;
source.h = m_TileHeight;

SDL_SetAlpha(pImageSource, SDL_SRCALPHA, 255);
SDL_FillRect(pImageTile, NULL, pImageSource->format->colorkey);
SDL_BlitSurface(pImageSource, &source, pImageTile, NULL);
SDL_SetColorKey(pImageTile, SDL_SRCCOLORKEY, pImageSource->format->colorkey);
SDL_Surface* pImageOutput = rotozoomSurface(pImageTile, m_angle, m_zoom, m_smoothing);
SDL_FreeSurface(pImageTile);

if(pImageOutput){
SDL_Rect dest;
dest.x = (int)m_x - pImageOutput->w/2 - System::CameraX;
dest.y = (int)m_y - pImageOutput->h/2 - System::CameraY;

SDL_SetColorKey(pImageOutput, SDL_SRCCOLORKEY, pImageSource->format->colorkey);
SDL_SetAlpha(pImageOutput, SDL_SRCALPHA, m_alpha);
SDL_BlitSurface(pImageOutput, NULL, System::Screen, &dest);
SDL_FreeSurface(pImageOutput);
return true;
}
}


You'll probably be able to decypher what the variables are by their names.

Share this post


Link to post
Share on other sites
If I'm interpreting this right - I load the sheet into a surface, then copy one frame into another surface, then rotate it, then use trig if I want to move the rotated version at an angle.

Share this post


Link to post
Share on other sites
That's essentially what I did in that code segment.

  1. Create a new surface and put the tile onto it.
  2. Rotate the tile using rotozoomSurface.
  3. Draw rotated tile.
  4. Free up any non-needed memory.

Share this post


Link to post
Share on other sites
Warning: bad ASCII graphics ahead.


Say this is the bmp
0,0-------6,0
| |
| |
| |
0,4-------6,4

Does rotozoom make this:

0,0 /--|
| / \|
| / /|
|/ / |
/---/--|

Or this:

----/--|
| / \|
| / /|
|/ / |
0,0-/--|

Share this post


Link to post
Share on other sites
It depends on which direction you're rotating it. Since it uses degrees, it doesn't matter. Just play around with it and you'll find out. When I made the devpak for Dev-C++ for it, I provided a sample project that used SDL_gfx, take a look at it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!