我正在为我的pcg游戏进行城市生成。我有一个循环,这使得3个城市的随机位置,我给你parentIteration
得到那个“ID”为城市做同样的for
圈,我做出一个建筑Ogre3d具有独特的节点名称错误
for (int i = 0; i < 3; i++)
{
parentIteration = i;
std::srand(i);
_rootNode = GameManager::getSingletonPtr()->getSceneManager()->getRootSceneNode();
_cityNode = _rootNode->createChildSceneNode("cityNode " + parentIteration);
generateCity(std::rand() % 10000 + 10, std::rand() % 10000 + 10, std::rand() % 11 +1);
}
建设
for (int i = 0; i < _numberOfBuildings; i++)
{
childIteration = i;
printf(" parent %d and child %d \n", parentIteration, childIteration);
Ogre::SceneNode* buildingNode = _cityNode->createChildSceneNode("citybuildingNode"+childIteration+parentIteration);
}
但是,当我尝试启动游戏时,它会在创建第二个城市时崩溃。说它已经有一个类似于它试图写的名字。然而我的printf
清楚地表明,那时的数字都是独一无二的。任何人都知道如何解决这个问题? (输出证明添加图片)
你确定''citybuildingNode“+ childIteration + parentIteration'是否符合你的想法?因为我认为你打算做一个字符串连接而不是指针算术。 'std :: string(“citybuildingNode”)+ childIteration + parentIteration'似乎更合适 – PeterT
'cityNode = _rootNode-> createChildSceneNode(“cityNode”+ parentIteration);' - 我不知道'Ogre',重新传球 - 预期的实际类型是什么?你正在添加一个字符串文字和一个“int”。这不会像预期的那样工作,除非有一些我不知道的魔法。 – PaulMcKenzie
[可能的重复](http://stackoverflow.com/questions/191757/how-to-concatenate-a-stdstring-and-an-int)。这可能是你的问题归结为什么。 C++不像其他语言那样使用字符串文字。你不能只是将一个数字连接到一个文字上,并得到一个你期望的字符串。 – PaulMcKenzie