Jump to content
  • Advertisement
Sign in to follow this  
ostamo1

SDL how do i load all tiles from 1 bitmap

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

I am learning SDL from the book Focus on SDL and i would like to know how would i go about loading tile images from one bitmap the images are 32x32 Are there any resources you can point me to for that subject ????

Share this post


Link to post
Share on other sites
Advertisement
Yes there is, on Cone3D's Lesson6 they have this function:


// Blit a portion of an image on the screen surface
void DrawIMG(SDL_Surface *img, int x, int y,
int w, int h, int x2, int y2)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_Rect dest2;
dest2.x = x2;
dest2.y = y2;
dest2.w = w;
dest2.h = h;
SDL_BlitSurface(img, &dest2, screen, &dest);
}




Basically it will do what you need it to. You specify the large bitmap as your img parameter, then X,Y is the location where you want to blit to on your screen surface (screen in the last statement). W,H are the width and height of your desired rect, in your case, 32 for both. Then finally X2,Y2 are the offset to begin at to extract your new smaller surface.

The tutorial shows it in use if you need an example, other than that, that's all there is to it! Good luck! [smile]

Share this post


Link to post
Share on other sites
This is what I'm using:
SDL_Rect source;
source.x = m_TileX * m_TileWidth;
source.y = m_TileY * m_TileHeight;
source.w = m_TileWidth;
source.h = m_TileHeight;

SDL_Rect dest;
dest.x = (int)m_x - m_TileWidth/2;
dest.y = (int)m_y - m_TileHeight/2;

SDL_BlitSurface(pImageSource, &source, System::Screen, &dest);
As you can see, I have some private variables (m_TileX, m_TileHeight, etc). You'll probably be able to decypher what they mean just by reading them.

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!