• Advertisement
Sign in to follow this  

SDL Problem

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

Hi I'm having a problem with SDL. I do this in allegro but am a little confused about how SDL does it. I have a bmp file that has 32x32 shapes in it. I want to seperate those shapes in to an array. In Allegro I do this: void LoadSpriteSheet32x32 (char* szFilename, int iROWS, int iCOLS) { temp_sprite_storage = load_bitmap(szFilename, NULL); int indexy = 0, indexx = 0, ripx = 0, ripy = 0, counter = 0; if (temp_sprite_storage == NULL) { alert("Loading Sprite","Failed","","OK",NULL,KEY_ENTER,KEY_ESC); allegro_exit(); } //int TILEHEIGHT = 32; //int TILEWIDTH = 32; for (indexy = 0; indexy != iROWS+1;++indexy) { for (indexx = 0; indexx != iCOLS+1; ++indexx) { ripx = indexx * TILEHEIGHT; // account for 1 pixel borders ripy = indexy * TILEWIDTH; spriteset[counter] = create_bitmap(TILEHEIGHT, TILEWIDTH); blit(temp_sprite_storage, spriteset[counter], ripx, ripy, 0, 0, TILEHEIGHT, TILEWIDTH); counter++; } } destroy_bitmap(temp_sprite_storage); But in SDL I want to do this: int InitImages() { back = SDL_LoadBMP("Sewers.bmp"); image = SDL_LoadBMP("enemy1.bmp"); return 0; } void DrawIMG(SDL_Surface *img, int x, int y) { SDL_Rect dest; dest.x = x; dest.y = y; SDL_BlitSurface(spriteset[0], NULL, screen, &dest); } void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2) { // * Img is back // x and y is start position // w and h and width and height 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, spriteset[0], &dest); void DrawBG() { //DrawIMG(back, 0, 0); } int DrawScene() { DrawIMG(back, xpos, ypos, 32, 32, xpos, ypos); //SDL_Flip(screen); } But I'm not sure if spritetset[0] is the 1st block, when I chnage spriteset[0] to screen I do see the 32x32 block on the upper left. can anyone help? Fud

Share this post


Link to post
Share on other sites
Advertisement
huh?

x2, y2 DrawIMG represents the upper-left starting coordinates of the image IN the file. While x and y represents the starting blitting coordinates of the image on the surface/screen.

Share this post


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

  • Advertisement