For the past week I've been trying to assign specific textures to sprites in a vector array via a for loop, with both elements being called from a XML file using PugiXML. With my current code, every sprite except for the last one within the vector array appears to have a white texture incorrectly assigned to it, with only the last one within the vector array having the correct texture assigned to it.
So far, I don't see any flaws within my code, which is confusing me. If anyone happens to see an error that I don't, a reply would be greatly appreciated.
initCollisionObject Function:
void CollisionObject::initCollisionObject(std::string fileName, b2World &_world, float objectX, float objectY, float objectRotation)
{
collisionObjectString = fileName;
collisionObjectImage.loadFromFile(collisionObjectString);
collisionObjectTexture.loadFromImage(collisionObjectImage);
collisionObjectSprite.setTexture(collisionObjectTexture);
width = collisionObjectSprite.getGlobalBounds().width;
height = collisionObjectSprite.getGlobalBounds().height;
x = objectX;
y = objectY;
rotation = objectRotation;
collisionObjectSprite.setOrigin(collisionObjectSprite.getGlobalBounds().width / 2, collisionObjectSprite.getGlobalBounds().height / 2);
collisionObjectSprite.setPosition(x, y);
collisionObjectSprite.setRotation(rotation);
createStaticCollision(_world, x, y, width, height, rotation);
return;
}
for Loop:
for (xml_node collisions = doc.child("level").child("collisions").child("object"); collisions; collisions = collisions.next_sibling("object"))
{
//cout << "Iterated" << endl;
xml_attribute textureAttribute = collisions.attribute("spritesheet");
xml_attribute xPosAttribute = collisions.attribute("x");
xml_attribute yPosAttribute = collisions.attribute("y");
xml_attribute rotationAttribute = collisions.attribute("rotation");
string texture = textureAttribute.as_string();
int xPos = xPosAttribute.as_int();
int yPos = yPosAttribute.as_int();
int rotation = rotationAttribute.as_int();
collisionArray.push_back(collisionObject);
collisionArray[currentCollisionObjectIndex].initCollisionObject(texture, _world, xPos, yPos, rotation);
currentCollisionObjectIndex++;
}