Okay, so I'm currently making a game with paperdoll (So you see the armor and hats of the other players, depending of what they have equipped), so I thought of having all the armors with their id on different files (So the armor id0 would be 0.png, etc...) and have created a class to handle those, but weirdly, only the last armor in the vector shows, the other shows as white squares.
(The code that loads the different armor into an "Image" vector)
for (int i=0; i<m_numBody; i++)
{
Image img;
m_body.push_back(img);
m_body[i].Init("body", i);
}
(The code that calls the drawing function of the "Image" class, 'body' being the armor id)
m_body[body].Draw(App, pixelX, pixelY, direction, anim);
And then there is the Image class :
(image.h)
#ifndef IMAGE_H_INCLUDED
#define IMAGE_H_INCLUDED
#include <SFML/Graphics.hpp>
#include <string>
class Image
{
public:
void Init(std::string type, int number);
void Draw(sf::RenderWindow &App, int pixelX, int pixelY, int direction, int anim);
private:
sf::Image m_image;
sf::Sprite m_sprite;
};
#endif // IMAGE_H_INCLUDED
(image.cpp)
#include <string>
#include <sstream>
#include <iostream>
#include "image.h"
using namespace std;
void Image::Init(string type, int number)
{
// Load the sprite
ostringstream t_stream;
t_stream << "data/sprites/" << type << "/" << number << ".png";
string t_string = t_stream.str();
m_image.LoadFromFile(t_string.c_str());
m_image.SetSmooth(false);
m_image.CreateMaskFromColor(sf::Color(255, 0, 255));
m_sprite.SetImage(m_image);
}
void Image::Draw(sf::RenderWindow &App, int pixelX, int pixelY, int direction, int anim)
{
// Draw the sprite
m_sprite.SetSubRect(sf::IntRect(32*direction-32, 48*anim, 32*direction, 48*anim+48));
m_sprite.SetPosition(pixelX, pixelY);
App.Draw(m_sprite);
}
Like I said, only the last armor (I tested with different numbers) shows. So if there is 4 armors, only m_body[3].Draw(...) would work, the others, like m_body[1].Draw(...) would show a white square)
Thank you.