Public Group

Making surface from big surface [SDL]

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

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 on other sites
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 screenSDL_Rect dest;dest.x = (int)m_x - m_TileWidth/2;dest.y = (int)m_y - m_TileHeight/2;// Draw itSDL_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 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 screenSDL_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

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 34
• 16
• 11
• 10
• Forum Statistics

• Total Topics
634122
• Total Posts
3015642
×