Jump to content
  • Advertisement
Sign in to follow this  
walle

Making surface from big surface [SDL]

This topic is 4821 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

Hello. Iv'e heard that it's better to use only one file for your sprites instead of the way cone 3d (where I learned SDL) do. But it has to be more dificult to edit the sprites? With that information I thought that I would layout my sprite files this way: |Frame #1 of animation #1||Frame #2 of animation #1|...etc. |Frame #1 of animation #2||Frame #2 of animation #2|...etc. In words, every sprite can have multiple animations, each row contains a new animation. and the animations can have a different amount of frames, each column in a row is a frame... But now I don't know how to take each frame and put it in the animation vector...and how do I detect if the image has anoter animation? Do I check for a different color with SDL_GetPixel()? In that case I would apprechiate a explanation on how to use it...becuse I've never used it... And finally, what do you think about the layout? //walle

Share this post


Link to post
Share on other sites
Advertisement
You can find out how many tiles there are in the image by dividing the image's width by the width of each tile. So if each tile is 32 pixels wide, you'd take the SDL_Surface.w and divide it by 32 and that's how many tiles there are.

This is what I'm using:

// Get the source picture (the frame)
SDL_Rect source;
source.x = m_TileX * m_TileWidth;
source.y = m_TileY * m_TileHeight;
source.w = m_TileWidth; source.h = m_TileHeight;

// Find out where it's going to draw it on the screen
SDL_Rect dest;
dest.x = (int)m_x - m_TileWidth/2;
dest.y = (int)m_y - m_TileHeight/2;

// Draw it
SDL_BlitSurface(pImageSource, &source, System::Screen, &dest);

It's part of my sprite class so there are some variable names you're going to have to decypher there.

Share this post


Link to post
Share on other sites
Ok, lets see if I get this...

Your sprites don't have a own SDL_Surface*?
You just load in the whole image and decide wich part to draw at wich place?
What happens with animations if you have multiple instances of the sprite?

And this I don't understand really:

// Find out where it's going to draw it on the screen
SDL_Rect dest;
dest.x = (int)m_x - m_TileWidth/2;
dest.y = (int)m_y - m_TileHeight/2;




Do you set the destination to half the tile width/height to the left and up from your sprites x/y values?

//walle

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!