cocos2d-x 3.1.1 學習筆記[6]ScrollView 可以拖動的Layer
阿新 • • 發佈:2019-02-15
//建立一個scroolview ui::ScrollView* scrollView = ui::ScrollView::create(); scrollView->setBounceEnabled(true); //移動的方向是任意方向 scrollView->setDirection(ui::ScrollView::Direction::BOTH); //scrollview的大小 scrollView->setSize(Size(500.0f, 500.0f)); scrollView->setPosition(Vec2(100, 100)); addChild(scrollView); //建立一個精靈放到scrollview裡面 auto sp = Sprite::create("card_bg_big_26.jpg"); sp->setAnchorPoint(Vec2(0, 0)); sp->setPosition(Vec2(20, 30)); float innerWidth = scrollView->getSize().width + sp->getContentSize().width; float innerHeight = scrollView->getSize().height + sp->getContentSize().height; //設定scrollview的內部容器大小 scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));