本文整理汇总了C++中Floor::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Floor::setPosition方法的具体用法?C++ Floor::setPosition怎么用?C++ Floor::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Floor
的用法示例。
在下文中一共展示了Floor::setPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateFloorsAndCoins
void GameScene::updateFloorsAndCoins()
{
//改变山体的位置
for (int i =0; i<floorArray.size(); i++) {
Floor *floor = floorArray.at(i);
//forceX=300,speedFix = 0.01
floor->setPosition(Point(floor->getPositionX()-forceX * speedFix, floor->getPositionY()));
}
//改变金币的位置
for (int i = 0; i<coinArray.size(); i++) {
Coin *coin = coinArray.at(i);
coin->setPosition(Point(coin->getPositionX()-forceX * speedFix, coin->getPositionY()));
}
//当第一个山体移出屏幕
if (floorArray.at(0)->getPositionX() <-50) {
int num = floorArray.size()-1;//数组中最后一个元素下标
float posx = floorArray.at(num)->getPositionX();//获取最后一个山体的X坐标
//将第一个山体再加入数组中,这样它就成为最后一个元素
floorArray.pushBack(floorArray.at(0));
//删除数组中第一个元素,这样就完成了第一个山体移动到数组中最后的位置
floorArray.eraseObject(floorArray.at(0));
coinArray.pushBack(coinArray.at(0));
coinArray.eraseObject(coinArray.at(0));
//获取0~2的随机数
randomNum = this->getRandomNumber(0, 2);
if (randomNum == 0) {
isFrontBlank = true;
randomNum = this->getRandomNumber(1, 4);
}
Coin *coin = coinArray.at(num);
//数组中最后一个元素,即原来的第一个元素移动到最后位置,再获取最后一个
coin->setVisible(true);
if (isFrontBlank) {
//posx为数组中倒数第二个元素的X坐标,高度为随机数100~150之间
//设置新的最后一个元素的位置
floorArray.at(num)->setPosition(Point(posx + randomNum*35 + 35, this->getRandomNumber(winSize.height/2 -100,170)));
coinArray.at(num)->setPosition(Point(posx + randomNum*35 + 35, floorArray.at(num)->getPositionY() + this->getRandomNumber(50, 150)));
isFrontBlank = false;
}else{
//X轴坐标后移,高度同前一个山体
floorArray.at(num)->setPosition(Point(posx + 35 , floorArray.at(num - 1)->getPositionY()));
coinArray.at(num)->setPosition(Point(posx + 35, floorArray.at(num)->getPositionY() + this->getRandomNumber(50, 150)));
}
randomNum = this ->getRandomNumber(0, 2);
if (randomNum == 0) {
coin->setVisible(false);
}
}
}
示例2: loadLevelResource
void LevelManager::loadLevelResource(int level)
{
//load position
char tmp[256];
char c;
int dataX, dataY;
stringstream ss;
ifstream fin(s_level1);//读取文件“2.txt”注意,文件须放在工作空间下。读取后产生 流型 文件fin
//load Floors
fin.getline(tmp, 256, '\n');
CCAssert(strcmp(tmp, "floor:") == 0, "Level Data Format Wrong!");
fin.getline(tmp, 256, '\n');
while (strcmp(tmp, "")){
ss.clear(); //记得clear, fuck!
ss << tmp;
ss >> dataX;
ss >> c;
ss >> dataY;
m_floorPositions.push_back(ccp(dataX*64 + 32, winSize.height-dataY*64-32));
i_map[rows - dataY][cols -dataX] = 3; //用3表示墙
fin.getline(tmp, 256, '\n');
}
//load Tom
fin.getline(tmp, 256, '\n');
CCAssert(strcmp(tmp, "tom:") == 0, "Level Data Format Wrong!");
fin.getline(tmp, 256, '\n');
ss.clear(); //记得clear, fuck!
ss << tmp;
ss >> dataX;
ss >> c;
ss >> dataY;
m_tomPosition = ccp(dataX*64 + 32, winSize.height -dataY*64-32);
i_map[rows - dataY][cols -dataX] = 9; //用9表示Tom
fin.getline(tmp, 256, '\n');
//load jerry
fin.getline(tmp, 256, '\n');
CCAssert(strcmp(tmp, "jerry:") == 0, "Level Data Format Wrong!");
fin.getline(tmp, 256, '\n');
ss.clear(); //记得clear, fuck!
ss << tmp;
ss >> dataX;
ss >> c;
ss >> dataY;
i_map[rows - dataY][cols -dataX] = 7; //用7表示jerry
m_jerryPosition = ccp(dataX * 64 + 32, winSize.height-dataY*64-32);
fin.getline(tmp, 256, '\n');
fin.close();
//load tom
Tom * tm = Tom::create();
tm->setPosition(m_tomPosition);
tom = tm;
m_gameLayer->addChild(tm,2);
//load Jerry
Jerry *jy = Jerry::create();
jy->setPosition(m_jerryPosition);
jerry = jy;
m_gameLayer->addChild(jy,2);
// load floor
for (int i = 0; i < m_floorPositions.size(); i++){
Floor* f = Floor::create();
f->setPosition(m_floorPositions.at(i));
m_gameLayer->addChild(f,1);
floors.push_back(f);
}
}