Hello!
I have a silly, simple question. I have a ListView in my scene. It’s pretty long so when I enter the scene I want that it automatically scrolls from left to right to show the whole content of the ListView (then ofcorse the user can manually scroll the View as he wants). My code looks like this:
auto listView = ListView::create();
listView->setDirection(ui::ScrollView::Direction::HORIZONTAL);
listView->setTouchEnabled(true);
listView->setBounceEnabled(true);
listView->setSize(Size(winSize.width, winSize.height/3));
listView->setClippingEnabled(true);
listView->setAnchorPoint(Vec2::ZERO);
listView->setPosition(Vec2::ZERO);
listView->setSwallowTouches(false);
auto spr1 = Sprite::create("sprite1.png");
auto spr2 = Sprite::create("sprite2.png");
auto spr3 = Sprite::create("sprite3.png");
auto spr4 = Sprite::create("sprite4.png");
auto spr5 = Sprite::create("sprite5.png");
spr1->setAnchorPoint(Vec2(0, 0.5f));
spr2->setAnchorPoint(Vec2(0, 0.5f));
spr3->setAnchorPoint(Vec2(0, 0.5f));
spr4->setAnchorPoint(Vec2(0, 0.5f));
spr5->setAnchorPoint(Vec2(0, 0.5f));
auto wid1 = Widget::create();
wid1->setContentSize(spr1->getContentSize());
wid1->addChild(spr1);
auto wid2 = Widget::create();
wid2->setContentSize(spr2->getContentSize());
wid2->addChild(spr2);
auto wid3 = Widget::create();
wid3->setContentSize(spr3->getContentSize());
wid3->addChild(spr3);
auto wid4 = Widget::create();
wid4->setContentSize(spr4->getContentSize());
wid4->addChild(spr4);
auto wid5 = Widget::create();
wid5->setContentSize(spr5->getContentSize());
wid5->addChild(spr5);
listView->pushBackCustomItem(wid1);
listView->pushBackCustomItem(wid2);
listView->pushBackCustomItem(wid3);
listView->pushBackCustomItem(wid4);
listView->pushBackCustomItem(wid5);
listView->scrollToRight(2.0f, true); <=====THIS FUNCTION SHOULD DO THE TRICK BUT DOES NOT WORK :(
addChild(listView);
The ListView works nice except for the scrollToRight method. What am I missing guys?