void HelloWorld::registerControllerListener() { //create an evnetListenerController _listener = EventListenerController::create(); //bind onConneected event call function _listener->onConnected = CC_CALLBACK_2(HelloWorld::onConnectController,this); //bind disconnect event call function _listener->onDisconnected = CC_CALLBACK_2(HelloWorld::onDisconnectedController,this); //bind onKeyDown event call function _listener->onKeyDown = CC_CALLBACK_3(HelloWorld::onKeyDown, this); //bind onKeyUp event call function _listener->onKeyUp = CC_CALLBACK_3(HelloWorld::onKeyUp, this); _listener->onKeyRepeat = CC_CALLBACK_3(HelloWorld::onKeyRepeat, this); //bind onAxis event call function, onAxis will be called when analog stick is changed _listener->onAxisEvent = CC_CALLBACK_3(HelloWorld::onAxisEvent, this); //Activate the listener into the event dispatcher _eventDispatcher->addEventListenerWithSceneGraphPriority(_listener, this); //This function should be called for iOS platform Controller::startDiscoveryController(); }
void P008::initNailStyle() { // 选择指甲的样式 m_scrollLayer = ScrollLayer::create("P008_style_", ScrollDragDir::DragLeft, 6, true, s_firstNailLayer); m_scrollLayer->setClickScrollItemEvent(CC_CALLBACK_3(P008::onClickNailStyleScrollItem, this)); m_scrollLayer->setScrollItemMovingCollisionEvent(CC_CALLBACK_3(P008::onScrollStyleMovingCollision, this)); m_scrollLayer->setScrollItemCollisonEndedEvent(CC_CALLBACK_3(P008::onScrollStyleCollisonEndedEvent, this)); SCROLL_POSITION_IN_JSON(m_scrollLayer); m_sceneJson->addChild(m_scrollLayer, 600); m_scrollLayer->initItemSelectFromIndex(0); s_firstNailLayer = false; }
void P003::initScrollLayer() { m_scrollDoubleLayer = ScrollDoubleLayer::create("P002_left_", ScrollDragDir::DragLeft, 4, true, sideScrollIsFirstRun); m_scrollDoubleLayer->setClickScrollItemEvent(CC_CALLBACK_3(P003::onClickItem, this)); m_scrollDoubleLayer->setScrollItemDragOutCallBack(CC_CALLBACK_3(P003::onDragOut, this)); m_scrollDoubleLayer->setScrollItemMovingCollisionEvent(CC_CALLBACK_3(P003::onMovingCollision, this)); m_scrollDoubleLayer->setScrollItemCollisonEndedEvent(CC_CALLBACK_3(P003::onCollisionEnded, this)); m_scrollDoubleLayer->initItemSelectFromIndex(0); SCROLL_POSITION_IN_JSON(m_scrollDoubleLayer); m_sceneJson->addChild(m_scrollDoubleLayer, ZORDER_PROGRESS); }
bool Gate::init(std::string fileName) { if(!BaseUI::init(fileName)) { return false; } this->gateResp=Manager::getInstance()->getRoleData()->gate();//服务器给的数据 Widget* bottom=static_cast<Widget*>(layout->getChildByName("bottom")); this->nameLabel = static_cast<Text*>(bottom->getChildByName("nameLabel")); this->desLabel = static_cast<Text*>(bottom->getChildByName("desLabel")); //模版 Widget* item=static_cast<Widget*>(layout->getChildByName("item")); item->removeFromParent(); Size widgetSize = Director::getInstance()->getWinSize(); this->rotateList = RotateList::create(); this->rotateList->setSize(Size(widgetSize.width, widgetSize.height)); this->rotateList->addEventListener(CC_CALLBACK_3(Gate::rotateListCallback,this)); //传进去单个模版 this->rotateList->setItemModel(item,widgetSize.width,widgetSize,113.6);//widgetSize.width/9); this->addChild(this->rotateList); float y =widgetSize.height-item->getContentSize().height; this->rotateList->setPosition(Vec2(0,y)); //滚动条 this->slider=static_cast<Slider*>(bottom->getChildByName("slider")); this->slider->getVirtualRenderer()->setContentSize(Size(474,slider->getVirtualRenderer()->getContentSize().height)); this->rotateList->setSlider(this->slider); //按钮分别为剧情,精英,活动,密镜,返回 std::vector<Button*> buttons; std::vector<std::string> btnName={"storyBtn","outstandBtn","activeBtn","mirrorBtn"}; for (std::string name : btnName) { Button* btn=static_cast<Button*>(bottom->getChildByName(name)); btn->setTouchEnabled(true); btn->addTouchEventListener(CC_CALLBACK_2(Gate::touchEvent,this)); buttons.push_back(btn); } tabBar=TabBar::create(buttons); tabBar->retain(); for (int i=0; i<buttons.size(); ++i) { bool isEnableTouch = getList(-buttons.at(i)->getTag()); buttons.at(i)->setTouchEnabled(isEnableTouch); buttons.at(i)->setColor(isEnableTouch?Color3B::WHITE:Color3B::GRAY); } Button* backBtn=static_cast<Button*>(layout->getChildByName("backBtn")); backBtn->addTouchEventListener(CC_CALLBACK_2(Gate::touchEvent,this)); //默认获取剧情的数据,并且设置高亮选中状态 this->currentType = 1; this->getList(this->currentType-1); Label* name = static_cast<Label*>(nameLabel->getVirtualRenderer()); name->enableOutline(Color4B::BLACK,1); Label* des = static_cast<Label*>(desLabel->getVirtualRenderer()); des->enableOutline(Color4B::BLACK,1); return true; }
void GameControllerTest::registerControllerListener() { _listener = EventListenerController::create(); _listener->onConnected = CC_CALLBACK_2(GameControllerTest::onConnectController,this); _listener->onDisconnected = CC_CALLBACK_2(GameControllerTest::onDisconnectedController,this); _listener->onKeyDown = CC_CALLBACK_3(GameControllerTest::onKeyDown, this); _listener->onKeyUp = CC_CALLBACK_3(GameControllerTest::onKeyUp, this); _listener->onAxisEvent = CC_CALLBACK_3(GameControllerTest::onAxisEvent, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(_listener, this); Controller::startDiscoveryController(); //get game pad status in polling mode //scheduleUpdate(); }
void FruitCutNinjaScene::onTouchesEnded(const std::vector<Touch*>& touches, Event *event) { for (Touch* touch : touches) { _blade->setDim(true); auto func = CC_CALLBACK_3(FruitCutNinjaScene::slice, this); _world->rayCast(func, touch->getStartLocation(), touch->getLocation(), nullptr); } }
bool RoleAllList::init(std::string fileName) { if(!BaseUI::init(fileName)) { return false; } //如果需要对cocostudio 设计的ui进行调整 //模版 Widget* item=static_cast<Widget*>(layout->getChildByName("item")); item->removeFromParent(); Size widgetSize = Director::getInstance()->getWinSize(); this->rotateList = RotateList::create(); this->rotateList->setSize(Size(widgetSize.width, widgetSize.height)); this->rotateList->addEventListener(CC_CALLBACK_3(RoleAllList::rotateListCallback,this)); //传进去单个模版 this->rotateList->setItemModel(item,widgetSize.width,widgetSize,widgetSize.width/10); this->addChild(this->rotateList); float y =widgetSize.height-item->getContentSize().height; this->rotateList->setPosition(Vec2(0,y-56)); //滚动条 Slider* slider=static_cast<Slider*>(layout->getChildByName("slider")); slider->getVirtualRenderer()->setContentSize(Size(474,slider->getVirtualRenderer()->getContentSize().height)); this->rotateList->setSlider(slider); Widget* btnPanel=static_cast<Widget*>(layout->getChildByName("btnPanel")); static_cast<Button*>(btnPanel->getChildByName("allBtn"))->addTouchEventListener(CC_CALLBACK_2(RoleAllList::touchButtonEvent, this)); static_cast<Button*>(btnPanel->getChildByName("frontBtn"))->addTouchEventListener(CC_CALLBACK_2(RoleAllList::touchButtonEvent, this)); // static_cast<Button*>(btnPanel->getChildByName("middleBtn"))->addTouchEventListener(CC_CALLBACK_2(RoleAllList::touchButtonEvent, this)); static_cast<Button*>(btnPanel->getChildByName("backBtn"))->addTouchEventListener(CC_CALLBACK_2(RoleAllList::touchButtonEvent, this)); btnPanel->removeFromParent(); this->addChild(btnPanel,0); Button* returnBtn = static_cast<Button*>(layout->getChildByName("returnBtn")); returnBtn->addTouchEventListener(CC_CALLBACK_2(RoleAllList::touchButtonEvent, this)); LoginResp* loginResp = Manager::getInstance()->getRoleData(); for (int i=0; i<loginResp->npclist_size(); i++) { PNpc pnpc=loginResp->npclist(i); pNpcs.push_back(pnpc); } //角色排序 sort(this->pNpcs.begin(), this->pNpcs.end(), this->sortHandler); //此处传进去的应该是表中可招募武将的长度 this->rotateList->setNum(int(this->pNpcs.size())); //当前拥有多少角色/最多可拥有多少角色 // static_cast<Text*>(layout->getChildByName("progress"))->setString( /npclist_size()); return true; }
bool GameOverLayer::init() { if (!LayerColor::initWithColor(Color4B(255, 255, 255, 50))) { return false; } auto visibleSize=Director::getInstance()->getVisibleSize(); auto score_bk=Sprite::createWithSpriteFrameName("gameover_score_bk.png"); score_bk->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2)); addChild(score_bk,1); score_bk->setScale(0.2f); score_bk->runAction(Sequence::create(ScaleTo::create(0.2f, 1.1f), ScaleTo::create(0.1f, 0.9f), ScaleTo::create(0.1f, 1.0f), CallFunc::create(CC_CALLBACK_0(GameOverLayer::ShowScore,this)), NULL)); auto backtomenu_normal=Sprite::createWithSpriteFrameName("gameover_backtomenu.png"); auto backtomenu_pressed=Sprite::createWithSpriteFrameName("gameover_backtomenu.png"); backtomenu_Item = MenuItemSprite::create(backtomenu_normal, backtomenu_pressed, CC_CALLBACK_1(GameOverLayer::menu_backtomenu_Callback,this)); // auto playagain_normal=Sprite::createWithSpriteFrameName("gameover_playagain.png"); // auto playagain_pressed=Sprite::createWithSpriteFrameName("gameover_playagain.png"); // playagain_Item = MenuItemSprite::create(playagain_normal, // playagain_pressed, // CC_CALLBACK_1(GameOverLayer::menu_playagain_Callback,this)); auto menu = Menu::create(backtomenu_Item,NULL); menu->alignItemsHorizontallyWithPadding(20); menu->setPosition(visibleSize.width/2, 100); this->addChild(menu, 2); auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); listener->onTouchBegan = CC_CALLBACK_2(GameOverLayer::onTouchBegan, this); listener->onTouchMoved = CC_CALLBACK_2(GameOverLayer::onTouchMoved, this); listener->onTouchEnded = CC_CALLBACK_2(GameOverLayer::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); #if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) auto controllListener = EventListenerController::create(); controllListener->onKeyUp = CC_CALLBACK_3(GameOverLayer::onKeyDown, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(controllListener, this); Controller::startDiscoveryController(); #endif return true; }
void P011_Draw::initScrollLayer() { m_scrollLayer = ScrollLayer::create("P011_draw_", ScrollDragDir::DragLeft, 18, false, s_firstDrawLayer); m_scrollLayer->setScrollItemTouchAbleEvent(CC_CALLBACK_3(P011_Draw::onScrollLayerTouchAble, this)); m_scrollLayer->setScrollItemMovingCollisionEvent(CC_CALLBACK_3(P011_Draw::onScrollLayerMovingCollision, this)); m_scrollLayer->setScrollItemCollisonEndedEvent(CC_CALLBACK_3(P011_Draw::onScrollItemCollisonEnded, this)); m_scrollLayer->setScrollItemTouchEndedEvent(CC_CALLBACK_3(P011_Draw::onScrollLayerTouchEnded, this)); m_scrollLayer->setScrollItemDragOutCallBack(CC_CALLBACK_3(P011_Draw::onScrollItemDragOutCallBack, this)); SCROLL_POSITION_IN_JSON(m_scrollLayer); m_sceneJson->addChild(m_scrollLayer, 600); m_scrollLayer->initItemSelectFromIndex(0); s_firstDrawLayer = false; // 擦除 m_earseSprite = m_sceneJson->getSubSprite("eraser"); m_earseSprite->setMoveAble(true); m_earseSprite->noClickMoveEffect(); m_earseSprite->setTouchSwallowsTouches(false); m_earseSprite->setOnTouchAble(CC_CALLBACK_2(P011_Draw::onEarseTouchAble, this)); m_earseSprite->setOnWillMoveTo(CC_CALLBACK_2(P011_Draw::onEarseWillMoveTo, this)); m_earseSprite->setOnTouchEnded(CC_CALLBACK_2(P011_Draw::onEarseTouchEnded, this)); m_earseSprite->saveCurrentProperties(); }
void CCutScene::toolSceneTouchMove(Touch *touch) { Point location = touch->getLocation(); _endPoint = location; if ((_startPoint - _endPoint).getLength() > 25) { _startPoint = _endPoint; } _blade->push(location); m_v2Delta = touch->getLocation() - touch->getPreviousLocation(); auto func = CC_CALLBACK_3(CCutScene::slice, this); _world->rayCast(func, touch->getPreviousLocation(), touch->getLocation(), nullptr); }
void TDDSwitchTest::testSetSwitches(Ref *sender) { log("testSetSwitches"); TDDSwitch *switchControl = new TDDSwitch(Size(150, 40), Color4B::WHITE, Color4B::BLUE); switchControl->setPosition(Point(100, 50)); addChild(switchControl); std::vector<std::string> switches; switches.push_back("all"); switches.push_back("history"); switchControl->setSwitches(switches, CC_CALLBACK_3(TDDSwitchTest::switchSelected, this)); }
void DeathMoth::play(int index) { switch (index) { case kDeathMothPlayIndex_Fly: { m_armature->getAnimation()->play("fly"); } break; case kDeathMothPlayIndex_Stand: { m_armature->getAnimation()->play("stand"); } break; case kDeathMothPlayIndex_OpenMouth: { m_armature->getAnimation()->play("open_mouth"); } break; case kDeathMothPlayIndex_Atk01: { m_armature->getAnimation()->play("atk01"); } break; case kDeathMothPlayIndex_Rush: { m_armature->getAnimation()->play("rush"); } break; case kDeathMothPlayIndex_Hurt: { m_armature->getAnimation()->play("hurt"); } break; case kDeathMothPlayIndex_Dead: { m_armature->getAnimation()->play("dead"); } break; default: break; } m_armature->getAnimation()->setMovementEventCallFunc(CC_CALLBACK_3(DeathMoth::movementEvent, this)); m_armature->getAnimation()->setFrameEventCallFunc(CC_CALLBACK_4(DeathMoth::frameEvent, this)); }
void TDDSwitchTest::testThreeSwitch(Ref *sender) { log("testSetSwitches"); TDDSwitch *switchControl = new TDDSwitch(Size(200, 50), Color4B::WHITE, Color4B::BLUE, Color3B::GRAY, Color3B::YELLOW, "GillSans", 16); switchControl->setPosition(Point(10, 150)); addChild(switchControl); std::vector<std::string> switches; switches.push_back("all"); switches.push_back("history"); switches.push_back("top"); switchControl->setSwitches(switches, CC_CALLBACK_3(TDDSwitchTest::switchSelected, this)); }
void ScrollDoubleLayer::creatMenuScrollItem(cocos2d::Vector<WJScrollItem*> &items, int count, const char *key) { m_vectorMenuItem.clear(); for (int i = 0; i < count; i++) { ScrollMenuItem *scrollItem = ScrollMenuItem::create(this, key, i, ScrollDragDir::StopDrag, true); scrollItem->setClickScrollItemEvent(CC_CALLBACK_3(ScrollDoubleLayer::_doEventMenuScrollItemClick, this)); // 默认选中了第一个 if (i == 0) scrollItem->setItemSelect(true); std::string itemKey = key; WJUtils::stringAddInt(itemKey, i + 1, 3); ScrollItemTemplate object = ScrollItemTemplateTem(itemKey); WJScrollItem* item = WJScrollItem::create(scrollItem, 0, scrollItem->getContentSize().height + object.itemsInterval); items.pushBack(item); // 当前1级菜单的数组 m_vectorMenuItem.push_back(scrollItem); } }
void SpiderFly::setState(SpiderState state) { Spider::setState(state); switch (m_state) { case kSpiderState_Attack: m_armature->getAnimation()->play("stand"); break; case kSpiderState_Stand: m_armature->getAnimation()->play("stand"); break; case kSpiderState_Hurted: m_armature->getAnimation()->play("hurt"); break; case kSpiderState_Walk: m_armature->getAnimation()->play("stand"); break; default: break; } m_armature->getAnimation()->setMovementEventCallFunc(CC_CALLBACK_3(SpiderFly::movementEvent, this)); m_armature->getAnimation()->setFrameEventCallFunc(CC_CALLBACK_4(SpiderFly::frameEvent, this)); }
// Tool bar constains the following elements // Back button // Filter Input // Switch // Layout: | BACK | INPUT .... SWITCH | // 800 or 480 // Landscape: | 80 // Portrait: | 80 | 80 | ... 120 | 400 - 120 = 280 - Layer *TDDSuiteLayer::createToolBarLayer() { float scale = TDDHelper::getBestScale(); // bool isLandscape = TDDHelper::isLandscape(); Size screenSize = TDDHelper::getScreenSize(); int midY = kToolBarHeight/2; int buttonW = (int)(scale * 90); int inputW = (int)(scale * 200); int switchW = (int)(scale * 130); int backX = buttonW/2; int inputH = kToolBarHeight - 10; int inputX = inputW / 2 + buttonW; int clearX = buttonW + buttonW/2; int switchY = 5; int switchX = screenSize.width - switchW - 10; int switchH = kToolBarHeight - switchY * 2; // Layer containter LayerColor *menuLayer = LayerColor::create(kColorToolBar, screenSize.width, kToolBarHeight); // Back Button Menu *menuBack = TDDHelper::createMenu(Point(backX, midY), "Back", CC_CALLBACK_1(TDDSuiteLayer::goBack, this)); menuLayer->addChild(menuBack); // Clear History button Menu *menuClear = TDDHelper::createMenu(Point(clearX, midY), "Clear", CC_CALLBACK_1(TDDSuiteLayer::clearHistory, this)); menuLayer->addChild(menuClear); mClearMenu = menuClear; mClearMenu->setVisible(false); // Filter Input mEditFilter = TDDHelper::createEditBox(menuLayer, Point(inputX, midY), Size(inputW, inputH)); mEditFilter->setText(TDDHelper::getFilter()); mEditFilter->setPlaceHolder("Testcase Filter"); mEditFilter->setDelegate(this); // Menu *menuFind = TDDHelper::createMenu(Point(findX, midY), "Find", // CC_CALLBACK_1(TDDSuiteLayer::filterTest, this)); // menuLayer->addChild(menuFind); // Switch TDDSwitch *switchControl = new TDDSwitch(Size(switchW, switchH), kColorSwitchBg, kColorSwitch, kColorSwitchOffText, kColorSwitchOnText, TDD_FONT_NAME, (int)(scale * TDD_FONT_SIZE2 )); switchControl->setPosition(Point(switchX, switchY)); menuLayer->addChild(switchControl); std::vector<std::string> switches; switches.push_back("all"); switches.push_back("history"); TDDMenuMode savedMode = TDDData::instance()->getMenuMode(); int index = 0; if(savedMode == TDDMenuModeHistory) { index = 1; } switchControl->setSwitches(switches, CC_CALLBACK_3(TDDSuiteLayer::switchSelected, this), index); return menuLayer; }
bool Label::multilineTextWrapByChar() { return multilineTextWrap(std::bind(CC_CALLBACK_3(Label::getFirstCharLen, this) , std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); }
bool Player::init() { _size = 0; _Model = EffectSprite3D::createFromObjFileAndTexture("playerv002.c3b", "playerv002_256.png"); _HealthSound = FMODAudioEngine::getEvent("event:/SFX/low_health"); _HealthSound->getParameter("health", &_HealthSoundParam); _HealthSoundParam->setValue(1.0f); // Start at full health if(_Model) { targetAngle = 0; targetPos = Vec2(0,0); _trailOffset = Vec2(0,-40); _Model->setScale(8); addChild(_Model); // _Model->setRotation3D(Vec3(90,0,0)); _radius = 40; _HP = 100; _alive = true; auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); listener->onTouchBegan = CC_CALLBACK_2(Player::onTouchBegan, this); listener->onTouchMoved = CC_CALLBACK_2(Player::onTouchMoved, this); listener->onTouchEnded = CC_CALLBACK_2(Player::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); //scheduleUpdate(); GameEntity::UseOutlineEffect(static_cast<Sprite3D*>(_Model), 0.02, Color3B(0,0,0)); schedule(schedule_selector(Player::shootMissile), 1.5, -1, 0); schedule(schedule_selector(Player::shoot), 0.075, -1, 0); // engine trail auto part_frame=SpriteFrameCache::getInstance()->getSpriteFrameByName("engine2.jpg"); ValueMap vm=ParticleManager::getInstance()->GetPlistData("engine"); auto part = ParticleSystemQuad::create(vm); part->setTextureWithRect(part_frame->getTexture(), part_frame->getRect()); addChild(part); part->setPosition(0,-30); part->setScale(0.6); //part->setRotation(90); //controller support ios and android #if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) //need include base/CCEventListenerController.h and base/CCController.h文件 auto controlListener = EventListenerController::create(); controlListener->onKeyDown = CC_CALLBACK_3(Player::onKeyDown,this); controlListener->onKeyUp = CC_CALLBACK_3(Player::onKeyUp,this); controlListener->onAxisEvent = CC_CALLBACK_3(Player::onAxisEvent,this); _eventDispatcher->addEventListenerWithSceneGraphPriority(controlListener,this); Controller::startDiscoveryController(); //init this->axisX = 0; this->axisY = 0; this->keyX = 0; this->keyY = 0; #endif return true; } return false; }
bool Label::multilineTextWrapByChar() { return multilineTextWrap(CC_CALLBACK_3(Label::getFirstCharLen, this)); }
bool Arcade::init(){ if(!Layer::init()){ return false; } //inicial tap_begin = Point::ZERO; visibleSize = Director::getInstance()->getVisibleSize(); origin = Director::getInstance()->getVisibleOrigin(); //dificultad setDelayRollBoard(DELAY_ROLL_BOARD); setDelayBeforeFall(DELAY_BEFORE_FALL); setDelayStopCombo(DELAY_STOP_COMBO); setRandomizeBall(DEFAULT_RANDOMIZE_BALL); setRowsStart(DEFAULT_ROWS_START); //objetivos setGoal(SCORE_WIN); setScoreWin(400); setComboWin(6); _stop = false; _goto_menu = false; _snd_take = String("musica y sonidos/baja.ogg"); _snd_drop = String("musica y sonidos/sube.ogg"); _snd_collide = String("musica y sonidos/choca_perla.ogg"); //set key this->setKeypadEnabled(true); background = Sprite::create("mapas/mapa1.png"); background->setPosition(Point( visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y ) ); this->addChild(background, -10); auto border = Sprite::create("efectos/barraArriba.png"); border->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height - border->getContentSize().height/4 + origin.y)); this->addChild(border, 9999); //iniciale el tablaro //y el populador del tablero board = Board::create(); Node* board_view = board->getView(); this->addChild(board_view); board_view->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); board->attachMatch(CC_CALLBACK_2(Arcade::onMatchSpheres, this)); board->attachFall(CC_CALLBACK_3(Arcade::onFallSpheres, this)); board->attachDropSphere(CC_CALLBACK_1(Arcade::onAnimateExploitSphere, this)); board->attachEndBoard(CC_CALLBACK_1(Arcade::onReachEndBoard,this)); board_populater = new BoardPopulaterRandom(board); board_populater->setStartRows(getRowsStart()); board_populater->populate(); board->setPopulater(board_populater); player = Indian::create(); player->retain(); Node* player_view = player->getView(); this->addChild(player_view); player->jumpTo(3); _score_label = LabelTTF::create("0000","default", 60); this->addChild(_score_label, 99999); _score_label->setPosition(Point(origin.x + _score_label->getContentSize().width, origin.y + visibleSize.height - _score_label->getContentSize().height/2)); //variables de juego setTimeStart(DEFAULT_TIME_START); _time = getTimeStart(); _clock_label = LabelTTF::create(String::createWithFormat("%02i", _time)->getCString(), "default", 60); this->addChild(_clock_label, 99999); _clock_label->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height + origin.y - _clock_label->getContentSize().height/3)); _time_over = false; _score = 0; setScoreCombo(DEFAULT_SCORE_COMBO); setScoreMatch(DEFAULT_SCORE_MATCH); auto dispatcher = Director::getInstance()->getEventDispatcher(); auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = CC_CALLBACK_2(Arcade::onTouchBegan, this); listener->onTouchMoved = CC_CALLBACK_2(Arcade::onTouchMoved, this); listener->onTouchEnded = CC_CALLBACK_2(Arcade::onTouchEnded, this); dispatcher->addEventListenerWithSceneGraphPriority(listener, this); this->schedule(schedule_selector(Arcade::updateBoard), 1.0f); CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(true); PLAY_MUSIC("musica y sonidos/juego.ogg"); _time_roll_board.initWithTarget(this, schedule_selector(Arcade::updateRollBoard)); _time_roll_board.setInterval(getDelayRollBoard()); _time_combo.initWithTarget(this, schedule_selector(Arcade::updateCombo)); _time_combo.setInterval(0.5f); _in_combo = false; _time_elapsed_combo = 0; //tutorial help_down = Sprite::create("tutorial/1paso.png"); help_down->retain(); help_up = Sprite::create("tutorial/2paso.png"); help_up->retain(); help_now = NULL; return true; }
void HandLayer::initNailLayer(WJLayer *oldLayer) { const Size &size = Director::getInstance()->getWinSize(); // 返回 m_back = WJButton::create("button/hand.png"); m_back->setPosition(oldLayer->getParent()->convertToNodeSpace(Vec2(size.width / 2 - 65, size.height - 50))); m_back->noClickMoveEffect(); m_back->setClickAniType(WJButton::ClickAniType::Scale); m_back->setNormalAniType(WJButton::NormalAniType::QBreathing); m_back->setOnClick(CC_CALLBACK_2(HandLayer::onClickBackButton, this)); m_back->setVisible(false); oldLayer->getParent()->addChild(m_back, 100); // 应用到所有 m_usedWhole = WJButton::create("button/hand.png"); m_usedWhole->setPosition(oldLayer->getParent()->convertToNodeSpace(Vec2(size.width / 2 + 65, size.height - 50))); m_usedWhole->noClickMoveEffect(); m_usedWhole->setClickAniType(WJButton::ClickAniType::Scale); m_usedWhole->setNormalAniType(WJButton::NormalAniType::QBreathing); m_usedWhole->setVisible(false); m_usedWhole->setOnClick(CC_CALLBACK_2(HandLayer::onClickUsedWholeButton, this)); oldLayer->getParent()->addChild(m_usedWhole, 100); // 擦除 m_earseSprite = WJSprite::create("game/03_minigame/p008/eraser.png"); m_earseSprite->setMoveAble(true); m_earseSprite->noClickMoveEffect(); m_earseSprite->setTouchSwallowsTouches(false); m_earseSprite->setPosition(oldLayer->getParent()->convertToNodeSpace(Vec2(180, 200))); m_earseSprite->setOnTouchAble(CC_CALLBACK_2(HandLayer::onEarseTouchAble, this)); m_earseSprite->setOnWillMoveTo(CC_CALLBACK_2(HandLayer::onEarseWillMoveTo, this)); m_earseSprite->setOnTouchEnded(CC_CALLBACK_2(HandLayer::onEarseTouchEnded, this)); m_earseSprite->setVisible(false); oldLayer->getParent()->addChild(m_earseSprite, 800); m_earseSprite->saveCurrentProperties(); // 笔刷 m_colorTool = WJSprite::create("game/03_minigame/p008/nailcolorbrush/001.png"); m_colorTool->setPosition(oldLayer->getParent()->convertToNodeSpace(Vec2(size.width - 330, 250))); m_colorTool->setUserTag(1); m_colorTool->setMoveAble(true); m_colorTool->noClickMoveEffect(); m_colorTool->setVisible(false); m_colorTool->setRotation(10); m_colorTool->setOnTouchAble(CC_CALLBACK_2(HandLayer::onColorToolTouchAble, this)); m_colorTool->setOnWillMoveTo(CC_CALLBACK_2(HandLayer::onColorToolWillMoveTo, this)); m_colorTool->setOnTouchEnded(CC_CALLBACK_2(HandLayer::onColorToolTouchEnded, this)); oldLayer->getParent()->addChild(m_colorTool, 800); m_colorTool->saveCurrentProperties(); // 选择弹窗 m_scrollLayer = ScrollDoubleLayer::create("P008_left_", ScrollDragDir::StopDrag, 3, true, P008ShowScrollIsFirstRun); m_scrollLayer->setClickScrollItemEvent(CC_CALLBACK_3(HandLayer::onClickScrollItemCallBack, this)); m_scrollLayer->setClickCancelItemEvent(CC_CALLBACK_3(HandLayer::onClickCancelItemCallBack, this)); m_scrollLayer->setClickMenuScrollItemEvent(CC_CALLBACK_3(HandLayer::onClickMenuScrollItemCallBack, this)); m_scrollLayer->setScrollItemTouchAbleEvent(CC_CALLBACK_3(HandLayer::onScrollItemTouchAble, this)); m_scrollLayer->setScrollItemDragOutCallBack(CC_CALLBACK_3(HandLayer::onScrollItemDragOutCallBack, this)); m_scrollLayer->setScrollItemMovingCollisionEvent(CC_CALLBACK_3(HandLayer::onScrollItemMovingCollision, this)); m_scrollLayer->setScrollItemTouchEndedEvent(CC_CALLBACK_3(HandLayer::onScrollItemTouchEnded, this)); m_scrollLayer->setScrollItemCollisonEndedEvent(CC_CALLBACK_3(HandLayer::onScrollItemCollisonEnded, this)); m_scrollLayer->setAutoDealCancel(AUTO_DEAL_CANCEL_START_INDEX, 2, AUTO_DEAL_CANCEL_END_INDEX); m_scrollLayer->setStackMaxNum(20); m_scrollLayer->setPosition(oldLayer->getParent()->convertToNodeSpace(Vec2(size.width + 300, size.height / 2 - 300))); oldLayer->getParent()->addChild(m_scrollLayer, 600); // 手环 m_wristScrollLayer = ScrollLayer::create("P008_bracelet_", ScrollDragDir::DragLeft, 10, true, s_firstWristLayer); m_wristScrollLayer->setClickScrollItemEvent(CC_CALLBACK_3(HandLayer::onClickWristStyleScrollItem, this)); //m_wristScrollLayer->setScrollItemMovingCollisionEvent(CC_CALLBACK_3(P008::onScrollStyleMovingCollision, this)); //m_wristScrollLayer->setScrollItemCollisonEndedEvent(CC_CALLBACK_3(P008::onScrollStyleCollisonEndedEvent, this)); m_wristScrollLayer->setPosition(oldLayer->getParent()->convertToNodeSpace(Vec2(size.width + 300, size.height / 2 - 300))); oldLayer->getParent()->addChild(m_wristScrollLayer, 600); m_wristScrollLayer->initItemSelectFromIndex(0); s_firstWristLayer = false; // 单个指甲 WJSprite *sprite = nullptr; NailLayer *layer = nullptr; for (int i = 0; i < 5; i++) { std::string key = WJUtils::stringAddInt("nail", i + 1); sprite = dynamic_cast<WJSprite*>(m_handLayer->getChildByName(key.c_str())); layer = NailLayer::create(sprite); layer->setNailNo(i + 1); layer->setNailStyleNo(4); layer->setName(key.c_str()); layer->_scrollLayer = m_scrollLayer; layer->setClickNormalNailCallBack(CC_CALLBACK_2(HandLayer::onClickNormalNail, this)); m_handLayer->addChild(layer, sprite->getLocalZOrder()); m_nailVector.pushBack(layer); sprite->removeFromParentAndCleanup(true); sprite = nullptr; } }
bool Player::init() { //_Model = EffectSprite3D::createFromObjFileAndTexture("playerv002.c3b", "playerv002_256.png"); _Model = Sprite::create("mplane0_0.png"); if(_Model) { targetAngle = 0; targetPos = Vec2(0,0); _trailOffset = Vec2(0,-40); //_Model->setScale(8); addChild(_Model); // _Model->setRotation3D(Vec3(90,0,0)); _radius = 40; _HP = 100; _alive = true; _shadowType = kShadowSky; //airscrew Vector<SpriteFrame*> frames; for (int i = 0; i < 2; i++) { auto pic = String::createWithFormat("mscrew0_%d.png", i); auto frame = SpriteFrame::create(pic->getCString(), Rect(0,0,85,71)); frames.pushBack(frame); } auto animation = Animation::createWithSpriteFrames(frames, 0.01f); auto animate = Animate::create(animation); auto screw = Sprite::createWithSpriteFrame(frames.at(0)); frames.clear(); /*screw->setPosition(_Model->getPositionX(), _Model->getPositionY()+_Model->getContentSize().height/2);*/ screw->runAction(RepeatForever::create(animate)); this->addChild(screw); ShadowController::createShadow(this); auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); listener->onTouchBegan = CC_CALLBACK_2(Player::onTouchBegan, this); listener->onTouchMoved = CC_CALLBACK_2(Player::onTouchMoved, this); listener->onTouchEnded = CC_CALLBACK_2(Player::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); //scheduleUpdate(); //GameEntity::UseOutlineEffect(static_cast<Sprite3D*>(_Model), 0.02, Color3B(0,0,0)); schedule(schedule_selector(Player::shootMissile), 1.5, -1, 0); schedule(schedule_selector(Player::shoot), 0.075, -1, 0); // engine trail /* auto part_frame=SpriteFrameCache::getInstance()->getSpriteFrameByName("engine2.jpg"); ValueMap vm=ParticleManager::getInstance()->GetPlistData("engine"); auto part = ParticleSystemQuad::create(vm); part->setTextureWithRect(part_frame->getTexture(), part_frame->getRect()); addChild(part); part->setPosition(0,-30); part->setScale(0.6);*/ //part->setRotation(90); //controller support ios and android #if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) //need include base/CCEventListenerController.h and base/CCController.h文件 auto controlListener = EventListenerController::create(); controlListener->onKeyDown = CC_CALLBACK_3(Player::onKeyDown,this); controlListener->onKeyUp = CC_CALLBACK_3(Player::onKeyUp,this); controlListener->onAxisEvent = CC_CALLBACK_3(Player::onAxisEvent,this); _eventDispatcher->addEventListenerWithSceneGraphPriority(controlListener,this); Controller::startDiscoveryController(); //init this->axisX = 0; this->axisY = 0; this->keyX = 0; this->keyY = 0; #endif return true; } return false; }
bool Label::multilineTextWrapByWord() { return multilineTextWrap(CC_CALLBACK_3(Label::getFirstWordLen, this)); }