//------------------------------------------------------------------ // // SpriteProgressToVertical // //------------------------------------------------------------------ void SpriteProgressToVertical::onEnter() { SpriteDemo::onEnter(); auto s = Director::getInstance()->getWinSize(); auto to1 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0)); auto to2 = Sequence::createWithTwoActions(ProgressTo::create(2, 100), ProgressTo::create(0, 0)); auto left = ProgressTimer::create(Sprite::create(s_pathSister1)); left->setType(ProgressTimer::Type::BAR); // Setup for a bar starting from the bottom since the midpoint is 0 for the y left->setMidpoint(Vec2(0,0)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change left->setBarChangeRate(Vec2(0, 1)); addChild(left); left->setPosition(100, s.height/2); left->runAction( RepeatForever::create(to1)); auto right = ProgressTimer::create(Sprite::create(s_pathSister2)); right->setType(ProgressTimer::Type::BAR); // Setup for a bar starting from the bottom since the midpoint is 0 for the y right->setMidpoint(Vec2(0, 1)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change right->setBarChangeRate(Vec2(0, 1)); addChild(right); right->setPosition(s.width-100, s.height/2); right->runAction( RepeatForever::create(to2)); }
//------------------------------------------------------------------ // // SpriteProgressBarTintAndFade // //------------------------------------------------------------------ void SpriteProgressBarTintAndFade::onEnter() { SpriteDemo::onEnter(); auto s = Director::getInstance()->getWinSize(); auto to = Sequence::createWithTwoActions(ProgressTo::create(6, 100), ProgressTo::create(0, 0)); auto tint = Sequence::create(TintTo::create(1, 255, 0, 0), TintTo::create(1, 0, 255, 0), TintTo::create(1, 0, 0, 255), nullptr); auto fade = Sequence::create(FadeTo::create(1.0f, 0), FadeTo::create(1.0f, 255), nullptr); auto left = ProgressTimer::create(Sprite::create(s_pathSister1)); left->setType(ProgressTimer::Type::BAR); // Setup for a bar starting from the bottom since the midpoint is 0 for the y left->setMidpoint(Vec2(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change left->setBarChangeRate(Vec2(1, 0)); addChild(left); left->setPosition(100, s.height/2); left->runAction(RepeatForever::create(to->clone())); left->runAction(RepeatForever::create(tint->clone())); left->addChild(Label::createWithTTF("Tint", "fonts/Marker Felt.ttf", 20.0f)); auto middle = ProgressTimer::create(Sprite::create(s_pathSister2)); middle->setType(ProgressTimer::Type::BAR); // Setup for a bar starting from the bottom since the midpoint is 0 for the y middle->setMidpoint(Vec2(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change middle->setBarChangeRate(Vec2(1, 1)); addChild(middle); middle->setPosition(s.width/2, s.height/2); middle->runAction(RepeatForever::create(to->clone())); middle->runAction(RepeatForever::create(fade->clone())); middle->addChild(Label::createWithTTF("Fade", "fonts/Marker Felt.ttf", 20.0f)); auto right = ProgressTimer::create(Sprite::create(s_pathSister2)); right->setType(ProgressTimer::Type::BAR); // Setup for a bar starting from the bottom since the midpoint is 0 for the y right->setMidpoint(Vec2(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change right->setBarChangeRate(Vec2(0, 1)); addChild(right); right->setPosition(s.width-100, s.height/2); right->runAction(RepeatForever::create(to->clone())); right->runAction(RepeatForever::create(tint->clone())); right->runAction(RepeatForever::create(fade->clone())); right->addChild(Label::createWithTTF("Tint and Fade", "fonts/Marker Felt.ttf", 20.0f)); }
bool LSWProgressTimer::init() { if (!Layer::init()) { return false; } auto winSize = Director::getInstance()->getWinSize(); auto s = Sprite::create("yellowNum.png"); auto center = Vec2(winSize.width/2, winSize.height/2); auto progressTimer = ProgressTimer::create(s); addChild(progressTimer); progressTimer->setPosition(center); progressTimer->setTag(100); progressTimer->setType(ProgressTimer::Type::BAR); progressTimer->setBarChangeRate(Vec2(1, 0)); progressTimer->setMidpoint(Vec2(0, 0)); // progressTimer->setPercentage(50); // schedule(schedule_selector(LSWProgressTimer::scheduleProgressTimer), 0.5f); // progressTimer->runAction(ProgressTo::create(2.0f, 100)); return true; }
void GameLayer::initMembers() { std::vector<std::string> fileNames { "CardBlue.png", "CardRed.png", "CardGreen.png", "CardYellow.png", "CardPurple.png" }; std::vector<Character::Element> elements { Character::Element::Water, Character::Element::Fire, Character::Element::Wind, Character::Element::Holy, Character::Element::Shadow, }; for (int i = 0; i < fileNames.size(); i++) { //メンバー auto memberData = Character::create(); memberData->setMaxHp(200); memberData->setHp(200); memberData->setElement(elements[i]); _memberDatum.pushBack(memberData); //メンバーの表示 auto member = Sprite::create(fileNames[i].c_str()); member ->setPosition(Point(70 + i * 125, 598)); addChild(member, ZOrder::Char); //メンバーヒットポイントバー枠の表示 auto hpBg = Sprite::create("HpCardBackground.png"); hpBg->setPosition(Point(70 + i * 125, 554)); addChild(hpBg, ZOrder::CharHp); //メンバーヒットポイントバーの表示 auto hpBarForMember = ProgressTimer::create(Sprite::create("HpCardGreen.png")); hpBarForMember->setPosition(Point(hpBg->getContentSize().width / 2, hpBg->getContentSize().height / 2)); hpBarForMember->setType(ProgressTimer::Type::BAR); hpBarForMember->setMidpoint(Point::ZERO); hpBarForMember->setBarChangeRate(Point(1, 0)); hpBarForMember->setPercentage(memberData->getHpPercentage()); hpBg->addChild(hpBarForMember); //配列に格納 _members.pushBack(member); _hpBarForMembers.pushBack(hpBarForMember); } }
//------------------------------------------------------------------ // // SpriteProgressWithSpriteFrame // //------------------------------------------------------------------ void SpriteProgressWithSpriteFrame::onEnter() { SpriteDemo::onEnter(); auto s = Director::getInstance()->getWinSize(); auto to = Sequence::createWithTwoActions(ProgressTo::create(6, 100), ProgressTo::create(0, 0)); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("zwoptex/grossini.plist"); auto left = ProgressTimer::create(Sprite::createWithSpriteFrameName("grossini_dance_01.png")); left->setType(ProgressTimer::Type::BAR); // Setup for a bar starting from the bottom since the midpoint is 0 for the y left->setMidpoint(Vec2(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change left->setBarChangeRate(Vec2(1, 0)); addChild(left); left->setPosition(100, s.height/2); left->runAction(RepeatForever::create(to->clone())); auto middle = ProgressTimer::create(Sprite::createWithSpriteFrameName("grossini_dance_02.png")); middle->setType(ProgressTimer::Type::BAR); // Setup for a bar starting from the bottom since the midpoint is 0 for the y middle->setMidpoint(Vec2(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change middle->setBarChangeRate(Vec2(1, 1)); addChild(middle); middle->setPosition(s.width/2, s.height/2); middle->runAction(RepeatForever::create(to->clone())); auto right = ProgressTimer::create(Sprite::createWithSpriteFrameName("grossini_dance_03.png")); right->setType(ProgressTimer::Type::RADIAL); // Setup for a bar starting from the bottom since the midpoint is 0 for the y right->setMidpoint(Vec2(0.5f, 0.5f)); // Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change right->setBarChangeRate(Vec2(0, 1)); addChild(right); right->setPosition(s.width-100, s.height/2); right->runAction(RepeatForever::create(to->clone())); }
bool ProgressTimer::initWithSprite(Sprite* sp) { setPercentage(0.0f); _vertexData = NULL; _vertexDataCount = 0; setAnchorPoint(Point(0.5f,0.5f)); _type = Type::RADIAL; _reverseDirection = false; setMidpoint(Point(0.5f, 0.5f)); setBarChangeRate(Point(1,1)); setSprite(sp); // shader program setShaderProgram(ShaderCache::getInstance()->programForKey(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return true; }
bool CCProgressTimer::initWithSprite(CCSprite* sp) { setPercentage(0.0f); m_pVertexData = NULL; m_nVertexDataCount = 0; setAnchorPoint(ccp(0.5f,0.5f)); m_eType = kCCProgressTimerTypeRadial; m_bReverseDirection = false; setMidpoint(ccp(0.5f, 0.5f)); setBarChangeRate(ccp(1,1)); setSprite(sp); // shader program setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); return true; }
bool ProgressTimer::initWithSprite(Sprite* sp) { setPercentage(0.0f); _vertexData = nullptr; _vertexDataCount = 0; setAnchorPoint(Vector2(0.5f,0.5f)); _type = Type::RADIAL; _reverseDirection = false; setMidpoint(Vector2(0.5f, 0.5f)); setBarChangeRate(Vector2(1,1)); setSprite(sp); // shader state setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return true; }
bool CCastleHpBar::init(){ if(!ProgressTimer::init())return false; Sprite* sp = Sprite::create(""); setSprite(sp); setPercentage(100); setType(ProgressTimerType::BAR); setBarChangeRate(Vec2(-1,0)); setMidpoint(Vec2(1,0)); scheduleUpdate(); return true; }
bool Loading::init() { textureCacheArray = __Array::create(); textureCacheArray->retain(); mpFontChina = FontChina::getInstance(); mpFontChina->initStringXml(); auto spriteBG = Sprite::create("TempPic/Loading/loading1.png"); spriteBG->setPosition(Point(400, 240)); this->addChild(spriteBG); auto size = Director::getInstance()->getVisibleSize(); auto spriteProgress = Sprite::create("TempPic/Loading/Loading.png"); auto progressBar = ProgressTimer::create(spriteProgress); progressBar->setType(ProgressTimer::Type::BAR); progressBar->setMidpoint(Point::ANCHOR_BOTTOM_LEFT); progressBar->setBarChangeRate(Point::ANCHOR_BOTTOM_RIGHT); progressBar->setPosition(Point(size.width / 2, 0 + 80)); progressBar->setPercentage(0); this->addChild(progressBar, 10, PROGRESSTAG); auto sprite2 = Sprite::create("TempPic/Loading/LoadingBG.png"); sprite2->setPosition(Point(size.width / 2, 0 + 80)); this->addChild(sprite2, 2); auto label = Label::create(); label->setPosition(Point(400, 40)); label->setSystemFontSize( 20.0f ); this->addChild(label, 10); auto nameString = __String::createWithFormat("Loading%d", ToolFunc::calcRandom(1, 19)); auto labelString = __String::createWithFormat("%s", mpFontChina->getComString(nameString->getCString())->getCString()); label->setString(labelString->getCString()); return true; }
void StartScene::addTarget() { DataModel *m = DataModel::getModel(); Wave *wave = this->getCurrentWave(); if(wave==nullptr) this->cleanup(); if (wave->totalCreeps <= 0) { if (m->targets.size()==0) getNextWave(); return; } wave->totalCreeps--; Creep *target = NULL; /* int random = rand()%3; if (random == 0) { target = FastGrayCreep::creep(m->waypoints.size()); } else if(random == 1) { target = StrongGreenCreep::creep(m->waypoints.size()); } else { target = MonsterYellowCreep::creep(m->waypoints.size()); } */ target = Creep::createWithType(wave->creeptype,m->waypoints.size(),true); WayPoint *waypoint = target->getCurrentWaypoint(); target->setPosition(waypoint->getPosition()); waypoint = target->getNextWaypoint(); auto lifeBar = CCProgressTimer::create(CCSprite::create("loginbg.png")); lifeBar->setType(kCCProgressTimerTypeBar); lifeBar->setPercentage(100.0f); lifeBar->setBarChangeRate(ccp(1, 0));//水平方向 lifeBar->setMidpoint(ccp(0,0));//设置起始点为左下方 lifeBar->setPosition(target->sprite->getPosition().x, target->sprite->getPosition().y+60); lifeBar->setScaleY(0.6); lifeBar->setScaleX(0.3); target->addChild(lifeBar,1); target->lifeBar = lifeBar; auto emptyLifeBar = Sprite::create("login_dbg.png"); emptyLifeBar->setScaleX(0.3); emptyLifeBar->setScaleY(0.3); emptyLifeBar->setPosition(lifeBar->getPosition()); target->addChild(emptyLifeBar,0); target->emptyLifeBar = emptyLifeBar; this->addChild(target, 1); int moveDuration = target->moveDuration; auto actionMove = CCMoveTo::create(moveDuration, waypoint->getPosition()); auto lifeBarActionMove = MoveTo::create(moveDuration, ccp(waypoint->getPosition().x,waypoint->getPosition().y+25)); auto actionMoveDone = CallFuncN::create(this, callfuncN_selector(StartScene::FollowPath)); target->runAction(CCSequence::create(actionMove, actionMoveDone, NULL)); // lifeBar->runAction(CCSequence::create(lifeBarActionMove, NULL)); target->tag = 1; m->targets.pushBack(target); }
void ProgressBarNode::SetProtoData( const CoreProto::Editor::ProgressBar& val ) { mProtoData = val; SetName(val.id()); CCSprite* sprite=new CCSprite(); sprite->autorelease(); FileSystemOrderItem* orderItem=ResourceManager::Instance().InitSprite(sprite,val.image(),val.size()); if (orderItem==NULL) { Log::LogErrorFormat("ProgressBarNode:Cannot find image:%s",val.image().file().name().c_str()); return; } if(!initWithSprite(sprite)) { Log::LogErrorFormat("Cannot init progress bar:%s",val.id().c_str()); return; } Point2F offset=orderItem->GetOffsetOrZero(); Size2F originalSize=orderItem->GetOriginalSizeOrZero(); Point2F newAnchorPoint=Point2F(val.anchor().x(),val.anchor().y()); if (offset!=Point2F::Zero) { CCSize contentSize=getContentSize(); newAnchorPoint= LayerEditor::CalculateAnchor(newAnchorPoint,offset,Size2F(contentSize.width,contentSize.height),Size2F(contentSize.width,contentSize.height)); } //setFlipX(val.isfilpx()); //setFlipY(val.isfilpy()); setZOrder(val.zorder()); setVisible(val.isvisible()); setAnchorPoint(ccp(newAnchorPoint.X,newAnchorPoint.Y)); if (val.has_scale()) { setScaleX(val.scale().x()); setScaleY(val.scale().y()); } else { setScale(1.f); } setRotation(val.rotation()); SetRenderFlag((RenderFlag)val.renderflag()); if (val.isproportionpoint()) { CCSize winSize= CCDirector::sharedDirector()->getWinSizeInPixels(); setPosition(ccp(val.position().x()*winSize.width,val.position().y()*winSize.height)); } else { setPosition(ccp(val.position().x(),val.position().y())); } setPercentage(100.f); setType((CCProgressTimerType)val.type()); CCPoint midPos = ccp(val.midpoint().x(),val.midpoint().y()); if (getType() == kCCProgressTimerTypeRadial) { midPos.x = Math::Clamp(midPos.x,0.001f,0.9999f); midPos.y = Math::Clamp(midPos.y,0.001f,0.9999f); } setMidpoint(midPos); setBarChangeRate(ccp(val.changerate().x(),val.changerate().y())); setTag(val.tag()); }
void GateResult::resetUI()//初始化界面 { Widget* img_bg=(Widget*)layout->getChildByName("img_bg"); img_bg->setVisible(true); bool isWin=this->pResultResp.star()!=0; Widget* img_win=(Widget*)img_bg->getChildByName("img_win"); Widget* img_lose=(Widget*)img_bg->getChildByName("img_lose"); img_win->setVisible(isWin); img_lose->setVisible(!isWin); Button* btn_return=(Button*)layout->getChildByName("btn_return"); btn_return->setVisible(true); btn_return->addTouchEventListener(CC_CALLBACK_2(GateResult::touchButtonEvent, this)); Text* tf_groupLvl=static_cast<Text*>(img_bg->getChildByName("tf_groupLvl")); Text* tf_groupExp=static_cast<Text*>(img_bg->getChildByName("tf_groupExp")); Text* tf_coin=static_cast<Text*>(img_bg->getChildByName("tf_coin")); tf_groupLvl->setString(Value(this->pResultResp.curgrouplvl()).asString()); tf_groupExp->setString(StringUtils::format("+%d",this->pResultResp.groupexp())); tf_coin->setString(StringUtils::format("+%d",this->pResultResp.coin())); for(int i=1;i<=3;i++){ Node* star=img_bg->getChildByName("star_"+Value(i).asString()); star->setVisible(i<=this->pResultResp.star()); } for (int i=0; i<5; i++) { Widget* npc=static_cast<Widget*>(img_bg->getChildByName("role_"+Value(i+1).asString())); ImageView* item=static_cast<ImageView*>(img_bg->getChildByName("item_"+Value(i+1).asString())); npc->setVisible(i<this->pResultResp.npcs_size()); item->setVisible(i<this->pResultResp.items_size()); if (i<this->pResultResp.npcs_size()) { PNpcRes pNpcRes=this->pResultResp.npcs(i); string addLevel=Value(pNpcRes.addlvl()).asString(); string addExp=Value(pNpcRes.addexp()).asString(); int totalLvl=pNpcRes.curlvl()+pNpcRes.addlvl(); int oldExp=Manager::getInstance()->getCurrExp(pNpcRes.curexp(), pNpcRes.curlvl()); int currExp=Manager::getInstance()->getCurrExp(pNpcRes.curexp()+pNpcRes.addexp(), totalLvl); int neddExp=XExp::record(Value(totalLvl))->getExp(); float oldPrecent=float(oldExp*100/neddExp); float curPrecent=float(currExp*100/neddExp); static_cast<TextAtlas*>(npc->getChildByName("txt_lvl"))->setString(Value(totalLvl).asString()); auto action = ProgressTo::create(abs(curPrecent-oldExp)/100, curPrecent); LoadingBar* loadingBar=static_cast<LoadingBar*>(npc->getChildByName("pro_exp")); loadingBar->setVisible(false); auto progressTimer = ProgressTimer::create(static_cast<Sprite*>(loadingBar->getVirtualRenderer())); progressTimer->setType(ProgressTimer::Type::BAR); progressTimer->setPosition(loadingBar->getPosition()); npc->addChild(progressTimer); //Setup for a bar starting from the left since the midpoint is 0 for the x progressTimer->setMidpoint(Vec2(0,0)); //Setup for a horizontal bar since the bar change rate is 0 for y meaning no vertical change progressTimer->setBarChangeRate(Vec2(1, 0)); progressTimer->setPercentage(oldPrecent>curPrecent?0:oldExp); progressTimer->runAction(action); static_cast<Text*>(npc->getChildByName("txt_addExp"))->setString(StringUtils::format("EXP+%d",pNpcRes.addexp())); if(pNpcRes.addlvl()>0){ Clip* clip=Clip::create("levelUp.plist", "levelUp",8); clip->setPosition(npc->getContentSize().width/2-5,npc->getContentSize().height/2-7); clip->play(true); npc->addChild(clip); } //loadingBar->setPercent(50); //static_cast<Text*>(npc->getChildByName("txt_exp"))->setString(Utils::getLang("EXP+{1}",params)); //pNpcRes } if (i<this->pResultResp.items_size()) { PItemRes pItemRes=this->pResultResp.items(i); static_cast<Text*>(item->getChildByName("txt_num"))->setString(Value(pItemRes.itemnum()).asString()); XItem* xItem=XItem::record(Value(pItemRes.itemid())); item->loadTexture("item_"+Value(xItem->getIcon()).asString()+".png"); item->addTouchEventListener(CC_CALLBACK_2(GateResult::touchItemEvent, this)); item->setTouchEnabled(true); item->setTag(pItemRes.itemid()); Manager::getInstance()->showMsg(StringUtils::format("获得%sX%d",xItem->getName().c_str(),pItemRes.itemnum())); } } }
void GameGuiLayer::update(float dt){ if (GAMEDATA::getInstance()->updateScore){ GAMEDATA::getInstance()->updateScore = false; updateScore(); } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto right = ProgressTimer::create(Sprite::create("progressbar.png")); right->setType(ProgressTimer::Type::BAR); right->setScaleY(0.95f); right->setPosition(240, 712); auto to4 = ProgressTo::create(GAMEDATA::getInstance()->gettime(), 0); right->setMidpoint(ccp(0, 0)); right->setBarChangeRate(ccp(1, 0)); right->setPercentage(GAMEDATA::getInstance()->gettime() * 10); this->addChild(right, 0); right->runAction(to4); //add addtime auto addtime = Menu::create(); auto spriteNomal = Sprite::create("addtime.png"); spriteNomal->setScale(0.8, 0.8); auto spriteSelect = Sprite::create("addtime.png"); spriteSelect->setScale(0.9, 0.9); auto add_time = MenuItemSprite::create(spriteNomal, spriteSelect, CC_CALLBACK_0(GameGuiLayer::addTimeBtn, this)); add_time->setPosition(400, visibleSize.height - 80); addtime->addChild(add_time); addtime->setPosition(Point(0, 0)); this->addChild(addtime); Sprite* timebg = Sprite::create("numBG.png"); timebg->setPosition(435, visibleSize.height - 85); timebg->setScale(0.8); addChild(timebg); label = CCLabelTTF::create(); ccColor3B color; color.r = 240; color.g = 255; color.b = 255; label->setColor(color); label->setScale(1.2); label->setPosition(435, visibleSize.height - 85); this->addChild(label); char* time = new char[100]; int addtimenum = GAMEDATA::getInstance()->getaddtimeNum(); if (addtimenum<0) { addtimenum == 0; } sprintf(time, "%d", addtimenum); label->setString(time); char* tip_num = new char[100]; int tipnum = GAMEDATA::getInstance()->gettipNum(); if (tipnum<0) { tipnum == 0; } sprintf(tip_num, "%d", tipnum); label1->setString(tip_num); char* refresh_num = new char[100]; int refreshnum = GAMEDATA::getInstance()->getrefreshNum(); if (refreshnum<0) { refreshnum == 0; } sprintf(refresh_num, "%d", refreshnum); label2->setString(refresh_num); //add tree auto tree = Sprite::create("tree.png"); tree->setPosition(70, visibleSize.height - 140); tree->setScale(0.8); addChild(tree); // goto result scene float stime = GAMEDATA::getInstance()->gettime(); if (stime<=3){ notime->setVisible(true); } if (stime <= 2.5){ notime->setVisible(false); } if (stime <= 2){ notime->setVisible(true); } if (stime <= 1.5){ notime->setVisible(false); } if (stime <= 1){ notime->setVisible(true); } if (stime <= 0.5){ notime->setVisible(false); } if (stime<0){ GAMEDATA::getInstance()->settime(11); Audio::getInstance()->timeover(); Director::getInstance()->replaceScene(TransitionFade::create(1, GameResultScene::create())); } }
void LDZGameLayer::initLevel(int level){ Size vs = Director::getInstance()->getVisibleSize(); Vec2 vo = Director::getInstance()->getVisibleOrigin(); _mode = MODE_BEGAIN; TMXTiledMap *map = TMXTiledMap::create("back.tmx"); _map = map; _mapSize = Size(map->getMapSize().width * map->getTileSize().width , map->getMapSize().height * map->getTileSize().height); map->setPosition(Vec2(0, 0)); this->addChild(map); //main char _mainC = Sprite::createWithSpriteFrameName("1.png"); _mainC->setPosition(_mapSize.width/2, _mainC->getContentSize().height/2 + 10); this->addChild(_mainC,1); //progress auto progress = ProgressTimer::create(Sprite::createWithSpriteFrameName("tempb.png")); float progx = _mapSize.width/2 - _mainC->getContentSize().width/2 - progress->getContentSize().width/2 - 5; float progy = _mainC->getContentSize().height/2 + 10; progress->setPosition( progx, progy); progress->setType(cocos2d::ProgressTimer::Type::BAR); progress->setBarChangeRate(Vec2(0, 1)); progress->setMidpoint(Vec2(0, 0)); auto progback = Sprite::createWithSpriteFrameName("temp.png"); progback->setPosition(progx, progy); this->addChild(progback); this->addChild(progress,1); progress->setVisible(false); progback->setVisible(false); _powerProg = progress; _powerProgBack = progback; //limit float height = 50 + arc4random()%100; float uy = _mapSize.height/3 + _mapSize.height/3*2*CCRANDOM_0_1() - 5; float dy = uy - height; _upLimit = Sprite::createWithSpriteFrameName("limit.png"); _upLimit->setPosition(_mapSize.width/2, uy); this->addChild(_upLimit); _downLimit = Sprite::createWithSpriteFrameName("limit.png"); _downLimit->setPosition(_mapSize.width/2, dy); this->addChild(_downLimit); //guide auto gt = ui::Text::create(LHLocalizedCString("guidetext"), Common_Font, 25); gt->setColor(Color3B::RED); gt->setPosition(Vec2(_mainC->getPosition().x , _mainC->getBoundingBox().getMaxY() + gt->getContentSize().height/2)); this->addChild(gt); auto bl = Blink::create(1, 1); auto rp = RepeatForever::create(bl); gt->runAction(rp); auto da = Sprite::create("da.png"); da->setScaleY(height/da->getContentSize().height); da->setPosition(Vec2(_mainC->getPosition().x,_downLimit->getPositionY()+height/2)); this->addChild(da); auto lis = EventListenerTouchOneByOne::create(); lis->onTouchBegan = [this,gt,progress,progback,da](Touch* tmpTouch, Event*){ if (_mode == MODE_VIEW) { Vec2 loca = tmpTouch->getLocation(); loca = this->convertToNodeSpace(loca); if (_mainC->getBoundingBox().containsPoint(loca)) { CallFunc *call = CallFunc::create([this](){ _mode = MODE_POWER; this->scheduleUpdate(); CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("wiso.wav"); }); float focusMargin = 20; this->focusOn(_mainC->getPosition(), _mainC->getContentSize().height + focusMargin, true , call); _mode = MODE_BEGAIN; gt->removeFromParent(); da->removeFromParent(); progress->setVisible(true); progback->setVisible(true); progress->setPercentage(0); } }else if (_mode == MODE_POWER_END){ _mode = MODE_POWER; } return true; }; lis->onTouchMoved = [this](Touch* tmpTouch, Event*){ Vec2 cu = tmpTouch->getLocation(); Vec2 last = tmpTouch->getPreviousLocation(); if (_mode == MODE_VIEW) { float toy = _focusCenter.y + (last.y - cu.y); if (toy+_focusLen/2 > _upLimit->getPositionY() + 20) { toy = _upLimit->getPositionY()+20 - _focusLen/2; } this->focusOn(Vec2(_focusCenter.x , toy),_focusLen, false); }else if (_mode == MODE_POWER){ float dy = fabsf(cu.y - last.y); _powerProg->setPercentage(_powerProg->getPercentage()+dy/(_powerProg->getPercentage()+1)/MOVE_FACTOR); } }; lis->onTouchEnded = [this](Touch*, Event*){ if (_mode == MODE_POWER) { _mode = MODE_POWER_END; _powerCount = 0.1f; } }; this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(lis, this); focusOn(Vec2(_mapSize.width/2,(uy - height/2)), vs.width, false); auto dl2 = DelayTime::create(1); CallFunc *call = CallFunc::create([this](){ auto tmpcall = CallFunc::create([this](){ _mode = MODE_VIEW; }); this->focusOn(_mainC->getPosition(), _focusLen, true , tmpcall); }); auto sq = Sequence::create(dl2,call, NULL); this->runAction(sq); }