Sorry for not being clear but I was actually storing the parameter to an attribute.
Npc.cpp
Npc::Npc(int x, int y,int gid, std::string location)
{
Npc::x = x;
Npc::y = y;
Npc::location = location;
Npc::gid = gid;
Npc::texture1.loadFromFile(Npc::location);
Npc::sprite1.setTexture(texture1);
}
TileMap.cpp
while(count >= 0)
{
if(atoi(attr->value()) >= locations[count].gid)
{
Npc temp(j,i,atoi(attr->value()) -
locations[count].gid, locations[count].location);
Npcs.push_back(temp);
break;
}
count--;
}
//I omitted alot of code but basically its just loops that take data from file. Then creating and storing each npc's position, image path etc inside the vector.
Main.cpp
int main()
{
TileMap t;
Player p;
//inside the game loop draws the tiles
for(int q = 0; q < t.Npcs.size(); q++)
{
//t.Npcs[q].sprite1.setTexture(t.Npcs[q].texture1);
t.Npcs[q].sprite1.setPosition(t.Npcs[q].getX()*32,t.Npcs[q].getY()*32);
t.Npcs[q].sprite1.setTextureRect(IntRect(0,0,32,48));
window.draw(t.Npcs[q].sprite1);
}
p.sprite.setTextureRect(IntRect(p.source.x%4*p.width,p.source.y*p.height,p.width,p.height));
window.draw(p.sprite);
window.display();
//above cove: draws the npc to screen and then draw the character.
*EDIT: Although it works if I add that commented out line t.Npcs[q].sprite1.setTexture(t.Npcs[q].texture1). I am not sure if that is a good way to do this because it will need to set the texture for every iteration in the loop.