game/Classes/startScene.cpp
// on "init" you need to initialize your instance
on "init" you need to initialize your instance
on " init " you need to initialize your instance
bool startScene::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    bubble::startCache();
    selectedHalo = 0;
    auto listener1 = EventListenerTouchOneByOne::create(); 
    listener1->setSwallowTouches(false); 
    listener1->onTouchBegan = CC_CALLBACK_2(startScene::onTouchBegan, this);
    this->_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, this);
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    auto sprite = Sprite::create("xxh-bg.png");
    sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    sprite->setScale(visibleSize.height/1920.0, visibleSize.height/1920.0);
    this->addChild(sprite, 0);
    auto startItem = MenuItemImage::create(
                                           "开始游戏.png",
                                           "开始游戏larged.png",
                                           CC_CALLBACK_1(startScene::startGame, this));
    startItem->setPosition(Vec2(visibleSize.width/2, visibleSize.height/4));
    auto menu = Menu::create(startItem, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu, 1);
    haloPosn[0] = Vec2(visibleSize.width/2, HALO_POSN_1);
    haloPosn[1] = Vec2(visibleSize.width/4, HALO_POSN_2);
    haloPosn[2] = Vec2(visibleSize.width/4*3, HALO_POSN_2);
    halo[0] = Sprite::create("slow.png");
    halo[1] = Sprite::create("fire.png");
    halo[2] = Sprite::create("heath+.png");
    halo[0]->setPosition(haloPosn[0]);
    halo[1]->setPosition(haloPosn[1]);
    halo[2]->setPosition(haloPosn[2]);
    halo[0]->setScale(1.5, 1.5);
    this->addChild(halo[0], 1);
    this->addChild(halo[1], 1);
    this->addChild(halo[2], 1);
    haloLabel[0] = LabelTTF::create(haloName[0], "Arial", 50);
    haloLabel[1] = LabelTTF::create(haloDescription[0], "Arial", 35);
    haloLabel[0]->setPosition(Vec2(visibleSize.width/2, HALO_POSN_1 - 160));
    haloLabel[1]->setPosition(Vec2(visibleSize.width/2, HALO_POSN_1 - 210));
    this->addChild(haloLabel[0], 2);
    this->addChild(haloLabel[1], 2);
    return true;
}
bool startScene :: init ( ) { if ( ! Layer :: init ( ) ) { return false ; } bubble :: startCache ( ) ; selectedHalo = 0 ; auto listener1 = EventListenerTouchOneByOne :: create ( ) ; listener1 -> setSwallowTouches ( false ) ; listener1 -> onTouchBegan = CC_CALLBACK_2 ( startScene :: onTouchBegan , this ) ; this -> _eventDispatcher -> addEventListenerWithSceneGraphPriority ( listener1 , this ) ; Size visibleSize = Director :: getInstance ( ) -> getVisibleSize ( ) ; Vec2 origin = Director :: getInstance ( ) -> getVisibleOrigin ( ) ; auto sprite = Sprite :: create ( " " ) ; sprite -> setPosition ( Vec2 ( visibleSize . width / 2 + origin . x , visibleSize . height / 2 + origin . y ) ) ; sprite -> setScale ( visibleSize . height / 1920.0 , visibleSize . height / 1920.0 ) ; this -> addChild ( sprite , 0 ) ; auto startItem = MenuItemImage :: create ( " " CC_CALLBACK_1 ( startScene :: startGame , this ) ) ; startItem -> setPosition ( Vec2 ( visibleSize . width / 2 , visibleSize . height / 4 ) ) ; auto menu = Menu :: create ( startItem , NULL ) ; menu -> setPosition ( Vec2 :: ZERO ) ; this -> addChild ( menu , 1 ) ; haloPosn [ 0 ] = Vec2 ( visibleSize . width / 2 , HALO_POSN_1 ) ; haloPosn [ 1 ] = Vec2 ( visibleSize . width / 4 , HALO_POSN_2 ) ; haloPosn [ 2 ] = Vec2 ( visibleSize . width / 4 * 3 , HALO_POSN_2 ) ; halo [ 0 ] = Sprite :: create ( " " ) ; halo [ 1 ] = Sprite :: create ( " " ) ; halo [ 2 ] = Sprite :: create ( " " ) ; halo [ 0 ] -> setPosition ( haloPosn [ 0 ] ) ; halo [ 1 ] -> setPosition ( haloPosn [ 1 ] ) ; halo [ 2 ] -> setPosition ( haloPosn [ 2 ] ) ; halo [ 0 ] -> setScale ( 1.5 , 1.5 ) ; this -> addChild ( halo [ 0 ] , 1 ) ; this -> addChild ( halo [ 1 ] , 1 ) ; this -> addChild ( halo [ 2 ] , 1 ) ; haloLabel [ 0 ] = LabelTTF :: create ( haloName [ 0 ] , " " , 50 ) ; haloLabel [ 1 ] = LabelTTF :: create ( haloDescription [ 0 ] , " " , 35 ) ; haloLabel [ 0 ] -> setPosition ( Vec2 ( visibleSize . width / 2 , HALO_POSN_1 - 160 ) ) ; haloLabel [ 1 ] -> setPosition ( Vec2 ( visibleSize . width / 2 , HALO_POSN_1 - 210 ) ) ; this -> addChild ( haloLabel [ 0 ] , 2 ) ; this -> addChild ( haloLabel [ 1 ] , 2 ) ; return true ; }
on "init" you need to initialize your instance
on " init " you need to initialize your instance
////////////////////////////// // 1. super init first //创建一个触摸监听 //设置是否想下传递触摸 // create menu, it's an autorelease object