0
我有一個應用程序,我使用PugiXML將XML代碼解析爲具有紋理的精靈。但是,我遇到了一個for
循環工作的問題,因爲編譯器在循環過程中不斷返回Expression: vector iterators incompatible
運行時錯誤,正當initCollisionObject
啓動時。任何幫助將不勝感激!C++ PugiXML向量迭代器不兼容錯誤
for
循環:
for (xml_node collisions = doc.child("level").child("collisions").child("object"); collisions; collisions = collisions.next_sibling("object"))
{
xml_attribute textureAttribute = collisions.attribute("spritesheet");
xml_attribute xPosAttribute = collisions.attribute("x");
xml_attribute yPosAttribute = collisions.attribute("y");
xml_attribute rotationAttribute = collisions.attribute("rotation");
std::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++;
}
initCollisionObject
功能:
void CollisionObject::initCollisionObject(std::string fileName, b2World &_world, float objectX, float objectY, float objectRotation)
{
collisionObjectSpriteImage.loadFromFile(fileName);
//spriteImage.createMaskFromColor(sf::Color::White);
collisionObjectSpriteTexture.loadFromImage(collisionObjectSpriteImage);
collisionObjectSprite.setTexture(collisionObjectSpriteTexture);
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;
}