Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem using Images and Sprites from within a class  (Read 1604 times)

0 Members and 1 Guest are viewing this topic.

Scipi

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Problem using Images and Sprites from within a class
« on: July 26, 2011, 06:54:12 am »
Hello, I am trying to display sprites inside a class function to display to the screen. However I am getting nothing but a wall of white. Here's my code:

Code: [Select]

class Game
{
public:

        sf::RenderWindow App;
        sf::View View;
        vector <sf::Sprite> SpriteFiles;
        vector <int> MapData;
        vector <int> CollisionData;
        vector <int> TransitionData;
vector <sf::Image> ImageFiles;
void Setup();
        void LoadMap(string);//Map to load ID
void Display();

        //void Setup();
        void MainMenu();
        void GetEvents();

        void LevelUp(string, int*);//Daemon name, pointer to Daemon stats array

//Game();
//~Game();
private:
bool FilesExist;


int MapWidth, MapHeight, ScreenWidth, ScreenHeight, PosX, PosY;
};


^ The class sf::Sprite and sf::Image are initialized in

Code: [Select]

void Game::Setup()
{
App.Create(sf::VideoMode(1024, 768), "Daemons");

App.UseVerticalSync(true);//Clearer graphics ftw

//sf::View View(sf::FloatRect(0,0,1024,768));
    View.SetFromRect(sf::FloatRect(0,0,1024,768));
App.SetView(View);//Sets up the view. So you can see stuff
App.SetFramerateLimit(60);

FilesExist = true;
int ImageNum = 0;
ScreenWidth = 17;
ScreenHeight = 13;
PosX = -1;
PosY = -1;
stringstream PictureName;

for(ImageNum = 0; ImageNum < 10; ImageNum++)
    {

        PictureName << "data/images/map/" << ImageNum << ".png";

ImageFiles.resize(ImageNum + 1);
SpriteFiles.resize(ImageNum + 1);


        if(ImageFiles[ImageNum].LoadFromFile(PictureName.str().c_str()))
        {
            ImageFiles[ImageNum].SetSmooth(false);
            SpriteFiles[ImageNum].SetImage(ImageFiles[ImageNum]);
        }
cout << "\n" << PictureName.str().c_str() << "\n";
PictureName.str(string());
       

    }

return;
}



////////////////////
//DISPLAY
////////////////////
void Game::Display()
{
try
{
        App.Clear();
        for (int y=PosY; y<ScreenHeight; y++)
            {
                for (int x=PosX; x<ScreenWidth; x++)
                {
                    if ((y >= 0 && x >= 0) && (y <= ScreenHeight && x <= ScreenWidth))
                    {
                        if (MapData[x + (y * MapWidth)] == -1)
                            continue;
                        int holder = MapData[x + (y * MapWidth)];
                        SpriteFiles[holder].SetPosition(x * 64, y * 64);

                        //cout << holder;
                        App.Draw(SpriteFiles[holder]);
                    }
                }

            }
        App.Display();
}
catch(exception& e)
{
   cout << e.what() << "\n";
}
return;
}


^Where they are used

So what exactly is causing the images to not display correctly and how can I fix it?

Thanks.
I issa Cat Person =^w^=

Scipi

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Problem using Images and Sprites from within a class
« Reply #1 on: July 26, 2011, 06:08:11 pm »
Disregard, I found out what was wrong.

It was when I was resizing the sf::Image and sf::Sprite vectors and it was breaking the pointers.
I issa Cat Person =^w^=

 

anything