I have a class that uses a reference to sfRenderWindow to render a sprite from a map container. The code compiles and runs fine but won't show the sprite. My code is as follows.
class imageHandler : public Unpacker
{
map<string, sfImage*> imageList;
map<string, sfSprite*> spriteList;
public:
sfRenderWindow* screen;
imageHandler();
~imageHandler();
void setScreen(sfRenderWindow*& screens);
void addImage( string imageName );
void setAlpha( string name, int alpha );
void clearImages();
void surfApp( int x, int y, string imageName );
void surfApp( int X, int Y, string Name, sfIntRect aniRect);
int imageW( string pFilename );
int imageH( string pFilename );
};
#include "ImageHandling.h"
imageHandler::imageHandler(){
int count = 1;
int i;
sfImage** imageList;
sfSprite** spriteList;
}
imageHandler::~imageHandler(){
}
void imageHandler::setScreen(sfRenderWindow*& screens) {
screen = screens;
}
void imageHandler::addImage( string imageName)
{
sfImage* image;
map<string, sfImage*>::iterator i = imageList.find( imageName );
map<string, sfSprite*>::iterator p = spriteList.find( imageName );
if( i == imageList.end() )
{
image = loadImageFromRes("data.pck", imageName.c_str());
i = imageList.insert( i, make_pair( imageName, image ) );
}
if( p == spriteList.end() )
{
sfSprite* sprite = sfSprite_Create();
sfSprite_SetImage( sprite, image );
p = spriteList.insert(p, make_pair( imageName, sprite ) );
}
}
void imageHandler::setAlpha( string name, int alpha )
{
sfColor alphaAdjust;
alphaAdjust.r = 255;
alphaAdjust.g = 255;
alphaAdjust.b = 255;
alphaAdjust.a = alpha;
map<string, sfSprite*>::iterator a = spriteList.find( name );
if( a != spriteList.end() )
{
sfSprite_SetColor( a -> second, alphaAdjust );
}
}
void imageHandler::surfApp( int x, int y, string imageName )
{
map<string, sfSprite*>::iterator p = spriteList.find( imageName );
if( p != spriteList.end() )
{
sfSprite_Move( p -> second, x, y );
sfRenderWindow_DrawSprite( screen, p -> second );
}
}
void imageHandler::surfApp( int X, int Y, string Name, sfIntRect aniRect)
{
map<string, sfSprite*>::iterator p = spriteList.find( Name );
if( p != spriteList.end() )
{
sfSprite_Move(p -> second, X, Y );
sfSprite_SetSubRect( p -> second, aniRect );
sfRenderWindow_DrawSprite( screen, p -> second );
}
};
int imageHandler::imageW(string pFilename)
{
int result;
map<string, sfImage*>::iterator p = imageList.find( pFilename );
if( p != imageList.end() )
{
result = sfImage_GetWidth( p -> second );
}
return result;
}
int imageHandler::imageH(string pFilename)
{
int result;
map<string, sfImage*>::iterator p = imageList.find( pFilename );
if( p != imageList.end() )
{
result = sfImage_GetHeight( p -> second );
}
return result;
}
main.cpp
#include "Engine.h"
int addButtonX = 40;
int addButtonY = 40;
sfEvent eventHolder;
int addAniX, addAniY = 25;
int dirX=1;
int dirY=4;
bool quit = false;
bool downupDown = true;
bool downupLeft = true;
bool downupRight = true;
int main(int argc, char* args[])
{
imageHandler images;
Events myEvents;
Timer fps;
images.addImage("logo.png");
sfVideoMode videoParams;
videoParams.Width = 640;
videoParams.Height = 480;
sfWindowSettings sfSettings;
sfSettings.AntialiasingLevel = 0;
sfSettings.DepthBits = 32;
sfSettings.StencilBits = 0;
videoParams.BitsPerPixel = 32;
sfColor colorBlue;
colorBlue.r = 0;
colorBlue.g = 0;
colorBlue.b = 255;
sfRenderWindow* App = sfRenderWindow_Create( videoParams, "Window Test", sfTitlebar | sfClose, sfSettings );
while( sfRenderWindow_IsOpened( App ) )
{
fps.startTimer();
images.setScreen(App);
myEvents.eventStruct( eventHolder );
while(sfRenderWindow_GetEvent( App, &eventHolder ))
{
if( eventHolder.Type == sfEvtClosed )
{
sfRenderWindow_Close( App );
}
if( eventHolder.Key.Type == sfEvtKeyPressed )
{
if( eventHolder.Key.Code == sfKeyNum0 )
{
cout << "Zero pressed" << endl;
}
if( eventHolder.Key.Code == sfKeyA )
{
cout << "A key pressed" << endl;
}
if( eventHolder.Key.Code == sfKeyEscape )
{
cout << "Esc key pressed" << endl;
}
}
if( myEvents.keyUp("j") == true )
{
cout << "J key pressed" << endl;
}
}
if( downupDown == false )
{
addButtonY += 10;
}
images.surfApp( addButtonX, addButtonY, "logo.png" );
sfRenderWindow_Clear( App, colorBlue );
sfRenderWindow_Display( App );
}
return 0;
}