List 无法从文件中将保存的值分配给列表
我们正在开发一个游戏引擎,它将包括加载精灵、音频剪辑等,所有这些都是从“Actor”抽象类扩展而来的。我们能够通过for循环遍历actor元素列表,并保存以下值: 键入x>>y>>w>>h>>td) { getType.push_back(类型); getID.推回(id); getX.向后推_(x); getY.向后推_(y); getWidth.向后推_(w); getHeight.向后推_(h); getTexDir.push_-back(td); cout setX(getX[行]); actorList->setY(getY[lines]); actorList->setWidth(getWidth[行]); actorList->setHeight(getHeight[行]); actorList->setTextureDir(getTexDir[lines]); actorList->texture2D.loadTexture(getExDir[lines]);List 无法从文件中将保存的值分配给列表,list,iteration,loading,getline,assign,List,Iteration,Loading,Getline,Assign,我们正在开发一个游戏引擎,它将包括加载精灵、音频剪辑等,所有这些都是从“Actor”抽象类扩展而来的。我们能够通过for循环遍历actor元素列表,并保存以下值: 键入x>>y>>w>>h>>td) { getType.push_back(类型); getID.推回(id); getX.向后推_(x); getY.向后推_(y); getWidth.向后推_(w); getHeight.向后推_(h); getTexDir.push_-back(td); cout setX(getX[行]);
std::cout通过添加另一个while循环并迭代来修复该解决方案
GLvoid Load::loadActor(list<Components::Actor*>::iterator it)
{
// Clear scene data
Components::Actor::actors.clear();
// Open file
std::cout << "\nOpen: ";
cin >> cinData;
inFile.open("Content/Maps/" + cinData + ".sol", std::ifstream::in);
// Iterate and add actor types to Actor::actors list
string line;
vector <int> getType;
vector <int> getID;
vector <float> getX;
vector <float> getY;
vector <float> getWidth;
vector <float> getHeight;
vector <string> getTexDir;
int lines = 0;
while (getline(inFile, line))
{
stringstream iss(line);
int type;
int id;
float x;
float y;
float w;
float h;
string td;
// Read and pack temp values in vector lists
if (iss >> type >> id >> x >> y >> w >> h >> td)
{
getType.push_back(type);
getID.push_back(id);
getX.push_back(x);
getY.push_back(y);
getWidth.push_back(w);
getHeight.push_back(h);
getTexDir.push_back(td);
cout << "All values have been read..." << endl;
}
// Reset temp values
type = 0;
id = 0;
x = 0.0f;
y = 0.0f;
w = 0.0f;
h = 0.0f;
td = "";
// Create actor types
switch(type)
{
case Components::Actor::T_SPRITE:
Components::ActorHandler::create(new Components::Sprite(true));
for ( it = Components::Actor::actors.begin(); it != Components::Actor::actors.end(); it++)
{
Components::Actor *actorList = (*it);
actorList->setID(getID[lines]);
actorList->setX(getX[lines]);
actorList->setY(getY[lines]);
actorList->setWidth(getWidth[lines]);
actorList->setHeight(getHeight[lines]);
actorList->setTextureDir(getTexDir[lines]);
actorList->texture2D.loadTexture(getTexDir[lines]);
std::cout << "Type: " << actorList->getType() << " ID: " << actorList->getID() << " X pos: " << actorList->getX() << " Y pos: " << actorList->getY() << " Width: " << actorList->getWidth() << " Height: " << actorList->getHeight() << " TexDir: " << actorList->getTextureDir() << endl;
}
break;
default:
break;
}
lines++;
}
std::cout << "Lines detected: " << lines << endl;
// Close file
inFile.close();
// Destroy temp data
getType.clear();
getID.clear();
getX.clear();
getY.clear();
getWidth.clear();
getHeight.clear();
getTexDir.clear();
std::cout << "Load success!" << endl;
enter code here
}