My sprites don't show up after converting project from C to C++

I recently converted my project from C to C++ because I feel more
comfortable working with OOP than C. I think I’ve correctly converted
the code, but my sprites don’t show up now. They did show up when the
project was in C. The source code is a bit long to post into an email,
so I’ve posted it to my webspace. Here’s the link:

http://www.espersunited.com/~michael/needhelp.txt

Please help me! Thank you!
-Michael Sullivan-

Maybe I should give you a little code to go on in an email. Trimmed, of
course:

#ifndef BATTLE_H
#define BATTLE_H

#include <SDL/SDL.h>
#include “SDL/SDL_ttf.h”
#include “character.h”

SDL_Surface *screen, *image[4], *status[4];
SDL_Rect src[4], dest[4];
Uint32 colorkey;
TTF_Font *font;

battle.h:

class battle
{
public:
void loadImage(int index, char* filename);
SDL_Surface *screen, *image[4], *status[4];
SDL_Rect src[4], dest[4];
Uint32 colorkey;
TTF_Font *font;
};
#endif

battle.cpp:

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_gfxPrimitives.h>
#include “battle.h”
#include “character.h”

int i;

void battle::loadImage(int index, char* filename)
{
image[index] = IMG_Load(filename);
if (image[index] == NULL)
{
printf(“Unable to load image %s: %s\n”, filename,
SDL_GetError());
}

colorkey = SDL_MapRGB(image[index]->format, 0, 255, 0);
SDL_SetColorKey(image[index], SDL_SRCCOLORKEY, colorkey);

src[index].x = 0;
src[index].y = 0;
src[index].w = image[index]->w;
src[index].h = image[index]->h;

dest[index].x = 600;
dest[index].y = index * 100;
dest[index].w = image[index]->w;
dest[index].h = image[index]->h;
}

int main()
{
battle mybattle = battle();

for (i = 0; i < 4; i++)
{
mybattle.party[i].setX(600);
mybattle.party[i].setY(i * 100);
}
i = 0;
/Draw the allies/
mybattle.loadImage(i++, “ffight.gif”);
mybattle.loadImage(i++, “tfight.gif”);
mybattle.loadImage(i++, “wmfight.gif”);
mybattle.loadImage(i, “bmfight.gif”);

for (i = 0; i < 4; i++)
{
SDL_BlitSurface(mybattle.image[i], &mybattle.src[i],
mybattle.screen, &mybattle.dest[i]);
}

The full code is at http://www.espersunited.com/~michael/needhelp.txt if
there’s anything relevant to this problem that’s not listed here…

/Draw the enemies/

/Draw the battle screen lines/
drawLines();

SDL_Delay(10000);

for (i = 0; i < 4; i++)
{
SDL_FreeSurface(image[i]);
SDL_FreeSurface(status[i]);
}

return 0;
}On Tue, 2007-11-27 at 16:06 -0600, Michael Sullivan wrote:

I recently converted my project from C to C++ because I feel more
comfortable working with OOP than C. I think I’ve correctly converted
the code, but my sprites don’t show up now. They did show up when the
project was in C. The source code is a bit long to post into an email,
so I’ve posted it to my webspace. Here’s the link:

http://www.espersunited.com/~michael/needhelp.txt

Please help me! Thank you!
-Michael Sullivan-

I would certainly remove the globals above the Battle class. They can
only confuse you (at any time, are you referring to battle::screen or
::screen?). See if your code works without the globals.

To clarify, I am talking about these:
// …
SDL_Surface *screen, *image[4], *status[4];
SDL_Rect src[4], dest[4];
Uint32 colorkey;
TTF_Font *font;

class battle {
// …

Michael Sullivan wrote:> On Tue, 2007-11-27 at 16:06 -0600, Michael Sullivan wrote:

I recently converted my project from C to C++ because I feel more
comfortable working with OOP than C. I think I’ve correctly converted
the code, but my sprites don’t show up now. They did show up when the
project was in C. The source code is a bit long to post into an email,
so I’ve posted it to my webspace. Here’s the link:

http://www.espersunited.com/~michael/needhelp.txt

I don’t see anywhere before the Delay() call a SDL_Flip() or
SDL_UpdateRects() call, you need it to display your blits on screen, SDL
uses a shadow buffer also if you are working without double buffering or
windowed.

Bye,
Gabry

I don’t see anywhere before the Delay() call a SDL_Flip() or
SDL_UpdateRects() call, you need it to display your blits on screen, SDL
uses a shadow buffer also if you are working without double buffering or
windowed.

There is an SDL_UpdateRects() in the Drawlines function called right before
SDL_Delay, so I don’t think that’s the issue. However, I’m wondering 2
things… In moving your project to c++, have you changed any of the folder
structure, so that your sprite images are now no longer loading
correctly(i.e. no longer in the same folder as the executable)? And second,
Do you at least see the lines that are drawn by the Drawlines function? If
so, then I’m guessing that your sprites simply aren’t loading correctly.
Make sure that your battle::loadImage() call has some kind of error
checking, and that it reports to you if the file loaded or not(so it isn’t
just silently failing.)
Good luck!
-Dave

----- Original Message -----
From: gabriele.greco@darts.it (Gabriele Greco)