SDL & loading sprites

Started by
2 comments, last by Gage64 17 years, 1 month ago
Hi again, as the topic states i'm having some problems loading sprites in SDL. I've been through this tutorial: http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/tut3 But i already have a spritebase and sprite file that I would like to use. They will contain my sprite images for my units different "sides" as they move around the map. (i.e. left, right etc.) Parts of my engine file for loading sprites is as follows: int engine::loadSprites(char *filename, std::vector<sprite *> &theSprite, std::vector<spriteBase *> &spriteBase, SDL_Surface *screen) { int x; int y; int w; int h; int base; int count = theSprite.size(); FILE *fp; char buffer[255]; if((fp=fopen(filename, "r")) == NULL) { printf("Error opening file %s\n", filename); return -1; } while(!feof(fp)) { fgets(buffer, 255, fp); sscanf(buffer, "SPRITE: %d %d %d %d %d", &base, &x, &y, &w, &h); if((w > 0) && (h > 0)){ theSprite.push_back(new sprite); theSprite[count]->initSprite(spriteBase[base], screen, x, y, w, h); count++; } } fclose(fp); return 0; } int engine::loadBaseList(char *filename, std::vector<spriteBase *> &base) { FILE *fp; char buffer[255]; char file[255]; int count = base.size(); if((fp=fopen(filename, "r")) == NULL) { printf("Error opening file %s\n", filename); return -1; } while(!feof(fp)) { fgets(buffer, 255, fp); sscanf(buffer, "BASE: %s", &file); base.push_back(new spriteBase); loadBase(file, base[count]); count++; } return 0; } These are the two functions im concerned with. Basically i'm attempting to load a building at the start of a level so i can use it as a start point where i will be able to select it and build additional units. I have included the following lines in main to attempt to load the building files: //Vector of buildings vector<sprite *> basebuilding; vector<spriteBase *> baseBase; //building Sprites theEngine->loadBaseList("data/maps/base/basebuilding.base", baseBase); theEngine->loadSprites("data/maps/level0.building", basebuilding, baseBase, screen); With basebuilding.base showing: BASEBUILDING: data/images/buildings/basebuilding.png 72 152 72 and I also have a file called level0.building which reads: SPRITE: 100 100 17 24 data/images/buildings/basebuilding.data and the file basebuilding.data reading: MV: W 100 MV: E 100 These files were duplicated from an already present "orc" enemy sprite that patrols around the map at a set location. Everytime i run the program i get one of those "***.exe has encountered an error....send report etc." and when i comment out the lines of theEngine.. it runs fine again. Do i need 2 define a method in my engine class specifically for this basebuilding sprite ? I'm quite new to this sprite mapping stuff and i'm working off an existing implementation as part of a project i'm doing. Any insight would be greatly appreciated, Sykth
Advertisement
Maybe theEngine is NULL? Have you tried commenting out just one of the two calls to see if it crashes on just one of them? Have you used the debugger?
Yea if i comment out theEngine parts that load the buildingbase bits i pasted up it loads all the rest of the sprites ok.

It seems to just have a problem with this basebuilding i created! its saved as a .png file the same as the other ones.
But have you tried commenting out just ONE of the two functions? will it still crash if one or the other is called? are you sure that theEngine isn't NULL (I already asked this but you didn't really give an answer...)

Also, go through it with the debugger and figure out what line causes the crash.

This topic is closed to new replies.

Advertisement