Sign in to follow this  
ostamo1

SDL how do i load all tiles from 1 bitmap

Recommended Posts

ostamo1    128
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
Drew_Benton    1861
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
Rob Loach    1504
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this