是这样的:
我打算用ScrollView实现一个滚动的效果,但是又不想一下添加很多的node进去。所以就再ScrollView加载了两个Layout。当滚动的时候,我把上面的layout放到下面的那个layout的下面,实现一个循环的显示。但是当我触发了scrolling后,我打算在layout里添加一个新的node。实现那种循环的滚动效果。但是会报错!
代码:
if(type == cocos2d::ui::ScrollviewEventType::SCROLLVIEW_EVENT_SCROLLING){
if (index < currentIndex_){ //need to change page;
currentMap_->setPositionY(nextMap_->getPositionY() - size.height);
currentIndex_ = index;
currentMap_->removeAllChildren();
auto node = maplist_;
currentMap_->addChild(node); // 这句会报错,但是我的node肯定不是空的
std::swap(currentMap_, nextMap_);
}
if (index > currentIndex_){
nextMap_->setPositionY(currentMap_->getPositionY() + size.height);
currentIndex_ = index;
nextMap_->removeAllChildren();
nextMap_->addChild(maplist_);
std::swap(currentMap_, nextMap_);
}

