bool GameScene::init(){ if ( !Layer::init() ) { return false; } auto touchLister = EventListenerTouchOneByOne::create(); touchLister->onTouchBegan =CC_CALLBACK_2(GameScene::onTouchBegan, this); touchLister->onTouchEnded =CC_CALLBACK_2(GameScene::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(touchLister,this); //加入游戏的背景颜色 auto layerColorBG = cocos2d::LayerColor::create(cocos2d::Color4B(180,170,160,255)); this->addChild(layerColorBG); Size visibleSize = Director::getInstance()->getVisibleSize(); //创建卡片 createCardSprite(visibleSize); // //创建2张自动生成卡片 autoCreateCardNumber(); autoCreateCardNumber(); //加入“分数”label auto labelTTFCardNumberName = LabelTTF::create("SCORE","HiraKakuProN-W6",80); labelTTFCardNumberName->setPosition(Point(visibleSize.width/3,visibleSize.height-40)); addChild(labelTTFCardNumberName); //加入具体的分数 labelTTFCardNumber = LabelTTF::create("0","HiraKakuProN-w6",80); labelTTFCardNumber->setPosition(Point(visibleSize.width-400,visibleSize.height-50)); addChild(labelTTFCardNumber); return true; }
// on "init" you need to initialize your instance bool GameScene::init() { if ( !Layer::init() ) { return false; } visibleSize = Director::getInstance()->getVisibleSize(); //加入游戏背景 //1 auto layerColorBG = LayerColor::create(Color4B(180, 170, 160, 255)); this->addChild(layerColorBG); //pause //2 MenuItemFont::setFontName("Consolas"); MenuItemFont::setFontSize(40); auto menuItemPause = MenuItemFont::create("PAUSE", CC_CALLBACK_1(GameScene::onPause, this)); auto menu = Menu::create(menuItemPause, NULL); addChild(menu); menu->setPosition(Point(100, visibleSize.width +(visibleSize.height - visibleSize.width)/2)); //创建分数 //3 auto cardNumberTitle = Label::createWithSystemFont("SCORE","Consolas",40); cardNumberTitle->setPosition(Point(visibleSize.width - 150, visibleSize.width + (visibleSize.height - visibleSize.width)/2 + 25)); addChild(cardNumberTitle); score = 0; cardNumberTTF = Label::createWithSystemFont("0", "Consolas", 40); cardNumberTTF->setPosition(Point(visibleSize.width - 150, visibleSize.width + (visibleSize.height - visibleSize.width)/2 -25)); addChild(cardNumberTTF); //设置触摸事件监听 auto touchListener = EventListenerTouchOneByOne::create(); touchListener->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan, this); touchListener->onTouchMoved = CC_CALLBACK_2(GameScene::onTouchMoved, this); touchListener->onTouchEnded = CC_CALLBACK_2(GameScene::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); createCardSprite(visibleSize); if (UserDefault::getInstance()->getBoolForKey("history")) { resumeStatus(); } else { //初始时生成两个2 createCardNumber(false); createCardNumber(false); } recognizer = new SimpleRecognizer(); return true; }
bool GameScene::init() { if (!Layer::init()) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); //游戏背景 auto layerBg = LayerColor::create(Color4B(180, 170, 160, 255)); this->addChild(layerBg); //暂停按钮 MenuItemFont::setFontName("Consolas"); MenuItemFont::setFontSize(20); auto menuItemPause = MenuItemFont::create("PAUSE", CC_CALLBACK_1(GameScene::onPause, this)); auto menu = Menu::create(menuItemPause, NULL); addChild(menu); menu->setPosition(visibleSize.width - 50, visibleSize.height - 20); //分数 auto cardNumberTitle = Label::createWithSystemFont("SCORE", "Consolas", 20); cardNumberTitle->setPosition(visibleSize.width - 50, visibleSize.height-100); addChild(cardNumberTitle); score = 0; cardNumberTTF = Label::createWithSystemFont("0", "Consolas", 20); cardNumberTTF->setPosition(visibleSize.width - 50, visibleSize.height - 150); addChild(cardNumberTTF); recognizer = new SimpleRecognizer(); auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan, this); listener->onTouchMoved = CC_CALLBACK_2(GameScene::onTouchMoved, this); listener->onTouchEnded = CC_CALLBACK_2(GameScene::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); //创建4*4 卡片 createCardSprite(visibleSize); createCardNumber(true); createCardNumber(true); return true; }
bool GameScene::init() { if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); //设置触摸事件监听 auto touchListener = EventListenerTouchOneByOne::create(); touchListener->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan, this); touchListener->onTouchEnded = CC_CALLBACK_2(GameScene::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); //加入游戏背景 auto layerColorBG = LayerColor::create(Color4B(180, 170, 160, 255)); this->addChild(layerColorBG); //创建分数 auto cardNumberTitle = LabelTTF::create("SCORE","Consolas",80); cardNumberTitle->setPosition(Point(visibleSize.width/2 + 340, visibleSize.height/2 + 130)); addChild(cardNumberTitle); score = 0; cardNumberTTF = LabelTTF::create("0", "Consolas", 70); cardNumberTTF->setPosition(Point(visibleSize.width/2 + 340, visibleSize.height/2 - 100)); addChild(cardNumberTTF); //创建4X4卡片 createCardSprite(visibleSize); //初始时生成两个2 createCardNumber(); createCardNumber(); return true; }