我有一个应用程序,我使用PugiXML将XML代码解析为带有纹理的sprite。但是,我遇到了使这一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;
}
答案 0 :(得分:0)
这听起来很荒谬,但重启计算机实际上解决了这个问题......