I sent this question in awhile ago and nobody said anything about it.
I’ll try again. This time with links to screenshots. My program runs;
it displays most sprites correctly, but one it doesn’t display
correctly. Can you guess which one?
The second sprite from the top on the right side is displayed almost as
if it’s overexposed by light. Here’s what it’s supposed to look like:
This is the actual file I’m using for the sprite. It’s supposed to have
a transparent background and indeed in eog and gimp it does. But it
doesn’t display correctly in my program, as you can see.
Here’s my the relevent (AFAIK) snippets of my code:
void drawBattle::loadImage(int index, string filename, bool polarity)
{
if (polarity == true) //It’s an ally
{
aparty[index].loadImage(filename);
cout << "Got to line drawBattle.cpp:198" << endl;
this->aimage[index] = aparty[index].getImage();
Uint32 colorkey = SDL_MapRGB(aimage[index]->format, 0, 255, 0);
SDL_SetColorKey(aimage[index], SDL_SRCCOLORKEY, colorkey);
cout << "Got to drawBattle.cpp:205" << endl;
asrc[index].x = 0;
asrc[index].y = 0;
asrc[index].w = this->aimage[index]->w;
asrc[index].h = this->aimage[index]->h;
cout << "Got to drawBattle.cpp:212" << endl;
aparty[index].setRect(asrc[index]);
cout << "Got to drawBattle.cpp:216" << endl;
adest[index].x = 600;
adest[index].y = index * 100;
adest[index].w = this->aimage[index]->w;
adest[index].h = this->aimage[index]->h;
cout << "Got to drawBattle.cpp:222" << endl;
}
else //Must be an enemy…
{
//Add in later the code to access the enemyParty info…
eparty[index].loadImage(filename);
this->eimage[index] = eparty[index].getImage();
colorkey = SDL_MapRGB(eimage[index]->format, 0, 0, 255);
SDL_SetColorKey(eimage[index], SDL_SRCCOLORKEY, colorkey);
esrc[index].x = 0;
esrc[index].y = 0;
esrc[index].w = this->eimage[index]->w;
esrc[index].h = this->eimage[index]->h;
eparty[index].setRect(esrc[index]);
edest[index].x = 0;
edest[index].y = index * 100;
edest[index].w = this->eimage[index]->w;
edest[index].h = this->eimage[index]->h;
}
}
aparty and eparty are arrays of Characters, which load there images from
here:
bool Character::loadImage(string f)
{
int i;
int size = f.size() + 1;
const char* temp = f.c_str();
cout << “Got to line character.cpp:51” << endl;
printf(“filename = %s\n”, temp);
if (temp != NULL)
{
image = IMG_Load(temp);
if (image == NULL)
{
printf(“Unable to load image %s: %s\n”, temp, SDL_GetError());
return false;
}
}
// delete temp;
return true;
}
Now will anyone tell me what the heck is going on with my one rogue sprite?