GameScene.h
#include "cocos2d.h"
#include "extensions/cocos-ext.h"
#include "ui/CocosGUI.h"
USING_NS_CC;
USING_NS_CC_EXT;
using namespace ui;
class GameScene : public cocos2d::Layer
{
protected:
void addLayer();
public:
static cocos2d::Scene* createScene();
virtual bool init();
CREATE_FUNC(GameScene);
};
GameScene.spp
#include "GameScene.h"
USING_NS_CC;
Scene* GameScene::createScene()
{
auto scene = Scene::createWithPhysics();
auto layer = GameScene::create();
scene->addChild(layer);
return scene;
}
bool GameScene::init()
{
if (!Layer::init())
return false;
addLayer();
return true;
}
#define kModalLayerPriority -1
void GameScene::addLayer(){
auto layer = Layer::create();
// モーダルレイヤ ここから
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = [](Touch *touch,Event*event)->bool{
return true;
};
auto dip = layer->getEventDispatcher();
dip->addEventListenerWithSceneGraphPriority(listener, this);
dip->setPriority(listener, kModalLayerPriority);
// モーダルレイヤ ここまで
auto size = Director::getInstance()->getVisibleSize();
ui::ScrollView* sc = ui::ScrollView::create();
sc->setContentSize(size);
sc->setBackGroundColor(Color3B::GREEN);
sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
sc->setBounceEnabled(true);
sc->setDirection(ui::ScrollView::Direction::VERTICAL);
sc->setContentSize(Size(480,size.height));
sc->setInnerContainerSize(Size(480, sc->getContentSize().height + 300 ));
sc->setPosition(Vec2(0,size.height - sc->getContentSize().height ));
Button* button = Button::create("button.png");
button->setPosition(Vec2(button->getContentSize().width / 2.0f,
sc->getContentSize().height - button->getContentSize().height / 2.0f));
sc->addChild(button);
layer->addChild(sc);
addChild(layer);
}