加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2dx 保存scrollview里的全部内容到一张图里

发布时间:2020-12-14 16:39:54 所属栏目:百科 来源:网络整理
导读:mapint,string levelMaps; setint saved;//记录存好的文件 for(int i=0; i189; i++){ //检查188个关卡,有哪些已经配置好了 string levelName = "guanka_"; levelName.append(Value(i).asString()); levelMaps.insert(mapint,string::value_type(i,levelName)

map<int,string> levelMaps;
set<int> saved;//记录存好的文件
for(int i=0; i<189; i++){
//检查188个关卡,有哪些已经配置好了
string levelName = "guanka_";
levelName.append(Value(i).asString());
levelMaps.insert(map<int,string>::value_type(i,levelName));
levelName.append(".tpl");
if(FileUtils::getInstance()->isFileExist(levelName)){
//文件存在就记录
saved.insert(i);
}
}
auto ws = Director::getInstance()->getWinSize();
auto lstw = ui::ListView::create();
lstw->setName("showLevel");
lstw->setBackGroundColorType(ui::ScrollView::BackGroundColorType::SOLID);
lstw->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
lstw->setSize(Size(110,ws.height));
lstw->setDirection(ui::ScrollView::Direction::VERTICAL);
lstw->setBounceEnabled(true);
lstw->setPosition(Vec2(0,0));
pNode->addChild(lstw);
for(std::pair<int,string> mapL : levelMaps){
auto lay = Layout::create();
lay->setBackGroundColorType(ScrollView::BackGroundColorType::SOLID);
lay->setBackGroundColor(Color3B::GRAY);
lay->setTouchEnabled(true);
lay->setUserData((void*)mapL.first);
lay->setContentSize(Size(110,42));//117 114
Label *label = Label::createWithSystemFont(mapL.second,"",18);
label->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
if(saved.find(mapL.first) != saved.end()){
//如果存在改变文字颜色
label->setColor(Color3B::GREEN);
}else {
label->setColor(Color3B::BLACK);
}
label->setDimensions(110,30);
label->setPosition(lay->getContentSize()/2);
lay->addClickEventListener([=](Ref *sender){
auto select = dynamic_cast<Layout*>(lstw->getUserObject());
if(select == lay){
return ;
}
if(select){
select->setBackGroundColor(Color3B::GRAY);
}
// m_guanka.canMove = pro.m_type;
lay->setBackGroundColor(Color3B::RED);
lstw->setUserObject(lay);
//设置关卡级数
m_level = mapL.first;
Button * levelText = dynamic_cast<Button*>(pNode->getChildByName("m_level"));
if(levelText){
levelText->setTitleText(Value(m_level).asString());
}
pNode->removeChildByName("showLevel");
//重新读取配置信息
readGameDataTpl();
});
//设置默认
if(m_level == mapL.first){
lay->setBackGroundColor(Color3B::RED);
lstw->setUserObject(lay);
}
lay->addChild(label);
lstw->addChild(lay);
}
lstw->runAction(Sequence::create(DelayTime::create(0.1),CallFunc::create([=](){
// lstw->scrollToPercentVertical(m_level*1.0/levelMaps.size()*100.0,0.1,true);
log("------------------------x=%f,y=%f,heigh=%f",lstw->getInnerContainer()->getPosition().x,lstw->getInnerContainer()->getPosition().y,lstw->getInnerContainer()->getSize().height);
int sn = lstw->getInnerContainerSize().height/960;
auto off = lstw->getInnerContainerSize().height-960.0*sn;
// lstw->getInnerContainer()->setPosition(Vec2(0,0));

//将listview里的全部内容保存到一张图片里

auto render = RenderTexture::create(640,lstw->getInnerContainerSize().height); render->begin(); auto pos = lstw->getInnerContainer()->getPosition(); for(int i=0; i<sn-1; i++){ this->visit();// pos+= Vec2(0,960); pos.y += 960; lstw->getInnerContainer()->setPosition(pos); log("pos [%d] y=%f",i,pos.y); } log("-----1pos [%d] y=%f",sn-2,pos.y); this->visit(); pos.y += off; lstw->getInnerContainer()->setPosition(pos); this->visit(); log("------2pos [%d] y=%f",sn-1,pos.y); render->end(); render->saveToFile("sssss.png"); }),nullptr));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读