我有一个应用程序,我在其中使用 PugiXML 将 XML 代码解析为带有纹理的精灵。但是,我在使这个for
循环正常工作时遇到了问题,因为编译器Expression: vector iterators incompatible
在循环期间一直返回运行时错误,就在initCollisionObject
启动时。任何帮助将不胜感激!
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;
}