void PumpkinEyes::doAction(float time) { stopAllActions(); runAction(blink); }
void ControllerPlayer::cdImg(float time, std::string name1, std::string name2, Button* but, float scale, MyEnum type) { CallFunc* cding; CallFunc* cded; ccdbut(); switch (type) { case attackcd: { cding = CallFunc::create([&](){attackisCD = true; }); cded = CallFunc::create([&](){attackisCD = false; }); this->scheduleOnce(schedule_selector(ControllerPlayer::oscdbut), 1.0f); PlayerAction(StringUtils::toString(attackType)); this->scheduleOnce(schedule_selector(ControllerPlayer::Cdskill), 0.8f); break; } case skillcd: { cding = CallFunc::create([&](){skillisCD = true; }); cded = CallFunc::create([&](){skillisCD = false; }); this->scheduleOnce(schedule_selector(ControllerPlayer::oacdbut), 1.2f); PlayerAction(StringUtils::toString(skillType)); this->scheduleOnce(schedule_selector(ControllerPlayer::Cdskill), 1.2f); break; } case bigskillcd: { cding = CallFunc::create([&](){ bigisCD = true; }); cded = CallFunc::create([&](){ bigisCD = false; }); this->scheduleOnce(schedule_selector(ControllerPlayer::obscdbut), 2.0f); PlayerAction(StringUtils::toString(skillType)); this->scheduleOnce(schedule_selector(ControllerPlayer::Cdskill), 1.2f); break; } case shangxiancd: { cding = CallFunc::create([&](){ sxisCD = true; }); cded = CallFunc::create([&](){ sxisCD = false; }); this->scheduleOnce(schedule_selector(ControllerPlayer::osxcdbut), 0.6f); m_player->sxskill(); this->scheduleOnce(schedule_selector(ControllerPlayer::Cdskill), 0.6f); break; } } SpriteFrameCache* frameCache = SpriteFrameCache::getInstance(); frameCache->addSpriteFramesWithFile("fight0.plist", "fight0.png"); Point thepoint = but->getPosition(); auto cds = Sprite::createWithSpriteFrameName(name2); cds->setPosition(thepoint); cds->setScale(scale, scale); addChild(cds, 3); auto funk = [cds, but]() { cds->setVisible(false); but->setEnabled(true); }; CallFunc* func = CallFunc::create(funk); auto cd = ProgressTimer::create(Sprite::createWithSpriteFrameName(name1)); cd->setType(ProgressTimer::Type::RADIAL); cd->setPosition(thepoint); cd->setScale(0.74, 0.74); auto to1 = Sequence::create(cding, ProgressTo::create(time, 100), ProgressTo::create(0, 0), func, cded, nullptr); cd->runAction(to1); addChild(cd, 4); }
Layout * Mx::createDialog(Node* child, Node * parent, Size innerSize, DialogBtn buttonStyle, string background){ auto layout = Layout::create(); auto size = parent->getContentSize(); auto dialogSize = Size(innerSize.width + 30, innerSize.height + 30); parent->addChild(layout, 999); layout->setContentSize(size); layout->setBackGroundColorType(cocos2d::ui::Layout::BackGroundColorType::SOLID); layout->setBackGroundColor(Color3B::BLACK); layout->setBackGroundColorOpacity(150); layout->setTouchEnabled(true); auto diaLayout = Layout::create(); layout->addChild(diaLayout); diaLayout->setContentSize(innerSize); diaLayout->setClippingEnabled(false); diaLayout->setAnchorPoint(Vec2::ANCHOR_MIDDLE); diaLayout->setPosition(Vec2(dialogSize.width/2, dialogSize.height/2)); diaLayout->setScale(0); diaLayout->setBackGroundImageScale9Enabled(true); if (background == "") { diaLayout->setBackGroundImage("sys_toast_b.png"); }else{ diaLayout->setBackGroundImage(background); } diaLayout->setPosition(size/2); if (child != nullptr) { diaLayout->addChild(child); } // set button; { if (buttonStyle.buttonNum != 0) { if (buttonStyle.closeText == "") { buttonStyle.closeText = this->getStrValue("close"); } auto buttonConfirm = this->createDialogButton(buttonStyle, buttonStyle.confirmText); auto buttonClose = this->createDialogButton(buttonStyle, buttonStyle.closeText); if (buttonStyle.buttonNum == 1) { buttonConfirm->setPosition(Vec2((dialogSize/2).width, 0)); diaLayout->addChild(buttonConfirm); }else{ Size size = buttonConfirm->getContentSize()/2; Size center = dialogSize/2; buttonConfirm->setPosition(Vec2(center.width - size.width, 0)); buttonClose->setPosition(Vec2(center.width + size.width, 0)); diaLayout->addChild(buttonConfirm); diaLayout->addChild(buttonClose); } } if (buttonStyle.isVisibleClose) { auto buttonClose = this->createDialogCloseButton(buttonStyle, buttonStyle.closeText, layout, diaLayout); diaLayout->addChild(buttonClose); buttonClose->setPosition(diaLayout->getContentSize() - buttonClose->getContentSize()/2 + Size(25, 25)); } } auto action = EaseBackOut::create(ScaleTo::create(.3, 1)); diaLayout->runAction(action); return layout; }
void Rolelayer::drawLeftlayer(){ float x_width= getDelwithint(200,0); layertag=Rolelayertag::left; if(this->getChildByTag(layer_left_tag)==nullptr){ left_layer=Layer::create(); left_layer->setContentSize(Size(Actual_x,Actual_y)); left_layer->setTag(layer_left_tag); left_layer->setPosition(Vec2(0,0)); addChild(left_layer); auto herobutton=MenuItemImage::create(hero_img,hero_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); herobutton->setPosition(Vec2(herobutton->getContentSize().width/2,getContentSize().height*0.8)); herobutton->setTag(Buton::hero_b); fillOuty(herobutton,hero_img); if(getUimove()==Isteachmove::teacher){ /* auto p_s=GuideLayer::createWithPrama(GuideLayer::MaskType::MaskType_Rectangle,herobutton->getPosition()); p_s->setSize(herobutton->getContentSize()); addChild(p_s); */ auto p=Sprite::create(teacher_shozhi); p->setAnchorPoint(Vec2(0.5,0.5)); p->setRotation(-90); p->setPosition(Vec2(herobutton->getContentSize().width,herobutton->getPositionY()+herobutton->getContentSize().height/2)); addChild(p); p->setGlobalZOrder(1000); p->runAction(RepeatForever::create(Sequence::create( FadeOut::create(0.5f),FadeIn::create(0.5f),nullptr))); } auto petbutton=MenuItemImage::create(pet_img,pet_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); petbutton->setPosition(Vec2(petbutton->getContentSize().width/2,getContentSize().height*0.60)); petbutton->setTag(Buton::pet_b); fillOuty(petbutton,pet_img); auto magicbutton=MenuItemImage::create(magic_img,magic_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); magicbutton->setPosition(Vec2(magicbutton->getContentSize().width/2,getContentSize().height*0.4)); magicbutton->setTag(Buton::magic_b); fillOuty(magicbutton,magic_img); auto menu=Menu::create( herobutton,petbutton,magicbutton, nullptr); menu->setPosition(Vec2::ZERO); menu->setTag(menu_zb1); left_layer->addChild(menu, 1000); tollgate_zb_menu=MenuItemImage::create(tollgatezbItem_img,tollgatezbItem_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); tollgate_zb_menu->setTag(Buton::tollgateItem_tag); tollgate_zb_menu->setPosition(Vec2(getContentSize().width*0.8,tollgate_zb_menu->getContentSize().height*0.5)); fillOuty(tollgate_zb_menu,tollgatezbItem_img); if(getUimove()!=Isteachmove::teacher) { auto armature =Armature::create("Run_UI_zhuye_anniu_xiaoguo"); armature->getAnimation()->play("chuxian",-1,1); armature->setPosition(Vec2(tollgate_zb_menu->getContentSize().width/2,tollgate_zb_menu->getContentSize().height/2)); tollgate_zb_menu->addChild(armature); } zb_menu=MenuItemImage::create(zb_img,zb_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); zb_menu->setTag(Buton::zb_b); zb_menu->setPosition(Vec2(tollgate_zb_menu->getPositionX(),tollgate_zb_menu->getPositionY()+zb_menu->getContentSize().height*1.2)); fillOuty(zb_menu,zb_img); auto menutag=Menu::create(tollgate_zb_menu,zb_menu,nullptr); menutag->setPosition(Vec2::ZERO); left_layer->addChild(menutag); auto back_img2=Sprite::create(tiao_img); back_img2->setTag(tiao_sp); back_img2->setAnchorPoint(Vec2(0,0)); back_img2->setPosition(Vec2(70,10));//zb_menu->getPositionY()-50)); left_layer->addChild(back_img2); auto hy_bt=MenuItemImage::create(hy_img,hy_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); hy_bt->setTag(hy_b); hy_bt->setPosition(Vec2(back_img2->getContentSize().width*0.23,back_img2->getContentSize().height*0.65)); fillOuty(hy_bt,hy_img); auto text_hy=Label::createWithSystemFont(FX::StringsMap::getValue("active"),"minijiankatong.ttf", 24); text_hy->setColor(yellow_c); text_hy->setPosition(Vec2(hy_bt->getPositionX(),back_img2->getContentSize().height*0.25)); back_img2->addChild(text_hy); auto xiaoxi_bt=MenuItemImage::create(xiaoxi_img,xiaoxi_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); xiaoxi_bt->setTag(msg_b); xiaoxi_bt->setPosition(Vec2(back_img2->getContentSize().width*0.4,back_img2->getContentSize().height*0.65)); fillOuty(xiaoxi_bt,xiaoxi_img); auto text_xx=Label::createWithSystemFont(FX::StringsMap::getValue("msg"),"minijiankatong.ttf", 24); text_xx->setColor(yellow_c); text_xx->setPosition(Vec2(xiaoxi_bt->getPositionX(),back_img2->getContentSize().height*0.25)); back_img2->addChild(text_xx); auto login_bt=MenuItemImage::create(denglu_img,denglu_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); login_bt->setTag(login_b); login_bt->setPosition(Vec2(back_img2->getContentSize().width*0.55,back_img2->getContentSize().height*0.65)); fillOuty(login_bt,denglu_img); auto text_lg=Label::createWithSystemFont(FX::StringsMap::getValue("logg"),"minijiankatong.ttf", 24); text_lg->setColor(yellow_c); text_lg->setPosition(Vec2(login_bt->getPositionX(),back_img2->getContentSize().height*0.25)); back_img2->addChild(text_lg); auto activ_bt=MenuItemImage::create(huodon_img,huodon_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); activ_bt->setTag(huodong_b); activ_bt->setPosition(Vec2(back_img2->getContentSize().width*0.72,back_img2->getContentSize().height*0.65)); fillOuty(activ_bt,huodon_img); auto text_ac=Label::createWithSystemFont(FX::StringsMap::getValue("huodong"),"minijiankatong.ttf", 24); text_ac->setColor(yellow_c); text_ac->setPosition(Vec2(activ_bt->getPositionX(),back_img2->getContentSize().height*0.25)); back_img2->addChild(text_ac); auto shezi_bt=MenuItemImage::create(shezi_img,shezi_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); shezi_bt->setTag(shezhi_b); shezi_bt->setPosition(Vec2(back_img2->getContentSize().width*0.88,back_img2->getContentSize().height*0.65)); fillOuty(shezi_bt,shezi_img); auto text_sz=Label::createWithSystemFont(FX::StringsMap::getValue("set"),"minijiankatong.ttf", 24); text_sz->setColor(yellow_c); text_sz->setPosition(Vec2(shezi_bt->getPositionX(),back_img2->getContentSize().height*0.25)); back_img2->addChild(text_sz); auto menu1=Menu::create(hy_bt,xiaoxi_bt,login_bt,activ_bt,shezi_bt, nullptr); menu1->setPosition(Vec2::ZERO); back_img2->addChild(menu1); //默认为减 oprate_bt=MenuItemImage::create(jia_img,jia_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); oprate_bt->setAnchorPoint(Vec2(0.5,0)); oprate_bt->setPosition(Vec2(oprate_bt->getContentSize().width/2,10));//zb_menu->getPositionY()-50)); oprate_bt->setLocalZOrder(100); oprate_bt->setTag(jian_mark); auto menu2=Menu::create(oprate_bt,nullptr); menu2->setPosition(Vec2::ZERO); menu2->setTag(menu_zb2); left_layer->addChild(menu2); allCallbackm(oprate_bt); } }
bool WelcomeScene::init() { if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); const float SCALE_TO_DEVICE = Director::getInstance()->getVisibleSize().width / DES_RES_X; auto welcomePic=Sprite::create("Starter_bg.png"); welcomePic->setPosition(Point(visibleSize.width/2+origin.x, visibleSize.height/2+origin.y)); welcomePic->setScaleX(visibleSize.width/welcomePic->getContentSize().width); welcomePic->setScaleY(visibleSize.height/welcomePic->getContentSize().height); this->addChild(welcomePic); auto gameTitleLabel= Label::createWithTTF("Halloween\n Candy Rush", "FEASFBRG.TTF", visibleSize.width * SCORE_FONT); gameTitleLabel->setColor(Color3B::YELLOW); gameTitleLabel->setPosition(Point(visibleSize.width/2+origin.x, visibleSize.height*0.75+origin.y)); this->addChild(gameTitleLabel,10); float scale_x=0.375; auto pp1=Sprite::create(); pp1->setScale(SCALE_TO_DEVICE); pp1->setPosition(Point(visibleSize.width*0.2+origin.x, visibleSize.height*scale_x+origin.y)); this->addChild(pp1,5); auto pp2=Sprite::create(); pp2->setScale(SCALE_TO_DEVICE); pp2->setPosition(Point(visibleSize.width*0.4+origin.x, visibleSize.height*scale_x+origin.y)); this->addChild(pp2,5); auto pp3=Sprite::create(); pp3->setScale(SCALE_TO_DEVICE); pp3->setPosition(Point(visibleSize.width*0.6+origin.x, visibleSize.height*scale_x+origin.y)); this->addChild(pp3,5); auto pp4=Sprite::create(); pp4->setScale(SCALE_TO_DEVICE); pp4->setPosition(Point(visibleSize.width*0.8+origin.x, visibleSize.height*scale_x+origin.y)); this->addChild(pp4,5); auto coin=Sprite::create("Candy (1).png"); coin->setScale(SCALE_TO_DEVICE); coin->setPosition(visibleSize.width*0.5+origin.x, visibleSize.height*0.5+origin.y); Vector<SpriteFrame*> an0(3); an0.pushBack(SpriteFrame::create("Candy (1).png", Rect(0,0,64,43))); an0.pushBack(SpriteFrame::create("Candy (2) 2.png", Rect(0,0,96,63))); an0.pushBack(SpriteFrame::create("Candy (3) 2.png", Rect(0,0,128,84))); auto ani0=Animation::createWithSpriteFrames(an0,0.2f); auto anim_00=Animate::create(ani0); auto anim_0=RepeatForever::create(anim_00); coin->runAction(anim_0); this->addChild(coin,4); for (float x=0;x<1.1;x=x+0.25) { for (float y=0;y<1.1;y=y+0.25) { if (y==0.25||y==0.5) { float pos_x=visibleSize.width*x+origin.x; float pos_y=visibleSize.height*y+origin.y; candy_matrix(pos_x, pos_y); } } } Vector<SpriteFrame*> an1(4); an1.pushBack(SpriteFrame::create("Idle (1).png", Rect(0,0,140,145))); an1.pushBack(SpriteFrame::create("Idle (2).png", Rect(0,0,140,145))); an1.pushBack(SpriteFrame::create("Idle (3).png", Rect(0,0,140,145))); an1.pushBack(SpriteFrame::create("Idle (4).png", Rect(0,0,140,145))); auto ani1=Animation::createWithSpriteFrames(an1,0.1f); auto anim_11=Animate::create(ani1); auto anim_1=RepeatForever::create(anim_11); pp1->runAction(anim_1); Vector<SpriteFrame*> an2(4); an2.pushBack(SpriteFrame::create("Launch Idle (1).png", Rect(0,0,111,139))); an2.pushBack(SpriteFrame::create("Launch Idle (2).png", Rect(0,0,101,139))); an2.pushBack(SpriteFrame::create("Launch Idle (3).png", Rect(0,0,101,139))); an2.pushBack(SpriteFrame::create("Launch Idle (4).png", Rect(0,0,101,139))); auto ani2=Animation::createWithSpriteFrames(an2,0.1f); auto anim_22=Animate::create(ani2); auto anim_2=RepeatForever::create(anim_22); pp2->runAction(anim_2); Vector<SpriteFrame*> an3(4); an3.pushBack(SpriteFrame::create("Launch Idle (1) 2.png", Rect(0,0,140,146))); an3.pushBack(SpriteFrame::create("Launch Idle (2) 2.png", Rect(0,0,140,146))); an3.pushBack(SpriteFrame::create("Launch Idle (3) 2.png", Rect(0,0,140,146))); an3.pushBack(SpriteFrame::create("Launch Idle (4) 2.png", Rect(0,0,140,146))); auto ani3=Animation::createWithSpriteFrames(an3,0.1f); auto anim_33=Animate::create(ani3); auto anim_3=RepeatForever::create(anim_33); pp3->runAction(anim_3); Vector<SpriteFrame*> an4(4); an4.pushBack(SpriteFrame::create("Launch Idle (1) 3.png", Rect(0,0,133,148))); an4.pushBack(SpriteFrame::create("Launch Idle (2) 3.png", Rect(0,0,133,148))); an4.pushBack(SpriteFrame::create("Launch Idle (3) 3.png", Rect(0,0,133,148))); an4.pushBack(SpriteFrame::create("Launch Idle (4) 3.png", Rect(0,0,133,148))); auto ani4=Animation::createWithSpriteFrames(an4,0.1f); auto anim_44=Animate::create(ani4); auto anim_4=RepeatForever::create(anim_44); pp4->runAction(anim_4); this->scheduleOnce(schedule_selector(WelcomeScene::GoToMainMenuScene), WELCOME_SCREEN_DISP_TIME); return true; }
// on "init" you need to initialize your instance bool SceneMain::init() { /** you can create scene with following comment code instead of using csb file. // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object auto closeItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(SceneMain::menuCloseCallback, this)); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24); // position the label on the center of the screen label->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height)); // add the label as a child to this layer this->addChild(label, 1); // add "SceneMain" splash screen" auto sprite = Sprite::create("SceneMain.png"); // position the sprite on the center of the screen sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(sprite, 0); **/ ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } // загрука ресурсов CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Plist.plist"); cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("Chudik/chudik.ExportJson"); cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("Battery/battery.ExportJson"); // создание сцены auto rootNode = CSLoader::createNode("SceneMain.csb"); // нажатие на button и label static_cast<TextBMFont *>(rootNode->getChildByName("BitmapFontSpd"))->addTouchEventListener(CC_CALLBACK_2(SceneMain::_buttonTouch, this)); static_cast<ImageView *>(rootNode->getChildByName("ImageButton"))->addTouchEventListener(CC_CALLBACK_2(SceneMain::_buttonTouch, this)); this->addChild(rootNode); ActionTimeline *action = CSLoader::createTimeline("SceneMain.csb"); rootNode->runAction(action); return true; }
bool GallaryList::init() { if (!Layer::init()) { return false; } visibleSize = Director::getInstance()->getVisibleSize(); thumbWidth = visibleSize.width/4; thumbSpace = visibleSize.width/3.5; currentThumb = 0; isClick = false; GallaryLayer::setGallaryState(0, true); GallaryLayer::setGallaryState(1, true); GallaryLayer::setGallaryState(3, true); GallaryLayer::setGallaryState(4, true); GallaryLayer::setGallaryState(5, true); GallaryLayer::setGallaryState(9, true); for (int i = 0; i != picCount; ++i) { char name[30]; sprintf(name, "gallary/gallary%d.png", i); auto listItem = Sprite::create(name); this->addChild(listItem); thumbs.push_back(listItem); listItem->setScale(thumbWidth/listItem->getContentSize().width, visibleSize.height/listItem->getContentSize().height/4); listItem->setPosition(Vec2(visibleSize.width/2+thumbSpace*i, 0)); if (!GallaryLayer::getGallaryState(i)) { listItem->setOpacity(100); } auto itemFrame = Sprite::create("frame/Data-Pic.png"); // TODO: need to be change this->addChild(itemFrame, -1); itemFrame->setPosition(Vec2(visibleSize.width/2+thumbSpace*i, 0)); itemFrame->setAnchorPoint(Point(0.5, 0.5)); itemFrame->setScale(thumbWidth/itemFrame->getContentSize().width*1.03, visibleSize.height/itemFrame->getContentSize().height/4*1.05); touchListener = EventListenerTouchOneByOne::create(); touchListener->setSwallowTouches(true); touchListener->onTouchBegan = [&, listItem](Touch *touch, Event *event) { isClick = true; event->getCurrentTarget()->stopActionByTag(tag_loadPic); startPoint = touch->getLocation(); movePoint = startPoint; // touch on list auto locationInNode = listItem->convertToNodeSpace(touch->getLocation()); auto rect = cocos2d::Rect(0, 0, listItem->getContentSize().width, listItem->getContentSize().height); if (rect.containsPoint(locationInNode)) { touchListener->setSwallowTouches(true); return true; } // touch on pic auto displayPic = static_cast<GallaryContent*>(this->getParent())->getDisplayPic(); auto locationInNode2 = displayPic->convertToNodeSpace(touch->getLocation()); auto rect2 = cocos2d::Rect(0, 0, displayPic->getContentSize().width*displayPic->getScaleX(), displayPic->getContentSize().height*displayPic->getScaleY()); if (rect2.containsPoint(locationInNode2)) { touchListener->setSwallowTouches(true); return true; } return false; }; touchListener ->onTouchMoved = [&](Touch *touch, Event *event) { auto currentPoint = touch->getLocation(); this->setPositionX(this->getPositionX() + currentPoint.x - movePoint.x); if (currentPoint.x - movePoint.x > 50 || currentPoint.x - movePoint.x < 100) { isClick = false; } movePoint = currentPoint; return true; }; touchListener->onTouchEnded = [&](Touch *touch, Event *event) { touchListener->setSwallowTouches(false); auto target = static_cast<GallaryList*>(event->getCurrentTarget()); currentThumb = static_cast<int>((event->getCurrentTarget()->getPositionX()-thumbSpace/2)/thumbSpace); // log("posx: %d", currentThumb); if (-currentThumb >= picCount) { currentThumb = -picCount + 1; } if (isClick) { auto displayPic = static_cast<GallaryContent*>(this->getParent())->getDisplayPic(); auto locationInNode = displayPic->convertToNodeSpace(touch->getLocation()); auto rect = cocos2d::Rect(0, 0, displayPic->getContentSize().width*displayPic->getScaleX(), displayPic->getContentSize().height*displayPic->getScaleY()); // open display mode if (rect.containsPoint(locationInNode) && GallaryLayer::getGallaryState(-currentThumb)) { // target->onPicClick(-currentThumb); this->onPicClick(-currentThumb); } } else { if (currentThumb >= 0) { target->runAction(MoveTo::create(0.2, Vec2(0, target->getPositionY()))); } else if (currentThumb < -picCount+1) { target->runAction(MoveTo::create(0.2, Vec2(thumbSpace*(-picCount+1), target->getPositionY()))); } else { target->runAction(MoveTo::create(0.2, Vec2(thumbSpace*currentThumb, target->getPositionY()))); } // target->thumbs.at(-currentThumb)->runAction(); // change pic target->onPicChange(-currentThumb); } return true; }; _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); } return true; }
bool GameGuide::init() { if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); const float SCALE_TO_DEVICE = Director::getInstance()->getVisibleSize().width / DES_RES_X; auto bk1 = Sprite::create("BG1.png"); float scaleRatio = visibleSize.width / bk1->getContentSize().width; bk1->setScale(scaleRatio, scaleRatio); bk1->setAnchorPoint(Point(0,0)); bk1->setPosition(Point(0, 0)); auto bk2 = Sprite::create("BG2.png"); bk2->setAnchorPoint( Point(0,0) ); bk2->setPosition( Point(0, bk1->getPositionY() + bk1->boundingBox().size.height -1) ); bk2->setScale(scaleRatio, scaleRatio); auto bk3 = Sprite::create("BG3.png"); bk3->setAnchorPoint( Point(0,0) ); bk3->setPosition( Point(0, bk2->getPositionY() + bk2->boundingBox().size.height -1) ); bk3->setScale(scaleRatio, scaleRatio); auto bk4 = Sprite::create("BG4.png"); bk4->setAnchorPoint( Point(0,0) ); bk4->setPosition( Point(0, bk3->getPositionY() + bk3->boundingBox().size.height -1) ); bk4->setScale(scaleRatio, scaleRatio); auto bk5 = Sprite::create("BG5.png"); bk5->setAnchorPoint( Point(0,0) ); bk5->setPosition( Point(0, bk4->getPositionY() + bk4->boundingBox().size.height -1) ); bk5->setScale(scaleRatio, scaleRatio); this->addChild(bk1, 0); this->addChild(bk2, 0); this->addChild(bk3, 0); this->addChild(bk4, 0); this->addChild(bk5, 0); auto MM=Sprite::create("Launch (1).png"); MM->setScale(SCALE_TO_DEVICE); MM->setPosition(Point(origin.x + visibleSize.width / 2, origin.y + visibleSize.height*0.2)); this->addChild(MM,10); Vector<SpriteFrame*> trix_ani(4); trix_ani.pushBack(SpriteFrame::create("Launch (1).png", Rect(0,0,280,289))); trix_ani.pushBack(SpriteFrame::create("Launch (2).png", Rect(0,0,280,289))); trix_ani.pushBack(SpriteFrame::create("Launch (3).png", Rect(0,0,280,289))); trix_ani.pushBack(SpriteFrame::create("Launch (4).png", Rect(0,0,280,289))); auto ani=Animation::createWithSpriteFrames(trix_ani,0.2f); auto anim_rr=Animate::create(ani); auto anim_r=RepeatForever::create(anim_rr); MM->runAction(anim_r); auto playItem = MenuItemImage::create("Blank.png", "Blank.png", CC_CALLBACK_1(GameGuide::GoToGameScene, this)); playItem->setScale(SCALE_TO_DEVICE); playItem->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height*0.5 + origin.y)); playItem->runAction(RotateBy::create(60, 3600)); auto menu = Menu::create(playItem,NULL); menu->setPosition(Point::ZERO); this->addChild(menu,11); auto game_title=Sprite::create("Launch.png"); game_title->setPosition(Point(visibleSize.width/2+origin.x, visibleSize.height*0.68 + origin.y)); game_title->setScale(SCALE_TO_DEVICE); this->addChild(game_title,10); /* auto gameTitleLabel= Label::createWithTTF("Tap/Drag to fly", "FEASFBRG.TTF", visibleSize.height * SCORE_FONT*0.7); gameTitleLabel->setColor(Color3B::YELLOW); gameTitleLabel->setPosition(Point(visibleSize.width/2+origin.x, visibleSize.height*0.6+origin.y)); this->addChild(gameTitleLabel,10); */ /* auto gameTitle= Label::createWithTTF("-> <-", "FEASFBRG.TTF", visibleSize.height * SCORE_FONT*0.5); gameTitle->setColor(Color3B::YELLOW); gameTitle->setPosition(Point(visibleSize.width/2+origin.x, visibleSize.height*0.5+origin.y)); this->addChild(gameTitle,10); */ return true; }
void FuelTank::supply(float delay) { FiniteTimeAction* move=MoveBy::create(0.2, Vec2(0, -150)); CallFunc* call=CallFunc::create(CC_CALLBACK_0(FuelTank::removeNode, this)); runAction(Sequence::create(move,call, NULL)); }
void BattleFieldUI::showGameOverUI() {//show the gameover UI when loss //diable AI //color layer auto layer = LayerColor::create(Color4B(255, 10, 10, 150)); layer->ignoreAnchorPointForPosition(false); layer->setPosition3D(Vec3(VisibleSize.width*0.5, VisibleSize.height*0.5, 0)); //add gameover auto gameOver = Sprite::create("battlefieldUI/gameover.png"); gameOver->setPosition3D(Vec3(VisibleSize.width*0.5, VisibleSize.height*0.5, 3)); gameOver->setScale(0.001); layer->addChild(gameOver, 1); layer->setGlobalZOrder(100); gameOver->setGlobalZOrder(100); auto listener = EventListenerTouchOneByOne::create(); //touch event listener->onTouchBegan = [](Touch*, Event*) { return true; }; listener->onTouchEnded = [this](Touch*, Event*) { //clear GlobalVaribals HeroPool.clear(); DragonPool.clear(); SlimePool.clear(); RatPool.clear(); BossPool.clear(); PigletPool.clear(); HeroManager.clear(); MonsterManager.clear(); GameMaster::reset(); //stop schedule currentLayer->unscheduleUpdate(); Director::getInstance()->getScheduler()->unschedule("gameController", currentLayer); //stop sound experimental::AudioEngine::stop(AUDIO_ID.BATTLEFIELDBGM); //replace scene Director::getInstance()->replaceScene(ChooseRoleScene::createScene()); }; gameOver->setCameraMask(2); auto eventDispatcher = layer->getEventDispatcher(); eventDispatcher->addEventListenerWithSceneGraphPriority(listener, layer); listener->setEnabled(false); auto enableListener = [=]() { listener->setEnabled(true); experimental::AudioEngine::stopAll(); experimental::AudioEngine::play2d("audios/effects/gameover.mp3"); }; //runaction auto action = Sequence::create(DelayTime::create(3), EaseElasticOut::create(ScaleTo::create(1.5, 1)), CallFunc::create(enableListener),NULL); gameOver->runAction(action); addChild(layer); }
void HelpLayer::onEnter(){ CCLayer::onEnter(); CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 1, true); runAction(CCMoveBy::create(0.3f, ccp(0, getContentSize().height - 80) / 2)); }
void Level13::restart(){ BaseLevel::restart(); #define MOVE_BY_X 192 auto r1 = Ring::create(); r1->setPosition(E::originX, E::originY + 128); r1->setScale(0.2); r1->initBody(); this->addChild(r1); r1->runAction(RepeatForever::create(Sequence::create(MoveBy::create(0.5f, Vec2(MOVE_BY_X, 0)), DelayTime::create(1.0f), MoveBy::create(0.5f, Vec2(-MOVE_BY_X, 0)), nullptr))); auto r2 = Ring::create(); r2->setPosition(E::originX + DESIGNED_WIDTH, E::originY + 128); r2->setScale(0.2); r2->initBody(); this->addChild(r2); r2->runAction(RepeatForever::create(Sequence::create(MoveBy::create(0.5f, Vec2(-MOVE_BY_X, 0)), DelayTime::create(1.0f),MoveBy::create(0.5f, Vec2(MOVE_BY_X, 0)), nullptr))); auto t1 = Target::create(); t1->setPosition(E::originX + DESIGNED_WIDTH / 2, E::originY + 400); t1->initBody(); t1->playAnim(1); this->addChild(t1); t1->initProtector(); /* auto b_l = Brick::create(E::originX + 96, 32); b_l->setPosition(0, E::originY + 32); b_l->setRotation(30); b_l->initBody(); this->addChild(b_l); auto b_r = Brick::create(E::originX + 96, 32); b_r->setPosition(E::originX + DESIGNED_WIDTH - 96, E::originY + 32); b_r->setRotation(-30); b_r->initBody(); this->addChild(b_r); */ ring1 = Ring::create(); ring1->setPosition(E::originX + DESIGNED_WIDTH / 2 - 80, E::originY + 400); ring1->setScale(0.1); ring1->initBody(); this->addChild(ring1); ring2 = Ring::create(); ring2->setPosition(E::originX + DESIGNED_WIDTH / 2 + 80, E::originY + 400); ring2->setScale(0.1); ring2->initBody(); this->addChild(ring2); auto diamond1 = Diamond::create(); diamond1->setScale(0.9f); diamond1->setRotation(30); diamond1->setPosition(E::originX - 128, E::originY + 256 + 64); diamond1->initBody(); this->addChild(diamond1); auto diamond2 = Diamond::create(); diamond2->setScale(0.9f); diamond2->setRotation(-30); diamond2->setPosition(E::originX + DESIGNED_WIDTH + 128, E::originY + 256 + 64); diamond2->initBody(); this->addChild(diamond2); angle = 0; }
void FloatingEffectManager::toast_help_tail(const cocos2d::Vec2& srcPos, const cocos2d::Vec2& desPos, const cocos2d::Color4F& color) { const float time = 0.2; float len = (desPos-srcPos).length(); if (len == 0) { return; } const float speed = len/time; auto _emitter = ParticleSystemQuad::createWithTotalParticles(500); _emitter->setAutoRemoveOnFinish(true); _layer->addChild(_emitter, 10); _emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("images/test_lizi.png")); _emitter->setDuration(time*5); // gravity _emitter->setGravity(Vec2::ZERO); // angle _emitter->setAngle(vector2angel(srcPos-desPos)); _emitter->setAngleVar(3); // speed of particles _emitter->setSpeed(speed/5); _emitter->setSpeedVar(0); // radial _emitter->setRadialAccel(0); _emitter->setRadialAccelVar(0); // tagential _emitter->setTangentialAccel(0); _emitter->setTangentialAccelVar(0); // emitter position // _emitter->setPosition( Vec2(160,240) ); _emitter->setPosVar({0,0}); // life of particles _emitter->setLife(0.2); _emitter->setLifeVar(0); // spin of particles _emitter->setStartSpin(720); _emitter->setStartSizeVar(360); _emitter->setEndSpin(0); _emitter->setEndSpinVar(360); // color of particles _emitter->setStartColor(color); Color4F startColorVar(0.f, 0.1f, 0.f, 0.1f); _emitter->setStartColorVar(startColorVar); _emitter->setEndColor(color); Color4F endColorVar(0.1f, 0.1f, 0.1f, 0.1f); _emitter->setEndColorVar(endColorVar); // size, in pixels _emitter->setStartSize(2.0f); _emitter->setStartSizeVar(1.0f); _emitter->setEndSize(ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE); // emits per second _emitter->setEmissionRate(_emitter->getTotalParticles()/_emitter->getLife()); // additive _emitter->setBlendAdditive(true); _emitter->setPosition(srcPos); _emitter->runAction(MoveTo::create(0.1, desPos)); }
Head_ParticalEffect void addParticalToHead(Node* node) { Vec2 pos[4]; pos[0] = Vec2(5, 75); pos[1] = Vec2(75, 75); pos[2] = Vec2(75, 5); pos[3] = Vec2(5, 5); for (int i = 0; i < 2; i++) { auto partNode = ParticleSystemQuad::createWithTotalParticles(60); partNode->setTexture(TextureCache::getInstance()->addImage("GameUI/CommonUI/fire.png"));//设置粒子图 partNode->setDuration(-1);//发射时长 // life of particles partNode->setLife(0.5f);//粒子生命 partNode->setLifeVar(0.1f); partNode->setEmissionRate(partNode->getTotalParticles() / partNode->getLife());//发射器发射频率 partNode->setPositionType(ParticleSystem::PositionType::FREE);//设置发射器的跟随模式 // color of particles partNode->setStartColor(ccc4f(0.76f, 0.25f, 0.12f, 1.0f));//起始颜色 partNode->setStartColorVar(ccc4f(0.1f, 0.1f, 0.1f, 0.0f)); partNode->setEndColor(ccc4f(1.0f, 1.0f, 1.0f, 1.0f));//结束颜色 partNode->setEndColorVar(ccc4f(0.1f, 0.1f, 0.1f, 0.1f)); // size, in pixels partNode->setStartSize(15);//粒子大小 partNode->setStartSizeVar(3); partNode->setEndSize(0); partNode->setEndSizeVar(3); // angle partNode->setAngle(0);//发射器角度 partNode->setAngleVar(0); // speed of particles partNode->setSpeed(0);//粒子速度 partNode->setSpeedVar(0); // emitter position partNode->setPosVar(ccp(0, 0));//发射器位置变化 partNode->setBlendAdditive(true); node->addChild(partNode); partNode->setTag(PARTICALTAG); auto move0 = MoveTo::create(1.f, pos[0]); auto move1 = MoveTo::create(1.f, pos[1]); auto move2 = MoveTo::create(1.f, pos[2]); auto move3 = MoveTo::create(1.f, pos[3]); if (i == 0) { partNode->setPosition(pos[0]); partNode->runAction(RepeatForever::create(Sequence::create(move1, move2, move3, move0, nullptr))); } else { partNode->setPosition(pos[2]); partNode->runAction(RepeatForever::create(Sequence::create(move3, move0, move1, move2, nullptr))); } } }
IntervalLayer::IntervalLayer() { _time0 = _time1 = _time2 = _time3 = _time4 = 0.0f; auto s = Director::getInstance()->getWinSize(); // sun auto sun = ParticleSun::create(); sun->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png")); sun->setPosition(VisibleRect::rightTop().x-32,VisibleRect::rightTop().y-32); sun->setTotalParticles(130); sun->setLife(0.6f); this->addChild(sun); // timers _label0 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0"); _label1 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0"); _label2 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0"); _label3 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0"); _label4 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0"); scheduleUpdate(); schedule([&](float dt){ _time1 +=dt; char str[10] = {0}; sprintf(str, "%2.1f", _time1); _label1->setString( str ); }, "step_1"); schedule([&](float dt){ _time2 +=dt; char str[10] = {0}; sprintf(str, "%2.1f", _time2); _label2->setString( str ); }, 0.5, "step_2"); schedule([&](float dt){ _time3 +=dt; char str[10] = {0}; sprintf(str, "%2.1f", _time3); _label3->setString( str ); }, 1, "step_3"); schedule([&](float dt){ _time4 +=dt; char str[10] = {0}; sprintf(str, "%2.1f", _time4); _label4->setString( str ); }, 2, "step_4"); _label0->setPosition(s.width*1/6, s.height/2); _label1->setPosition(s.width*2/6, s.height/2); _label2->setPosition(s.width*3/6, s.height/2); _label3->setPosition(s.width*4/6, s.height/2); _label4->setPosition(s.width*5/6, s.height/2); addChild(_label0); addChild(_label1); addChild(_label2); addChild(_label3); addChild(_label4); // Sprite auto sprite = Sprite::create(s_pathGrossini); sprite->setPosition(VisibleRect::left().x + 40, VisibleRect::bottom().y + 50); auto jump = JumpBy::create(3, Vec2(s.width-80,0), 50, 4); addChild(sprite); sprite->runAction( RepeatForever::create(Sequence::create(jump, jump->reverse(), nullptr) )); // pause button auto item1 = MenuItemFont::create("Pause", [&](Ref* sender) { if(Director::getInstance()->isPaused()) Director::getInstance()->resume(); else Director::getInstance()->pause(); }); auto menu = Menu::create(item1, nullptr); menu->setPosition(s.width/2, s.height-50); addChild( menu ); }
void LevelTwo::createFlames(float dt) { for (int i = 0; i < 9; i++) { auto spritecache = SpriteFrameCache::getInstance(); spritecache->addSpriteFramesWithFile("GameScreen/fireList.plist"); cocos2d::SpriteFrame* spriteFrame = spritecache->getSpriteFrameByName("fire1.png"); cocos2d::Vector<cocos2d::Sprite *> m_aiSprites; cocos2d::Vector<cocos2d::SpriteFrame*> m_animFrames; for (int j = 1; j < 27; j++) { // Get a SpriteFrame using a name from the spritesheet .plist file. m_animFrames.pushBack(spritecache->getSpriteFrameByName("fire" + std::to_string(j) + ".png")); } // Create the animation out of the frames. Animation* animation = Animation::createWithSpriteFrames(m_animFrames, 0.065); Animate* animate = Animate::create(animation); // Create a sprite using any one of the SpriteFrames // This is so we get a sprite of the correct dimensions. auto sprite = Sprite::createWithSpriteFrame(m_animFrames.at(0)); // Run and repeat the animation. sprite->setScale(2.0f); sprite->runAction(animate); auto fireBody = PhysicsBody::createBox(sprite->getContentSize(), PhysicsMaterial(0, 0, 0)); if (i == 0) { sprite->setPosition(Vec2(600, 420)); sprite->setTag(21); //fireBody->setCollisionBitmask(0x000101); //sprite->setPhysicsBody(fireBody); } else if (i == 1) { sprite->setPosition(Vec2(770, 420)); sprite->setTag(22); //fireBody->setCollisionBitmask(0x000201); //sprite->setPhysicsBody(fireBody); } else if (i == 2) { sprite->setPosition(Vec2(940, 420)); sprite->setTag(23); //fireBody->setCollisionBitmask(0x000301); //sprite->setPhysicsBody(fireBody); } else if (i == 3) { sprite->setPosition(Vec2(600, -20)); sprite->setTag(23); //fireBody->setCollisionBitmask(0x000301); //sprite->setPhysicsBody(fireBody); } else if (i == 4) { sprite->setPosition(Vec2(940, -20)); sprite->setTag(23); //fireBody->setCollisionBitmask(0x000301); //sprite->setPhysicsBody(fireBody); } else if (i == 5) { sprite->setPosition(Vec2(100, 260)); sprite->setTag(23); //fireBody->setCollisionBitmask(0x000301); //sprite->setPhysicsBody(fireBody); } else if (i == 6) { sprite->setPosition(Vec2(130, 130)); sprite->setTag(23); //fireBody->setCollisionBitmask(0x000301); //sprite->setPhysicsBody(fireBody); } else if (i == 7) { sprite->setPosition(Vec2(100, -20)); sprite->setTag(23); //fireBody->setCollisionBitmask(0x000301); //sprite->setPhysicsBody(fireBody); } else if (i == 8) { sprite->setPosition(Vec2(200, -20)); sprite->setTag(23); //fireBody->setCollisionBitmask(0x000301); //sprite->setPhysicsBody(fireBody); } this->addChild(sprite, 10); m_aiSprites.pushBack(sprite); if (dt == 5) { sprite->removeFromPhysicsWorld(); } for (int i = 0; i < m_aiSprites.size(); i++) { if (player->boundingBox().intersectsRect(sprite->boundingBox())) { playerOneDead = true; } if (player2->boundingBox().intersectsRect(sprite->boundingBox())) { playerTwoDead = true; } } //m_aiSprites.clear(); } }
bool StageSelect::init() { if (Layer::init()) { selected_cell = nullptr; s_playerConfig.overstage = 50; if(s_playerConfig.overstage >=50 ) { s_playerConfig.overstage = 50; fake_overstage = 49; } else fake_overstage = s_playerConfig.overstage; _selectItem = fake_overstage; _noTouch = true ; isCloseClick = true; auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); listener->onTouchBegan = [](Touch* touch, Event* event){ return true; }; _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); auto panelSize = Size(520,s_visibleRect.visibleHeight * 0.88f);//s_visibleRect.visibleWidth - 97 _cellSize.width = panelSize.width; _cellSize.height = 100; _panel = Scale9Sprite::create("mission.png"); _panel->setAnchorPoint(Point::ANCHOR_MIDDLE_TOP); _panel->setPosition(Point(s_visibleRect.center.x,s_visibleRect.top.y + panelSize.height)); _panel->setContentSize(panelSize); this->addChild(_panel); auto stageselect_text = TextSprite::create(s_gameStrings.mainMenu->stageselect.c_str()); stageselect_text->setAnchorPoint(Point::ANCHOR_MIDDLE); stageselect_text->setPosition(Point(panelSize.width/2, panelSize.height-170)); _panel->addChild(stageselect_text); //door effect. left_door = Sprite::create("door_l.png"); right_door = Sprite::create("door_r.png"); left_door->setScale(1.0f, 0.9f); right_door->setScale(1.0f, 0.9f); left_door->setAnchorPoint(Point::ANCHOR_MIDDLE_RIGHT); right_door->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); left_door->setPosition(Point(panelSize.width/2+25,panelSize.height/2-39)); right_door->setPosition(Point(panelSize.width/2-25,panelSize.height/2-39)); _panel->addChild(left_door,2); _panel->addChild(right_door,2); auto actionmovedone = CallFunc::create( [=](){ PLAY_OPENDOOR_EFFECT; auto size = left_door->getContentSize(); auto move = MoveBy::create(0.5, Point(-(size.width), 0)); left_door->runAction(move); left_door->runAction(ScaleTo::create(0.5, 0, 0.9f)); auto move1 = move->reverse(); right_door->runAction(move1); right_door->runAction(Sequence::create(ScaleTo::create(0.5, 0, 0.9f), CallFunc::create([=]() { PLAY_STAGELIST_EFFECT; isCloseClick = false; if(fake_overstage>2 && fake_overstage<47) tableView->setContentOffsetInDuration(tableView->getContentOffset() + Point(0,_cellSize.height*(fake_overstage-2)),fake_overstage*0.02f); else if(fake_overstage>=47) tableView->setContentOffsetInDuration(tableView->getContentOffset() + Point(0,_cellSize.height*45),46*0.02f); }), nullptr)); }); _panel->runAction(Sequence::create(MoveTo::create(0.15f,s_visibleRect.top), DelayTime::create(0.3f), actionmovedone,nullptr)); tableView = TableView::create(this, Size(panelSize.width, panelSize.height - 345)); tableView->setDirection(ScrollView::Direction::VERTICAL); tableView->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN); tableView->setPosition(Point(0,135)); tableView->setDelegate(this); tableView->reloadData(); _panel->addChild(tableView,0); tableView->setTouchEnabled(false); runAction(Sequence::create(DelayTime::create(1.0f),CallFunc::create([=](){tableView->setTouchEnabled(true);}), nullptr)); auto itemClosed = MenuItemImageLabel::createWithFrameName("back_0.png","back_1.png", CC_CALLBACK_1(StageSelect::menuCallbackClosed,this)); itemClosed->setAnchorPoint(Point::ANCHOR_TOP_RIGHT); itemClosed->setPosition((s_visibleRect.visibleWidth + panelSize.width)/2,panelSize.height); auto itemFight = MenuItemImageLabel::createWithFrameName("btA_0.png","btA_1.png", CC_CALLBACK_1(StageSelect::menuCallbackFight,this), s_gameStrings.mainMenu->stage_fight.c_str()); itemFight->setPosition(Point(panelSize.width / 2,77)); itemFight->setTextColor(Color3B(255, 255, 0)); auto menu = Menu::create( itemClosed, itemFight, nullptr); menu->setPosition(Point::ZERO); _panel->addChild(menu); addBall(); return true; } return false; }
void OrganizeContainer::openNewContainer(Kantai *kantai) { CallFunc* f1=CallFunc::create(CC_CALLBACK_0(OrganizeContainer::updateCharacterInfo, this,kantai)); CallFunc* f2=CallFunc::create(CC_CALLBACK_0(OrganizeContainerAction::setPankOpen, lKantaiDoor,rKantaiDoor,clippingNode,templateNode)); runAction(Sequence::create(f1,f2,DelayTime::create(0.35), NULL)); }
void AllianceFlagPar::createPar(std::string icon){ if(icon == "Blood.png"){ bloodPar(); } if(icon == "Snow.png"){ snowPar(); } if(icon == "Warhammer.png"){ warhammerPar(); } if(icon == "Tree.png"){ treePar(); } if(icon == "Cure.png"){ curePar(); } if(icon == "Death.png"){ deathPar(); } if(icon == "Fire.png"){ firePar(); } if(icon == "Ocean.png"){ oceanPar(); } if(icon == "Sun.png"){ sunPar(); } if(icon == "Wolf.png"){ wolfPar(); } if(icon == "Angel.png"){ m_partileNode = CCNode::create(); this->addChild(m_partileNode); for (int i=1; i<5; i++) { auto particle = ParticleController::createParticle(CCString::createWithFormat("FlagAngel_%d",i)->getCString()); particle->setPosition(0, 0); m_partileNode->addChild(particle); } } if(icon == "Cattle.png"){ m_partileNode = CCNode::create(); this->addChild(m_partileNode); for (int i=1; i<6; i++) { auto particle = ParticleController::createParticle(CCString::createWithFormat("FlagCattle_%d",i)->getCString()); particle->setPosition(0, 0); m_partileNode->addChild(particle); } } if(icon == "FireWolf.png"){ m_partileNode = CCNode::create(); this->addChild(m_partileNode); auto particle = ParticleController::createParticle("FireWolf_1"); particle->setPosition(-6, 18); m_partileNode->addChild(particle); particle = ParticleController::createParticle("FireWolf_2"); particle->setPosition(-12, 22); m_partileNode->addChild(particle); particle = ParticleController::createParticle("FireWolf_3"); particle->setPosition(6, 20); m_partileNode->addChild(particle); } if(icon == "Grail.png"){ m_partileNode = CCNode::create(); this->addChild(m_partileNode); for (int i=1; i<5; i++) { auto particle = ParticleController::createParticle(CCString::createWithFormat("FlagGrail_%d",i)->getCString()); particle->setPosition(0, 0); m_partileNode->addChild(particle); } } if(icon == "Knight.png"){ m_partileNode = CCNode::create(); this->addChild(m_partileNode); auto particle = ParticleController::createParticle("FlagDeath_4"); particle->setPosition(3, 17); m_partileNode->addChild(particle); particle = ParticleController::createParticle("FlagDeath_4"); particle->setPosition(-6, 21); m_partileNode->addChild(particle); particle = ParticleController::createParticle("FlagKnight_R"); particle->setPosition(48, -17); m_partileNode->addChild(particle); particle = ParticleController::createParticle("FlagKnight_L"); particle->setPosition(-50, -15); m_partileNode->addChild(particle); particle = ParticleController::createParticle("FlagKnight_1"); particle->setPosition(0, 18); m_partileNode->addChild(particle); particle = ParticleController::createParticle("FlagKnight_2"); particle->setPosition(0, -32); m_partileNode->addChild(particle); particle = ParticleController::createParticle("FlagKnight_3"); particle->setPosition(0, 91); m_partileNode->addChild(particle); particle = ParticleController::createParticle("FlagKnight_4"); particle->setPosition(-3, -40); m_partileNode->addChild(particle); particle = ParticleController::createParticle("FlagKnight_4"); particle->setPosition(-40, -60); m_partileNode->addChild(particle); particle = ParticleController::createParticle("FlagKnight_4"); particle->setPosition(-20, -54); m_partileNode->addChild(particle); particle = ParticleController::createParticle("FlagKnight_4"); particle->setPosition(45, -40); m_partileNode->addChild(particle); } if(icon == "Spain.png"){ m_spainWingNode = Node::create(); this->addChild(m_spainWingNode); auto wing = CCLoadSprite::createSprite("SpainWing.png"); wing->setPosition(-70,20); CCSequence *sequene = CCSequence::create(CCFadeTo::create(2, 102), CCFadeTo::create(2, 255), NULL); CCSequence *sequene1 = CCSequence::create(CCFadeTo::create(2, 102), CCFadeTo::create(2, 255), NULL); wing->runAction(CCRepeatForever::create(sequene)); m_spainWingNode->addChild(wing); wing = CCLoadSprite::createSprite("SpainWing.png"); wing->setFlippedX(true); wing->setPosition(70,20); wing->runAction(CCRepeatForever::create(sequene1)); m_spainWingNode->addChild(wing); m_partileNode = CCNode::create(); this->addChild(m_partileNode); auto particle = ParticleController::createParticle("Spain_1"); particle->setPosition(37, 0); m_partileNode->addChild(particle); particle = ParticleController::createParticle("Spain_2"); particle->setPosition(-46, 0); m_partileNode->addChild(particle); particle = ParticleController::createParticle("Spain_3"); particle->setPosition(0, 0); m_partileNode->addChild(particle); particle = ParticleController::createParticle("Spain_4"); particle->setPosition(0, 0); m_partileNode->addChild(particle); } }
void Player::update(float dt) { //////////爆風に当たってたらゲームオーバーにする/////////// if (scene->mapcontrol->getblock(getPosition())->firenull() == false) { gameover(); } ///////enterキーでボム設置/////////////// if (obsevekey->getkey((Observekey::Key)playerkey.bomset) == 2 && bomcon->getChildrenCount()<maximumbom) { bomset(); } //////主人公移動//////////////////////// //主人公がmoveアニメーションしていないとき if (getActionByTag(1) == nullptr) { static int x = 0, y = 0; if (obsevekey->getkey((Observekey::Key)playerkey.right) != 0) { if (x == 16 && y == 0) {} else { setTexture("シロボン右.png"); stopActionByTag(2); runAction(action[RIGHT]); x = 16; y = 0; } } else if (obsevekey->getkey((Observekey::Key)playerkey.left) != 0) { if (x == -16 && y == 0) {} else { setTexture("シロボン左.png"); stopActionByTag(2); runAction(action[LEFT]); x = -16; y = 0; } } else if (obsevekey->getkey((Observekey::Key)playerkey.up) != 0) { if (x == 0 && y == 16) {} else { setTexture("シロボン前.png"); stopActionByTag(2); runAction(action[FRONT]); x = 0; y = 16; } } else if (obsevekey->getkey((Observekey::Key)playerkey.down) != 0) { if (x == 0 && y == -16) {} else { setTexture("シロボン後.png"); stopActionByTag(2); runAction(action[BACK]); x = 0; y = -16; } } else { stopActionByTag(2); x = 0; y = 0; return; } //移動先に障害物がないとき if (scene->mapcontrol->getblock(Vec2(getPositionX() + x,getPositionY() + y))->obstaclecheck() == false) { //1ブロック分移動 auto move = MoveBy::create(speed, Vec2(x, y)); move->setTag(1); runAction(move); } } }
void Rolelayer::drawCenter(){ float x_width= getDelwithint(200,0); //魔法物 人物 宠物 string hero_str=ImageHelper::getUnitSpriteUIScene(hero.unit.ID)->getName(); auto hero_default=MenuItemImage::create(hero_str,hero_str,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); menus.push_back(hero_default); hero_default->setTag(hero_ab); hero_default->setNormalImage(ImageHelper::getUnitSpriteUIScene(hero.unit.ID)); hero_default->setSelectedImage(ImageHelper::getUnitSpriteUIScene(hero.unit.ID)); //hero_default->setScale(0.85f); hero_default->setAnchorPoint(Vec2(0.5,0.0)); string namekl=hero_default->getName(); hero_default->setPosition(Vec2(getContentSize().width*0.3+x_width,getContentSize().height*0.5)); hero_default->setOpacity(0.0f); Layer* h_l=Layer::create(); h_l->setTag(hero_layer); h_l->setPosition(hero_default->getPosition()); addChild(h_l,1000); jianls.push_back(h_l); string arExportName, armatureName, animationData; getActorInfor(hero.unit.ID, arExportName, armatureName, animationData); playAnimationByname(h_l,"xiaoxiao_NG.ExportJson","xiaoxiao_NG",animationData,true,false,Vec2(hero_default->getContentSize().width/2,50)); //阴影 MenuItemImage* hero_default1=nullptr; Layer* pet_l=nullptr; if(pet.unit.ID!=unitID_None){ pet_l=Layer::create(); pet_l->setTag(pet_layer); string hero_str=pet.unit.imageFile; CCLOG("---->%s",hero_str.c_str()); hero_default1=MenuItemImage::create(hero_str,hero_str,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); hero_default1->setTag(pet_ab); hero_default1->setNormalImage(Sprite::create(hero_str)); hero_default1->setSelectedImage(Sprite::create(hero_str)); hero_default1->setAnchorPoint(Vec2(0.0f,0.0f)); hero_default1->setOpacity(0.0f); string namekl=hero_default1->getName(); float pet_y=hero_default1->getPositionX()+hero_default1->getContentSize().width/2+hero_default1->getContentSize().width/2; float pet_yh=getContentSize().height*0.25; float pet_xh=getContentSize().width*0.1+x_width; // if(pet.unit.ID==unitID_PiPiZhu){ // //animationData="limao"; // pet_y=hero_default1->getPositionX()+hero_default1->getContentSize().width/1.5; // // }else if(pet.unit.ID==unitID_XiXiaoYang ){ // //animationData="xiaoxiong"; // pet_y=hero_default1->getPositionX()+hero_default1->getContentSize().width/2; // // }else if(pet.unit.ID==unitID_BuGuNiao ){ // //animationData="maotouying"; // pet_y=hero_default1->getPositionX()+hero_default1->getContentSize().width/2; // } hero_default1->setPosition(Vec2(pet_xh,pet_yh)); pet_l->setPosition(hero_default1->getPosition()); addChild(pet_l,1000); jianls.push_back(pet_l); menus.push_back(hero_default1); string arExportFilename, armatureName, animationName; getPetInfor(pet.unit.ID,arExportFilename, armatureName, animationName); playAnimationByname(pet_l,arExportFilename,armatureName,animationName,true,false,Vec2(hero_default1->getContentSize().width/2,50)); // // vector<Achieve> allacives=*AchievementHelper::getHelper()->getAllAchievement(); for(auto m:allacives){ bool isfinish=AchievementHelper::getHelper()->getAchieveByID(m.ID)->isOver; bool islq=AchievementHelper::getHelper()->getIsGotAchievement(m.ID); const AchieveSpecialAward* pa= AchievementHelper::getHelper()->getAchieveSpecialAwardInfo(m.ID); if(pa!=nullptr){ if(isfinish==true&&islq==false&&(pa->award_unitID>=unitID_PiPiZhu&&pa->award_unitID<unitID_PetEnd)){ bingbi=1; pet_l->setVisible(false); auto click=Sprite::create("UI_jiesuan_longdan.png"); click->setPosition(Vec2(getContentSize().width*0.3+x_width,getContentSize().height*0.65)); click->setTag(click_tag2); addChild(click); click->setLocalZOrder(1025); achiveId=m.ID; click->runAction(Sequence::create(Shake::create(0.5f,10), MoveTo::create(0.5f,Vec2(94,getContentSize().height*0.60)), ScaleTo::create(0.5f,0), CallFuncN::create(CC_CALLBACK_1(Rolelayer::Movedone,this)), nullptr)); break; } } } } MenuItemImage* hero_default2=nullptr; Layer* magic_l=nullptr; if(magic.unit.ID!=unitID_None){ magic_l=Layer::create(); magic_l->setTag(magic_layer); string magic_name="UI_modian_1.png"; magic_name=__String::createWithFormat("UI_modian_%d.png",magic.level)->getCString(); hero_default2=MenuItemImage::create(magic_name,magic_name,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); hero_default2->setTag(magic_ab); hero_default2->setOpacity(0); if(hero.unit.ID==unitID_Actor2){ hero_default2->setPosition(Vec2((getContentSize().width)*0.15+x_width,getContentSize().height*0.875)); }else{ hero_default2->setPosition(Vec2((getContentSize().width)*0.12+x_width,getContentSize().height*0.875)); } string animationData= CCString::createWithFormat("b_huxi%d", magic.level)->getCString(); magic_l->setPosition(hero_default2->getPosition()); addChild(magic_l,1000); jianls.push_back(magic_l); menus.push_back(hero_default2); playAnimationByname(magic_l,"book_ui.ExportJson","book_ui",animationData,true,false,Vec2(hero_default2->getContentSize().width/2,0)); } auto menu0=Menu::create(hero_default2,hero_default,hero_default1,nullptr); menu0->setPosition(Vec2::ZERO); menu0->setTag(menu_zb0); addChild(menu0,1000); }
/** create the menu, shuffle the cards and assign them to the player **/ void DeckScene::startGame() { readyMenu->setVisible(false); //initiate the outCard, callDiZhu, qiangDiZhu menu firstly if (outCardMenu == nullptr) { auto outCardItem = MenuItemImage::create("play_green_btn.png", "play_green_btn_down.png", CC_CALLBACK_0(DeckScene::outCard, this, 1)); auto disableOutItem = MenuItemImage::create("no_red_btn.png", "no_red_btn_down.png", CC_CALLBACK_0(DeckScene::outCard, this, 2)); outCardMenu = Menu::create(outCardItem, disableOutItem, nullptr); outCardMenu->alignItemsHorizontallyWithPadding(20); outCardMenu->setAnchorPoint(Vec2(0.5, 0.5)); outCardMenu->setPosition(origin.x + visible.width / 2, origin.y + visible.height / 2); addChild(outCardMenu); } outCardMenu->setVisible(false); if (callMenu == nullptr) { auto callItem = MenuItemImage::create("message_jiao.png", "message_jiao.png", CC_CALLBACK_0(DeckScene::callDiZhu, this, 1)); auto noCallItem = MenuItemImage::create("message_bu.png", "message_bu.png", CC_CALLBACK_0(DeckScene::callDiZhu, this, 2)); callMenu = Menu::create(callItem, noCallItem, nullptr); callMenu->alignItemsHorizontallyWithPadding(20); callMenu->setAnchorPoint(Vec2(0.5, 0.5)); callMenu->setPosition(origin.x + visible.width / 2, origin.y + visible.height / 2); addChild(callMenu); } callMenu->setVisible(false); if (robMenu == nullptr) { auto robItem = MenuItemImage::create("message_qiang.png", "message_qiang.png", CC_CALLBACK_0(DeckScene::callDiZhu, this, 3)); auto noRobItem = MenuItemImage::create("message_buQiang.png", "message_buQiang.png", CC_CALLBACK_0(DeckScene::callDiZhu, this, 4)); robMenu = Menu::create(robItem , noRobItem, nullptr); robMenu->alignItemsHorizontallyWithPadding(20); robMenu->setAnchorPoint(Vec2(0.5, 0.5)); robMenu->setPosition(origin.x + visible.width / 2, origin.y + visible.height / 2); addChild(robMenu); } robMenu->setVisible(false); //shuffle the cards randomly and assign them to the player randCards.clear(); for (int i = 0; i < 54; i++) { randCards.push_back(i); } random_shuffle(randCards.begin(), randCards.end()); player->sortCard(); //display the card of each player for (int i = 0; i < player->leftCard.size(); i++) { int interval = i - player->leftCard.size() / 2; float distance = cardIntervalHorizontal * interval; //log("first:%d, second:%f, distance:%d", (i - player->getLeftCard().size() / 2), cardIntervalHorizontal, distance); auto card = player->leftCard.at(i); card->setPosition(origin.x + visible.width / 2, origin.y + 100); if (i == player->leftCard.size() - 1) { card->runAction(Sequence::create(MoveBy::create(shuffleTime, Vec2(distance, 0)), CallFunc::create([=] { callMenu->setVisible(true); }), nullptr)); } else { card->runAction(MoveBy::create(shuffleTime, Vec2(distance, 0))); } //add the card in Sequence based on their value addChild(card); } }
void TwoSchedulers::onEnter() { SchedulerTestLayer::onEnter(); auto s = Director::getInstance()->getWinSize(); // rotate and jump auto jump1 = JumpBy::create(4, Vec2(0,0), 100, 4); auto jump2 = jump1->reverse(); auto seq = Sequence::create(jump2, jump1, NULL); auto action = RepeatForever::create(seq); // // Center // auto grossini = Sprite::create("Images/grossini.png"); addChild(grossini); grossini->setPosition(Vec2(s.width/2,100)); grossini->runAction(action->clone()); auto defaultScheduler = Director::getInstance()->getScheduler(); // // Left: // // Create a new scheduler, and link it to the main scheduler sched1 = new Scheduler(); defaultScheduler->scheduleUpdate(sched1, 0, false); // Create a new ActionManager, and link it to the new scheudler actionManager1 = new ActionManager(); sched1->scheduleUpdate(actionManager1, 0, false); for( unsigned int i=0; i < 10; i++ ) { auto sprite = Sprite::create("Images/grossinis_sister1.png"); // IMPORTANT: Set the actionManager running any action sprite->setActionManager(actionManager1); addChild(sprite); sprite->setPosition(Vec2(30+15*i,100)); sprite->runAction(action->clone()); } // // Right: // // Create a new scheduler, and link it to the main scheduler sched2 = new Scheduler();; defaultScheduler->scheduleUpdate(sched2, 0, false); // Create a new ActionManager, and link it to the new scheudler actionManager2 = new ActionManager(); sched2->scheduleUpdate(actionManager2, 0, false); for( unsigned int i=0; i < 10; i++ ) { auto sprite = Sprite::create("Images/grossinis_sister2.png"); // IMPORTANT: Set the actionManager running any action sprite->setActionManager(actionManager2); addChild(sprite); sprite->setPosition(Vec2(s.width-30-15*i,100)); sprite->runAction(action->clone()); } sliderCtl1 = sliderCtl(); addChild(sliderCtl1); sliderCtl1->retain(); sliderCtl1->setPosition(Vec2(s.width / 4.0f, VisibleRect::top().y - 20)); sliderCtl2 = sliderCtl(); addChild(sliderCtl2); sliderCtl2->retain(); sliderCtl2->setPosition(Vec2(s.width / 4.0f*3.0f, VisibleRect::top().y-20)); }
void DeckScene::callDiZhu(int flag) { std::string file; PokerCard* card1; PokerCard* card2; PokerCard* card3; switch (flag) { case 1: //call DiZhu callMenu->setVisible(false); file = "message1.png"; //assign the bottom cards to the player and display all the cards card1 = GameManager::getInstance()->rawCardArray.at(randCards.at(51)); card2 = GameManager::getInstance()->rawCardArray.at(randCards.at(52)); card3 = GameManager::getInstance()->rawCardArray.at(randCards.at(53)); log("Add before : %d", player->leftCard.size()); player->leftCard.push_back(card1); player->leftCard.push_back(card2); player->leftCard.push_back(card3); log("Add after: %d", player->leftCard.size()); card1->setVisible(false); card2->setVisible(false); card3->setVisible(false); addChild(card1); addChild(card2); addChild(card3); flashCard(); bottomCard1 = Sprite::createWithSpriteFrame(card1->getSpriteFrame()); bottomCard2 = Sprite::createWithSpriteFrame(card2->getSpriteFrame()); bottomCard3 = Sprite::createWithSpriteFrame(card3->getSpriteFrame()); bottomCard1->setAnchorPoint(pokerBack1->getAnchorPoint()); bottomCard2->setAnchorPoint(pokerBack2->getAnchorPoint()); bottomCard3->setAnchorPoint(pokerBack3->getAnchorPoint()); bottomCard1->setPosition(pokerBack1->getPosition()); bottomCard2->setPosition(pokerBack2->getPosition()); bottomCard3->setPosition(pokerBack3->getPosition()); bottomCard1->setScale(pokerBack1->getScale()); bottomCard2->setScale(pokerBack2->getScale()); bottomCard3->setScale(pokerBack3->getScale()); addChild(bottomCard1); addChild(bottomCard2); addChild(bottomCard3); isInGame = true; break; case 2: //No Call callMenu->setVisible(false); file = "message0.png"; break; case 3: robMenu->setVisible(false); file = "message3.png"; break; case 4: robMenu->setVisible(false); file = "message2.png"; break; default: return; } auto sprite = Sprite::create(file); sprite->setPosition(origin.x + visible.width / 2, origin.y + visible.height / 2); sprite->runAction(Sequence::create(DelayTime::create(1.0f), CallFunc::create([=] { sprite->removeFromParentAndCleanup(true); outCardMenu->setVisible(true); }), nullptr)); addChild(sprite); }
void runGripperAction(GenPR2SoftGripperAction &a) { a.reset(); try { runAction(a, BulletConfig::dt); } catch (...) { } }
void LevelListScene::_build() { cocos2d::Vec2 visibleOrigin = cocos2d::Director::getInstance()->getVisibleOrigin(); cocos2d::Size visibleSize = cocos2d::Director::getInstance()->getVisibleSize(); //auto background = cocos2d::Sprite::create("background.png"); //background->setAnchorPoint(cocos2d::Vec2::ZERO); //background->setPosition(cocos2d::Vec2::ZERO); //background->setOpacity(0); //addChild(background); //background->runAction(cocos2d::FadeIn::create(0.5)); auto levelPack = _game->getLevelPack(_packIndex); const std::vector<LevelPackEntry>& entries = levelPack->getEntries(); cocos2d::Rect menuRect(visibleOrigin.x + 100, visibleOrigin.y + 100, visibleSize.width - 200, visibleSize.height - 140); cocos2d::Size cellSize(menuRect.size.width / 5, menuRect.size.height / 5); cocos2d::Vec2 point(0, menuRect.size.height - cellSize.height); bool prevLevelCompleted = true; for (size_t i = 0; i + _startLevelIndex < entries.size() && i < 25; i++) { int levelIndex =_startLevelIndex + i; auto& record = _game->getHighscores()->getRecord(_packIndex, levelIndex); bool canStart = prevLevelCompleted || record.tried; auto button = cocos2d::ui::Button::create(canStart ? "slide-north-0001.png" : "floor.png", "", "", cocos2d::ui::Widget::TextureResType::PLIST); button->setAnchorPoint(cocos2d::Vec2(0.5f, 0.5f)); button->setPosition(menuRect.origin + point + cocos2d::Vec2(cellSize) * 0.5f - cocos2d::Vec2(0, 100)); button->setScale(0); button->setEnabled(canStart); button->addTouchEventListener([this, levelIndex](cocos2d::Ref* sender, cocos2d::ui::Widget::TouchEventType type) { if (type == cocos2d::ui::Widget::TouchEventType::ENDED) { auto director = cocos2d::Director::getInstance(); director->pushScene(LevelScene::create(_game, _packIndex, _startLevelIndex + levelIndex)); } }); if (canStart) { auto buttonLabel = cocos2d::Label::createWithTTF(std::to_string(i + 1), "fonts/Marker Felt.ttf", 24); buttonLabel->setPosition(cocos2d::Vec2(button->getContentSize()) * 0.5f); buttonLabel->setAnchorPoint(cocos2d::Vec2(0.5f, 0.5f)); buttonLabel->enableOutline(cocos2d::Color4B::BLACK, 2); button->addChild(buttonLabel); } addChild(button); if (record.completed) { auto star = cocos2d::Sprite::createWithSpriteFrameName("ic-chip.png"); star->setPosition(cocos2d::Vec2(button->getContentSize().width - 10, 11)); button->addChild(star); } if (i % 5 != 4) { point.x += cellSize.width; } else { point.x = 0; point.y -= cellSize.height; } button->runAction(cocos2d::Sequence::create( cocos2d::DelayTime::create(0.01 * i), cocos2d::Spawn::create( cocos2d::EaseBounceIn::create(cocos2d::ScaleTo::create(0.25, 1)), cocos2d::MoveBy::create(0.25, cocos2d::Vec2(0, 100)), nullptr ), nullptr )); prevLevelCompleted = record.completed; } /*auto backButton = cocos2d::MenuItemSprite::create(cocos2d::Sprite::create("boots-ice.png"), nullptr, CC_CALLBACK_1(LevelsScene::_backCallback, this)); backButton->setPosition(cocos2d::Vec2(100, 60)); menu->addChild(backButton);*/ }
void JigTile::setDirection(Direction dir) { float angle = dir.toint() * 90; runAction( RotateTo::create(0.1f, angle) ); }
//时间到 void infoLayer::timeOver() { //移除人 this->removeChildByTag(100); this->removeChildByTag(101); this->removeChildByTag(102); this->pause(); //提示版 auto bookSprite=Sprite::create("book_s.png"); bookSprite->setPosition(size.width/2,size.height/2); bookSprite->setScale(0, 0); this->addChild(bookSprite,1000); //分值 char scoreBuf[128]; sprintf(scoreBuf, "We get %d Stars!",score); auto scoreLabel=Label::createWithSystemFont(scoreBuf, "Marker Felt.ttf", 30); scoreLabel->setColor(Color3B::RED); scoreLabel->setPosition(Point(bookSprite->getContentSize().width/4,bookSprite->getContentSize().height-50)); bookSprite->addChild(scoreLabel); sprintf(scoreBuf, "Relation %d ",Relation); auto relationLabel=Label::createWithSystemFont(scoreBuf, "Marker Felt.ttf", 30); relationLabel->setColor(Color3B::RED); relationLabel->setPosition(Point(bookSprite->getContentSize().width/4,bookSprite->getContentSize().height-50-50)); bookSprite->addChild(relationLabel); sprintf(scoreBuf, "Growth %d ",growth); auto growtLabel=Label::createWithSystemFont(scoreBuf, "Marker Felt.ttf", 30); growtLabel->setColor(Color3B::RED); growtLabel->setPosition(Point(bookSprite->getContentSize().width/4,bookSprite->getContentSize().height-50-50-50)); bookSprite->addChild(growtLabel); //弹出效果 bookSprite->runAction(Sequence::create(ScaleTo::create(0, 0),ScaleTo::create(0.1, 0.2),ScaleTo::create(0.1, 0.5),ScaleTo::create(0.1, 0.8), ScaleTo::create(0.1, 1),NULL)); //确定按钮 auto okLabel=Label::createWithSystemFont("OK", "Marker Felt.ttf", 40); okLabel->setColor(Color3B::RED); auto okButton=MenuItemLabel::create(okLabel,CC_CALLBACK_1(infoLayer::goBackCallBack, this)); okButton->setPosition(bookSprite->getContentSize().width/4,bookSprite->getContentSize().height/4); auto menu=Menu::create(okButton, NULL); menu->setPosition(0,0); bookSprite->addChild(menu); //如果出现了星座 if (collensation!=0 && conllGeted==true) { auto boardSprite=Sprite::create("mark_2.png"); boardSprite->setPosition(size.width/2+bookSprite->getContentSize().width/4,size.height/2); boardSprite->setScale(0, 0); boardSprite->setRotation(-10); this->addChild(boardSprite,1001); boardSprite->runAction(Sequence::create(DelayTime::create(1.0f),ScaleTo::create(0, 1),ScaleTo::create(0.1, 0.8),ScaleTo::create(0.1, 0.6),ScaleTo::create(0.1, 0.5), NULL)); char conBuf[10]; sprintf(conBuf, "C%d.png",collensation); auto conSprite=Sprite::create(conBuf); conSprite->setPosition(boardSprite->getContentSize().width/2,boardSprite->getContentSize().height/2); conSprite->setScale(2.0f); boardSprite->addChild(conSprite); } }
void Test4::delay2(float dt) { auto node = static_cast<Sprite*>(getChildByTag(2)); auto action1 = RotateBy::create(1, 360); node->runAction(action1); }
//------------------------------------------------------------------ // // Billboard Rendering Test // //------------------------------------------------------------------ BillBoardTest::BillBoardTest() : _camera(nullptr) { //Create touch listener auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesMoved = CC_CALLBACK_2(BillBoardTest::onTouchesMoved, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); auto layer3D=Layer::create(); addChild(layer3D,0); _layerBillBorad=layer3D; auto s = Director::getInstance()->getWinSize(); if (_camera == nullptr) { _camera=Camera::createPerspective(60, (GLfloat)s.width/s.height, 1, 500); _camera->setCameraFlag(CameraFlag::USER1); _layerBillBorad->addChild(_camera); } //Create rotating billboards std::string imgs[3] = {"Images/Icon.png", "Images/r2.png"}; for (unsigned int i = 0; i < 4; ++i) { Layer *layer = Layer::create(); auto billboard = BillBoard::create(imgs[(unsigned int)(CCRANDOM_0_1() * 1 + 0.5)]); billboard->setScale(0.5f); billboard->setPosition3D(Vec3(0.0f, 0.0f, CCRANDOM_MINUS1_1() * 150.0f)); billboard->setOpacity(CCRANDOM_0_1() * 128 + 128); _billboards.push_back(billboard); layer->addChild(billboard); _layerBillBorad->addChild(layer); layer->runAction( RepeatForever::create( RotateBy::create( CCRANDOM_0_1() * 10, Vec3(0.0f, 45.0f, 0.0f) ) ) ); } { auto billboard = BillBoard::create("Images/Icon.png"); billboard->setScale(0.2f); billboard->setPosition3D(Vec3(0.0f, 30.0f, 0.0f)); auto billboard2 = BillBoard::create("Images/r2.png"); billboard2->setPosition3D(Vec3(0.0f, 0.0f, 100.0f)); billboard->addChild(billboard2); _billboards.push_back(billboard); _billboards.push_back(billboard2); auto sprite3d = Sprite3D::create("Sprite3DTest/orc.c3t"); sprite3d->setScale(2.0f); sprite3d->addChild(billboard); sprite3d->runAction( RepeatForever::create( RotateBy::create( 10.0f, Vec3(0.0f, 360.0f, 0.0f) ) ) ); _layerBillBorad->addChild(sprite3d); } addNewBillBoradWithCoords(Vec3(20,5,0)); addNewBillBoradWithCoords(Vec3(60,5,0)); addNewBillBoradWithCoords(Vec3(100,5,0)); addNewBillBoradWithCoords(Vec3(140,5,0)); addNewBillBoradWithCoords(Vec3(180,5,0)); addNewAniBillBoradWithCoords(Vec3(-20,0,0)); addNewAniBillBoradWithCoords(Vec3(-60,0,0)); addNewAniBillBoradWithCoords(Vec3(-100,0,0)); addNewAniBillBoradWithCoords(Vec3(-140,0,0)); addNewAniBillBoradWithCoords(Vec3(-180,0,0)); _camera->setPosition3D(Vec3(0, 100, 230)); _camera->lookAt(Vec3(0,0,0), Vec3(0,1,0)); TTFConfig ttfConfig("fonts/arial.ttf", 16); auto label1 = Label::createWithTTF(ttfConfig,"rotate+"); auto menuItem1 = MenuItemLabel::create(label1, CC_CALLBACK_1(BillBoardTest::rotateCameraCallback,this,10)); auto label2 = Label::createWithTTF(ttfConfig,"rotate-"); auto menuItem2 = MenuItemLabel::create(label2, CC_CALLBACK_1(BillBoardTest::rotateCameraCallback,this,-10)); auto menu = Menu::create(menuItem1, menuItem2, nullptr); menu->setPosition(Vec2::ZERO); menuItem1->setPosition( Vec2( s.width-80, VisibleRect::top().y-160) ); menuItem2->setPosition( Vec2( s.width-80, VisibleRect::top().y-190) ); addChild(menu, 0); _layerBillBorad->setCameraMask(2); label1 = Label::createWithTTF(ttfConfig,"Point Oriented"); menuItem1 = MenuItemLabel::create(label1,CC_CALLBACK_1(BillBoardTest::menuCallback_orientedPoint,this) ); label2 = Label::createWithTTF(ttfConfig,"Plane Oriented"); menuItem2 = MenuItemLabel::create(label2,CC_CALLBACK_1(BillBoardTest::menuCallback_orientedPlane,this) ); menuItem1->setPosition( Vec2( s.width-80, VisibleRect::top().y-100) ); menuItem2->setPosition( Vec2( s.width-80, VisibleRect::top().y-130) ); menu = Menu::create(menuItem1, menuItem2, nullptr); menu->setPosition(Vec2(0,0)); this->addChild(menu, 10); menuCallback_orientedPoint(nullptr); schedule(schedule_selector(BillBoardTest::update)); }