What if I have two images loaded in different sf::image objects and you want to display one image or another depending of the situation?
I mean, I have a class named character and I need a method to change the image to display. I was trying something like this:
( in main() )
sf::image *img1 = new sf::image();
sf::image *img2 = new sf::image();
img1->loadfromfile("img1.png");
img2->loadfromfile("img2.png");
sprite->setimage(*img1);
Character *character = new Character(*img1);
/* in the class I do image = img1, where "image" is sf::image *image; */
and later in the game I need to change the sf::image of the character, then I do something like
character->setimage(*img2);
/* in the class i tried this:
delete image;
image = img2;
sprite->setimage(*image);*/
and trows and exception.
What is wrong? How can I do that in the right way?
Thanks.