void CCPhysicsSprite::updatePosFromPhysics() { cpVect cpPos = cpBodyGetPos(m_pCPBody); m_obPosition = ccp(cpPos.x, cpPos.y); }
bool WhenNotGoToDream::init() { Sprite *backGround = Sprite::create("WhenInPub.jpg"); Size size = Director::sharedDirector()->getWinSize(); float scalX = size.width / backGround->getContentSize().width;///设置x轴方向的缩放系数 float scalY = size.height / backGround->getContentSize().height;//设置y轴方向的缩放系数 backGround->setScaleX(scalX); backGround->setScaleY(scalY); backGround->setPosition(ccp(size.width / 2, size.height / 2)); this->addChild(backGround, 0, 0);//菜单背景 /*Sprite *TalkBox = Sprite::create("TalkBackGround2.png"); TalkBox->setAnchorPoint(Point(0.5,0.5)); TalkBox->setPosition(Point(size.width/2,TalkBox->getContentSize().height/2)); this->addChild(TalkBox);*/ Size s = Director::getInstance()->getVisibleSize(); //获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("1"); const char* b = a->getCString(); Label* label1 = Label::createWithSystemFont(b, "Arial", 30);//第一句旁白的层 /*TalkBox->setAnchorPoint(Point(0.5,0.5)); TalkBox->setPosition(Point(size.width/2,TalkBox->getContentSize().height/2));*/ label1->setAnchorPoint(Point(0.5,0.5)); label1->setPosition(Point(s.width/2,label1->getContentSize().height/3*2)); label1->setOpacity(0); this->addChild(label1,2,1); auto action1 = FadeIn::create(1.0f); label1->runAction(action1); auto ListenerForDialogue1 = EventListenerTouchOneByOne::create(); static int count = 1; ListenerForDialogue1->onTouchBegan = [&](Touch* touch,Event* event){ auto target = static_cast<Label*>(event->getCurrentTarget()); if (count == 1){ this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("2"); const char* b = a->getCString(); Label* label2 = Label::createWithSystemFont(b, "Arial", 30);//第2句旁白的层 label2->setAnchorPoint(Point(0.5,0.5)); label2->setPosition(Point(s.width/2,label2->getContentSize().height/3*2)); label2->setOpacity(0); this->addChild(label2,3,1); auto action2 = FadeIn::create(1.0f); label2->runAction(action2); count = count+1;} else if(count == 2) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("3"); const char* b = a->getCString(); Label* label3 = Label::createWithSystemFont(b, "Arial", 30);//第3句旁白的层 label3->setAnchorPoint(Point(0.5,0.5)); label3->setPosition(Point(s.width/2,label3->getContentSize().height/3*2)); label3->setOpacity(0); this->addChild(label3,3,1); auto action2 = FadeIn::create(1.0f); label3->runAction(action2); count = count+1; } else if(count == 3) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("4"); const char* b = a->getCString(); Label* label4 = Label::createWithSystemFont(b, "Arial", 30);//第4句旁白的层 label4->setAnchorPoint(Point(0.5,0.5)); label4->setPosition(Point(s.width/2,label4->getContentSize().height/3*2)); label4->setOpacity(0); this->addChild(label4,3,1); auto action2 = FadeIn::create(1.0f); label4->runAction(action2); count = count+1; } else if(count == 4) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("5"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 5) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("6"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 6) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("7"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 7) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("8"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 8) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("9"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 9) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("10"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 10) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("11"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 11) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("12"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 12) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("13"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 13) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("14"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 14) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("15"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 15) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("16"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 16) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("17"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 17) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("18"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; } else if(count == 18) { this->removeChildByTag(1); Size s = Director::getInstance()->getVisibleSize();//获取屏幕大小 __Dictionary* string = __Dictionary::createWithContentsOfFile("WhenNotGoToDream.xml"); __String* a = (__String*)string->objectForKey("19"); const char* b = a->getCString(); Label* label5 = Label::createWithSystemFont(b, "Arial", 30);//第5句旁白的层 label5->setAnchorPoint(Point(0.5,0.5)); label5->setPosition(Point(s.width/2,label5->getContentSize().height/3*2)); label5->setOpacity(0); this->addChild(label5,3,1); auto action2 = FadeIn::create(1.0f); label5->runAction(action2); count = count+1; auto menu = Menu::create(MenuItemImage::create("jixuWhenEased.png", "jixuWhenTouched.png", [](Object* obj){ auto scene1 = WhenInTaxi::createScene();//创建待切换的场景 auto transition = TransitionFade::create(0.2f, scene1);//给场景包装动画特效 Director::getInstance()->replaceScene(transition);//运用导演类来进行切换场景 count = 1; }), NULL); menu->setPosition(ccp(s.width / 9*8, s.height /10)); addChild(menu, 1); //开始按钮 } return true; }; _eventDispatcher->addEventListenerWithSceneGraphPriority(ListenerForDialogue1,this); return true; }
CCLayer* DefendQuest::getDescLayer() { CCLayer* layer = CCLayer::create(); CCLabelTTF* descTitle = CCLabelTTF::create("任务简报:","Arial",25); descTitle->setAnchorPoint(ccp(0,0.5)); descTitle->setPosition(ccp(25,360)); descTitle->setColor(ccc3(255,120,0)); CCLabelTTF* desc = CCLabelTTF::create(GXUtil::insertNewline(getDescStr()->getCString(),15).c_str(),"Arial",23,CCSizeZero, kCCTextAlignmentLeft, kCCVerticalTextAlignmentTop); desc->setAnchorPoint(ccp(0,1)); desc->setPosition(ccp(25,340)); desc->setColor(ccc3(230, 207, 185)); CCLabelTTF* destTitle = CCLabelTTF::create("任务目标:","Arial",25); destTitle->setAnchorPoint(ccp(0,1)); destTitle->setPosition(ccp(25,337-desc->getContentSize().height)); destTitle->setColor(ccc3(255,120,0)); char str[100] = {0}; int i=0; CCSprite* tixing; if (defendTimes->getValue() >= needDefendTimes->getValue() ) { sprintf(str," [已完成] 防守胜利%d次",needDefendTimes->getValue()); tixing = CCSprite::createWithSpriteFrameName("questAppear.png"); tixing->setScale(0.45); tixing->setPosition(ccp(55,293-desc->getContentSize().height)); tixing->runAction(CCRepeatForever::create(static_cast<CCSequence*>(CCSequence::create(CCScaleTo::create(1, 0.5), CCScaleTo::create(1,0.45),NULL) ))); } else { sprintf(str," [未完成] 防守胜利%d次,\n进度:%d/%d",needDefendTimes->getValue(),defendTimes->getValue(),needDefendTimes->getValue()); tixing = CCSprite::createWithSpriteFrameName("questQuestion.png"); tixing->setScale(0.45); tixing->setPosition(ccp(55,293-desc->getContentSize().height)); } CCLabelTTF* dest = CCLabelTTF::create(str,"Arial",23,CCSizeZero, kCCTextAlignmentLeft, kCCVerticalTextAlignmentTop); dest->setAnchorPoint(ccp(0,1)); dest->setPosition(ccp(25,305-desc->getContentSize().height)); dest->setColor(ccc3(230, 207, 185)); layer->addChild(dest); layer->addChild(tixing); if(deadLine > 0) { struct cc_timeval now; CCTime::gettimeofdayCocos2d(&now, NULL); CCSprite* tixing1; if (now.tv_sec <= deadLine/1000 ) { sprintf(str," 需在『%s』之前完成",getdeadLineLabel()->getCString()); tixing1 = CCSprite::createWithSpriteFrameName("questAppear.png"); tixing1->setScale(0.45); tixing1->setPosition(ccp(55,293-desc->getContentSize().height-i*32)); tixing1->runAction(CCRepeatForever::create(static_cast<CCSequence*>(CCSequence::create(CCScaleTo::create(1, 0.5), CCScaleTo::create(1,0.45),NULL) ))); } else { sprintf(str," 已经超过『%s』,无法完成",getdeadLineLabel()->getCString()); tixing1 = CCSprite::createWithSpriteFrameName("questQuestion.png"); tixing1->setScale(0.45); tixing1->setPosition(ccp(55,293-desc->getContentSize().height-i*32)); } CCLabelTTF* dest1 = CCLabelTTF::create(str,"Arial",23); dest1->setAnchorPoint(ccp(0,1)); dest1->setPosition(ccp(25,305-desc->getContentSize().height-i*32)); dest1->setColor(ccc3(230, 207, 185)); layer->addChild(dest1); layer->addChild(tixing1); } layer->addChild(descTitle); layer->addChild(desc); layer->addChild(destTitle); return layer; }
bool UpStateLayer::init() { CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); if (!CCLayerColor::initWithColor(Color_Up_Down,origin.x+visibleSize.width,UpHeight)) { return false; } m_Level_bg = CCMenuItem::create(this, menu_selector(UpStateLayer::menuBePressed)); m_Top_bg = CCMenuItem::create(this, menu_selector(UpStateLayer::menuBePressed)); m_Score_bg = CCMenuItem::create(this, menu_selector(UpStateLayer::menuBePressed)); m_Level_bg->ignoreAnchorPointForPosition(false); m_Top_bg->ignoreAnchorPointForPosition(false); m_Score_bg->ignoreAnchorPointForPosition(false); m_Level_bg->setAnchorPoint(ccp(0, 0.5)); m_Top_bg->setAnchorPoint(ccp(0, 0.5)); m_Score_bg->setAnchorPoint(ccp(0, 0.5)); //menu CCMenu * menu = CCMenu::create(m_Level_bg,m_Top_bg,m_Score_bg,NULL); menu->setAnchorPoint(ccp(0, 0)); menu->setPosition(ccp(0, 0)); this->addChild(menu); if (SettingHelper::getGameType() == GAME_TYPE_CLASSIC || SettingHelper::getGameType() == GAME_TYPE_SPEED) { m_Score_bg->setContentSize(CCSizeMake(this->getContentSize().width/2, UpHeight)); m_Top_bg->setContentSize(CCSizeMake(this->getContentSize().width/2, UpHeight)); //最高分/得分 m_Top_bg->setPosition(ccp(0,UpHeight/2)); m_Score_bg->setPosition(ccp(this->getContentSize().width/2,UpHeight/2)); }else{ m_Level_bg->setContentSize(CCSizeMake(this->getContentSize().width/3, UpHeight)); m_Score_bg->setContentSize(CCSizeMake(this->getContentSize().width/3, UpHeight)); //等级/目标/得分 m_Level_bg->setPosition(ccp(0,UpHeight/2)); m_Score_bg->setPosition(ccp(this->getContentSize().width/2,UpHeight/2)); } title_score = CCLabelTTF::create(CCLocalizedString("score", ""), "fonts/Josefin Sans.ttf", 12); title_level = CCLabelTTF::create(CCLocalizedString("level", ""), "fonts/Josefin Sans.ttf", 12); title_top = CCLabelTTF::create(CCLocalizedString("top", ""), "fonts/Josefin Sans.ttf", 12); title_goal = CCLabelTTF::create(CCLocalizedString("goal", ""), "fonts/Josefin Sans.ttf", 12); title_score->setAnchorPoint(ccp(0, 0.5)); title_score->setColor(Color_Text); title_top->setAnchorPoint(ccp(0, 0.5)); title_top->setColor(Color_Text); title_level->setAnchorPoint(ccp(0, 0.5)); title_level->setColor(Color_Text); title_goal->setAnchorPoint(ccp(0, 0.5)); title_goal->setColor(Color_Text); m_Level_bg->addChild(title_level); m_Level_bg->addChild(title_goal); m_Top_bg->addChild(title_top); m_Score_bg->addChild(title_score); //labels m_labelScore = CCLabelTTF::create("0", "fonts/Josefin Sans.ttf", 20); m_labelLevel = CCLabelTTF::create("0", "fonts/Josefin Sans.ttf", 20); m_labelGoal = CCLabelTTF::create("0", "fonts/Josefin Sans.ttf", 20); m_labelTop = CCLabelTTF::create("0", "fonts/Josefin Sans.ttf", 20); m_labelTop->setAnchorPoint(ccp(0, 0.5)); m_labelTop->setColor(Color_Text); m_labelScore->setAnchorPoint(ccp(0, 0.5)); m_labelScore->setColor(Color_Text); m_labelLevel->setAnchorPoint(ccp(0, 0.5)); m_labelLevel->setColor(Color_Text); m_labelGoal->setAnchorPoint(ccp(0, 0.5)); m_labelGoal->setColor(Color_Text); m_Level_bg->addChild(m_labelLevel); m_Level_bg->addChild(m_labelGoal); m_Top_bg->addChild(m_labelTop); m_Score_bg->addChild(m_labelScore); //设置位置 resetItemPosition(); //progress CCSprite *psSprite1 = CCSprite::create("progress_bar.png"); //利用精灵创建进度条,并设置一些属性 progresstime1 = CCProgressTimer::create(psSprite1); //初始化CCProgressTimer progresstime1->setPercentage(100.0f); //设置初始百分比的值 // Setup for a bar starting from the left since the midpoint is 0 for the x progresstime1->setMidpoint(ccp(0,0)); // Setup for a horizontal bar since the bar change rate is 0 for y meaning no vertical change progresstime1->setBarChangeRate(ccp(1, 0)); progresstime1->setType(kCCProgressTimerTypeBar); //设置进度条为水平 progresstime1->setAnchorPoint(ccp(0, 0)); progresstime1->setPosition(ccp(0, 0)); //放置进度条位置 this->addChild(progresstime1, 100); //加入Layer中 this->scheduleUpdate(); this->setVisible(false); return true; }
void VVAlertView::show() { showAt(ccp(winSize.width/2, winSize.height/2)); }
bool PanelLayer::init() { bool bRet = false; do { CC_BREAK_IF(! CCLayer::init()); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); // Settting and pause (Right Top) CCMenuItemImage* setting = CCMenuItemImage::create( STATIC_DATA_STRING("setting_normal"), STATIC_DATA_STRING("setting_selected"), this, menu_selector(PanelLayer::setting)); CC_BREAK_IF( !setting ); CCMenuItemImage* pause = CCMenuItemImage::create( STATIC_DATA_STRING("pause_normal"), STATIC_DATA_STRING("pause_selected"), this, menu_selector(PanelLayer::pause)); CC_BREAK_IF( !pause ); CCSize settingSize = setting->getContentSize(); CCSize pauseSize = pause->getContentSize(); CCMenu* menu = CCMenu::create(setting, pause, NULL); CC_BREAK_IF( !menu ); this->addChild(menu, 1, MENUTAG); menu->setPosition(CCPointMake(winSize.width-pauseSize.width * 3 / 2, winSize.height-pauseSize.height * 3 /4)); menu->alignItemsHorizontallyWithPadding(pauseSize.width / 3); // energy bar (Left Top) energyBar = ProgressBar::create(); CC_BREAK_IF( !energyBar ); CCSize barSize = energyBar->getContentSize(); energyBar->setPosition(ccp(barSize.width*0.52, winSize.height-barSize.height*0.58)); this->addChild(energyBar); // energy button(Left Top) eneygyButtonNormal = CCMenuItemImage::create( STATIC_DATA_STRING("ultimateButton_normal"), STATIC_DATA_STRING("ultimateButton_normal"), this, menu_selector(PanelLayer::useUltimate)); eneygyButtonFull = CCMenuItemImage::create( STATIC_DATA_STRING("ultimateButton_selected"), STATIC_DATA_STRING("ultimateButton_selected"), this, menu_selector(PanelLayer::useUltimate)); menuUltimate = CCMenu::create(eneygyButtonNormal, eneygyButtonFull, NULL); eneygyButtonFull->setVisible(false); this->addChild(menuUltimate); CCSize ultiSize = eneygyButtonNormal->getContentSize(); menuUltimate->setPosition(ccp(ultiSize.width*0.6, winSize.height-ultiSize.height*0.58)); // Pro propLeft = CCMenuItemImage::create( STATIC_DATA_STRING("prop_nothing"), STATIC_DATA_STRING("prop_nothing"), this, menu_selector(PanelLayer::useLeftPro)); propLeft->setTag(LEFT); Prop* prop = Prop::create(No_Prop); this->setLeftProp(prop); propRight = CCMenuItemImage::create( STATIC_DATA_STRING("prop_nothing"), STATIC_DATA_STRING("prop_nothing"), this, menu_selector(PanelLayer::useRightPro)); propRight->setTag(RIGHT); Prop* prop2 = Prop::create(No_Prop); this->setRightProp(prop2); menuProp = CCMenu::create(propLeft, propRight, NULL); this->addChild(menuProp); CCSize proSize = propLeft->getContentSize(); menuProp->setPosition(CCPointMake(proSize.width * 3 / 2, proSize.height * 0.618)); menuProp->alignItemsHorizontallyWithPadding(proSize.width / 3); leftPlaced = rightPlaced = false; bRet = true; } while (0); return bRet; }
//-------------------------------------------------- // // void CPet::ApplyHurt( int damage, bool isHardAttack ) { CBaseDataPet* pPetBaseData = g_pClientLoader->GetBaseDataPetFromId(m_PetData.petid); int skilldata = CExpressions::GetInstance()->GetAttribute( pPetBaseData->skillaptitude, pPetBaseData->upskill, pPetBaseData->initskill, m_PetData.petlevel ); float pec = CExpressions::GetInstance()->GetSkillFrquency(skilldata, m_PetData.petlevel ); CBaseDataSkill* pDataSkill = g_pClientLoader->GetBaseDataSkillFromId(pPetBaseData->skillfield_defense[m_PetData.skilllevel.skillsLevel[1] - 1]); //skill attack if( CCRANDOM_0_1() < pec && m_PetData.skilllevel.skillsLevel[1] > 0 && m_PetData.mp >= pDataSkill->skillmp ) { CBaseDataAnimation *pAnimationData = g_pClientLoader->GetBaseDataAnimationFromId(m_PetData.ResId); PlayAnimation( pAnimationData->m_defense, 1, callfunc_selector( CPet::HurtEndCallBack ), this, false, false ); m_PetData.mp = m_PetData.mp - pDataSkill->skillmp; if( m_PetData.mp <= 0 ) { m_PetData.mp = 0; } std::string effectpath = GetGameParticlePath(); std::string filename = effectpath + pDataSkill->plist; if( !pDataSkill->plist.empty() ) { CCParticleSystemQuad *pEmitter = CCParticleSystemQuad::particleWithFile(filename.c_str() ); //m_emitter->setPositionType( kCCPositionTypeRelative ); pEmitter->setPosition( getPosition() ); g_pFightGroundLayer->addChild( pEmitter, 100 ); } if( CCUserDefault::sharedUserDefault()->getBoolForKey( "sound" ) ) { string path = "data/audio/" + pDataSkill->skill_sound; CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(path.c_str(), false); CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("data/audio/scoreCount2.wav", false); } return; } m_PetData.hp = m_PetData.hp - damage; char strbuffer[32]; if( 0 == damage ) { sprintf( strbuffer, "%s", "miss"); } else { sprintf( strbuffer, "-%d", damage); } CCLabelTTF *plabel = CCLabelTTF::labelWithString(strbuffer, kFontSystem[FONT_GRAND].fontName,kFontSystem[FONT_GRAND].fontSize); const ccColor3B ccwhite = {255,255,255}; const ccColor3B ccYellow = {255,255,0}; const ccColor3B ccRed = {255,0,0 }; if( isHardAttack ) { plabel->setColor( ccYellow ); } else if( 0 == damage ) { plabel->setColor( ccRed ); } else { plabel->setColor( ccwhite ); } plabel->setPosition( ccp( getPosition().x, getPosition().y + getTextureRect().size.height ) ); g_pFightGroundLayer->addChild(plabel,100); plabel->runAction( CCFadeOut::actionWithDuration(1.5f) ); plabel->runAction(CCMoveBy::actionWithDuration(0.2f, ccp( 0, 50 ))); if( m_PetData.hp <= 0 ) { CBaseDataAnimation *pAnimationData = g_pClientLoader->GetBaseDataAnimationFromId(m_PetData.ResId); PlayAnimation( pAnimationData->m_lost, 1, NULL, this, false, false ); m_pLockTarget->m_bIsWin = true; } else { CBaseDataAnimation *pAnimationData = g_pClientLoader->GetBaseDataAnimationFromId(m_PetData.ResId); PlayAnimation( pAnimationData->m_injured, 1, callfunc_selector( CPet::HurtEndCallBack ), this, false, false ); } if( 0 != damage ) { std::string effectpath = GetGameParticlePath(); std::string filename = effectpath + "hurteffect.plist"; CCParticleSystemQuad *pEmitter = CCParticleSystemQuad::particleWithFile( filename.c_str() ); //m_emitter->setPositionType( kCCPositionTypeRelative ); pEmitter->setPosition( getPosition() ); CCPoint pos = getPosition(); g_pFightGroundLayer->addChild( pEmitter, 100 ); } if( isHardAttack ) { std::string effectpath = GetGameParticlePath(); std::string filename = effectpath + "bloodEffect.plist"; CCParticleSystemQuad *pEmitter = CCParticleSystemQuad::particleWithFile( filename.c_str() ); //m_emitter->setPositionType( kCCPositionTypeRelative ); pEmitter->setPosition( getPosition() ); CCPoint pos = getPosition(); g_pFightGroundLayer->addChild( pEmitter, 100 ); } }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); block_size_ = visibleSize.width / kHorizontalNumber; ///////////////////////////// // 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 CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label CCLabelTTF* pLabel = CCLabelTTF::create("", "Arial", 24); // position the label on the center of the screen pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); // add the label as a child to this layer this->addChild(pLabel, 1); // add "HelloWorld" splash screen" CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // position the sprite on the center of the screen pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(pSprite, 0); //ブロック初期化 blocks_.resize(kHorizontalNumber * kVerticalNumber); for ( int i=0; i<kHorizontalNumber ; ++i) { for ( int j=0; j<kVerticalNumber ; ++j) { CCLabelTTF* label = CCLabelTTF::create("", "Arial", 100); this->addChild(label, 1); block(i,j).init( block_size_,i,j,label ); block(i,j).setStateRandom(); } } current_number_ =-1; label_ = CCLabelTTF::create("tap number", "Arial", 100); this->addChild(label_, 1); label_->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label_->getContentSize().height)); CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true); return true; }
MenuLayerMainMenu::MenuLayerMainMenu( void ) { CCLabelBMFont* label_new=CCLabelBMFont::create("New Game","fonts/bitmapFontTest3.fnt"); CCMenuItemLabel* item_new=CCMenuItemLabel::create(label_new,this,menu_selector(MenuLayerMainMenu::menuCallback)); CCLabelBMFont* label_load=CCLabelBMFont::create("Load Game","fonts/bitmapFontTest3.fnt"); CCMenuItemLabel* item_load=CCMenuItemLabel::create(label_load,this,menu_selector(MenuLayerMainMenu::menuCallback)); CCLabelBMFont* label_config=CCLabelBMFont::create("Config","fonts/bitmapFontTest3.fnt"); CCMenuItemLabel* item_config=CCMenuItemLabel::create(label_config,this,menu_selector(MenuLayerMainMenu::menuCallback)); CCLabelBMFont* label_toplist=CCLabelBMFont::create("Top List","fonts/bitmapFontTest3.fnt"); CCMenuItemLabel* item_toplist=CCMenuItemLabel::create(label_toplist,this,menu_selector(MenuLayerMainMenu::menuCallback)); CCLabelBMFont* label_help=CCLabelBMFont::create("Help","fonts/bitmapFontTest3.fnt"); CCMenuItemLabel* item_help=CCMenuItemLabel::create(label_help,this,menu_selector(MenuLayerMainMenu::menuCallback)); //item_config->setScale(1.2); CCLabelBMFont* label_exit=CCLabelBMFont::create("Exit","fonts/bitmapFontTest3.fnt"); CCMenuItemLabel* item_exit=CCMenuItemLabel::create(label_exit,this,menu_selector(MenuLayerMainMenu::menuCallback)); //CCMenu* mainmenu=CCMenu::create(item_new,item_load,item_config,item_toplist,item_help,item_exit,NULL); CCMenu* mainmenu=CCMenu::create(); mainmenu->addChild(item_new,1000+1); mainmenu->addChild(item_load,1000+2); mainmenu->addChild(item_config,1000+3); mainmenu->addChild(item_toplist,1000+4); mainmenu->addChild(item_help,1000+5); mainmenu->addChild(item_exit,1000+6); //mainmenu->alignItemsVertically(); mainmenu->alignItemsVerticallyWithPadding(10); CCSize s=CCDirector::sharedDirector()->getWinSize(); int i=0; CCNode* child; CCArray * pArray = mainmenu->getChildren(); CCObject* pObject = NULL; CCARRAY_FOREACH(pArray, pObject) { if(pObject == NULL) break; child = (CCNode*)pObject; CCPoint dstPoint = child->getPosition(); int offset = (int) (s.width/2 + 50); if( i % 2 == 0) offset = -offset; child->setPosition( ccp( dstPoint.x + offset, dstPoint.y) ); child->runAction( CCEaseElasticOut::create(CCMoveBy::create(2, ccp(dstPoint.x - offset,0)), 0.35f) ); i++; } this->addChild(mainmenu); mainmenu->setPosition(ccp(s.width/2,s.height/2)); CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("Music/mainMainMusic.mp3"); }
//-------------------------------------------------------- CCPoint CVisibleRect::rightTop() { lazyInit(); return ccp(s_VisibleRect.origin.x+s_VisibleRect.size.width, s_VisibleRect.origin.y+s_VisibleRect.size.height); }
//-------------------------------------------------------- CCPoint CVisibleRect::rightBottom() { lazyInit(); return ccp(s_VisibleRect.origin.x+s_VisibleRect.size.width, s_VisibleRect.origin.y); }
//-------------------------------------------------------- CCPoint CVisibleRect::center() { lazyInit(); return ccp(s_VisibleRect.origin.x+s_VisibleRect.size.width/2, s_VisibleRect.origin.y+s_VisibleRect.size.height/2); }
//-------------------------------------------------------- CCPoint CVisibleRect::left() { lazyInit(); return ccp(s_VisibleRect.origin.x, s_VisibleRect.origin.y+s_VisibleRect.size.height/2); }
CCLayer* ArmyQuest::getDescLayer() { CCLayer* layer = CCLayer::create(); CCLabelTTF* descTitle = CCLabelTTF::create("任务简报:","Arial",25); descTitle->setAnchorPoint(ccp(0,0.5)); descTitle->setPosition(ccp(25,360)); descTitle->setColor(ccc3(255,120,0)); CCLabelTTF* desc = CCLabelTTF::create(GXUtil::insertNewline(getDescStr()->getCString(),15).c_str(),"Arial",23,CCSizeZero, kCCTextAlignmentLeft, kCCVerticalTextAlignmentTop); desc->setAnchorPoint(ccp(0,1)); desc->setPosition(ccp(25,340)); desc->setColor(ccc3(230, 207, 185)); CCLabelTTF* destTitle = CCLabelTTF::create("任务目标:","Arial",25); destTitle->setAnchorPoint(ccp(0,1)); destTitle->setPosition(ccp(25,337-desc->getContentSize().height)); destTitle->setColor(ccc3(255,120,0)); char str[200] = {0}; int i=0; float preHeight =0; for (i=0; i<needArmyTagList->count(); i++) { int needLevel = ((GXintValue*)needArmyLevelList->objectAtIndex(i))->getValue(); CCString* needLabel = (CCString*)needArmyLabelList->objectAtIndex(i); int finishLevel = ((GXintValue*)finishArmyList->objectAtIndex(i))->getValue(); CCSprite* tixing; if (finishLevel >= needLevel) { if (needLevel <= 1) { sprintf(str," [已完成] 解锁兵种『%s』",needLabel->getCString()); } else { sprintf(str," [已完成] 升级兵种『%s』至%d级",needLabel->getCString(),needLevel); } tixing = CCSprite::createWithSpriteFrameName("questAppear.png"); tixing->setScale(0.45); tixing->setPosition(ccp(55,293-desc->getContentSize().height-preHeight-5)); tixing->runAction(CCRepeatForever::create(static_cast<CCSequence*>(CCSequence::create(CCScaleTo::create(1, 0.5), CCScaleTo::create(1,0.45),NULL) ))); } else { if (needLevel <= 1) { sprintf(str," [未完成] 解锁兵种『%s』",needLabel->getCString()); } else { sprintf(str," [未完成] 升级兵种『%s』至%d级,进度:%d/%d",needLabel->getCString(),needLevel,finishLevel,needLevel); } tixing = CCSprite::createWithSpriteFrameName("questQuestion.png"); tixing->setScale(0.45); tixing->setPosition(ccp(55,293-desc->getContentSize().height-preHeight-5)); } CCLabelTTF* dest = CCLabelTTF::create(GXUtil::insertNewline(str,15).c_str(),"Arial",23,CCSizeZero, kCCTextAlignmentLeft, kCCVerticalTextAlignmentTop); dest->setAnchorPoint(ccp(0,1)); dest->setPosition(ccp(25,305-desc->getContentSize().height-preHeight-5)); dest->setColor(ccc3(230, 207, 185)); preHeight = preHeight + dest->getContentSize().height+5; layer->addChild(dest); layer->addChild(tixing); } if(deadLine > 0) { struct cc_timeval now; CCTime::gettimeofdayCocos2d(&now, NULL); CCSprite* tixing1; if (now.tv_sec <= deadLine/1000 ) { sprintf(str," 需在[%s]之前完成",getdeadLineLabel()->getCString()); tixing1 = CCSprite::createWithSpriteFrameName("questAppear.png"); tixing1->setScale(0.45); tixing1->setPosition(ccp(55,293-desc->getContentSize().height-i*32)); tixing1->runAction(CCRepeatForever::create(static_cast<CCSequence*>(CCSequence::create(CCScaleTo::create(1, 0.5), CCScaleTo::create(1,0.45),NULL) ))); } else { sprintf(str," 已经超过[%s],无法完成",getdeadLineLabel()->getCString()); tixing1 = CCSprite::createWithSpriteFrameName("questQuestion.png"); tixing1->setScale(0.45); tixing1->setPosition(ccp(55,293-desc->getContentSize().height-i*32)); } CCLabelTTF* dest1 = CCLabelTTF::create(str,"Arial",23); dest1->setAnchorPoint(ccp(0,1)); dest1->setPosition(ccp(25,305-desc->getContentSize().height-preHeight)); dest1->setColor(ccc3(230, 207, 185)); layer->addChild(dest1); layer->addChild(tixing1); } layer->addChild(descTitle); layer->addChild(desc); layer->addChild(destTitle); return layer; }
void DancingBoneLayer::draw() { // // IMPORTANT: // This is only for debug purposes // It is recommend to disable it // CCLayer::draw(); ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position ); kmGLPushMatrix(); world->DrawDebugData(); kmGLPopMatrix(); //draw ground glLineWidth(2); ccDrawColor4B(124,1,1,128); cocos2d::ccDrawLine(ccp(0, 4 * PTM_RATIO), ccp(VisibleRect::rightBottom().x, 4 * PTM_RATIO)); /* if (this->world == NULL) { return; } for (int i = 0; i < this->boneArray->count(); i++) { b2Body *body = ((PhysicsSprite*)this->boneArray->objectAtIndex(i))->body; //body->set; b2Shape *shape = body->GetFixtureList()->GetShape(); b2Vec2 pos = body->GetPosition(); if (shape->GetType() == b2Shape::e_circle) { } else if (shape->GetType() == b2Shape::e_polygon) { b2PolygonShape *polShape = (b2PolygonShape*)shape; for (int i = 0; i < polShape->GetVertexCount(); i++) { b2Vec2 vec = polShape->GetVertex(i); CCPoint posVec = ccp((vec.x + pos.x) * PTM_RATIO, (vec.y + pos.y) * PTM_RATIO); cocos2d::ccDrawCircle(posVec, 16, 0, 16, true); } } }; */ /* //draw joint if ((!this->isReal) && (this->world != NULL)) { int count = this->world->GetJointCount(); b2Joint *joint = this->world->GetJointList(); for (int i = 0; i < count; i++) { if ((joint->GetBodyA() != this->groundBody) && (joint->GetBodyB() != this->groundBody)) { b2Vec2 vec = joint->GetAnchorA(); CCPoint pos = ccp(vec.x * PTM_RATIO, vec.y * PTM_RATIO); cocos2d::ccDrawCircle(pos, 32, 0, 32, true); //cocos2d::ccDrawSolidRect(pos, ccp(pos.x + 64, pos.y + 64), ccc4f(101, 11, 12, 21)); } joint = joint->GetNext(); } } */ }
// on "init" you need to initialize your instance bool TutorialScene::init(bool firstTime) { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } //navigation _firstTime = firstTime; _moveStarted = false; CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCLayerColor* background = CCLayerColor::create(ccc4(0, 0, 0, 255), visibleSize.width, visibleSize.height); background->setAnchorPoint(ccp(0,0)); addChild(background); CCMenuItemImage* nextImgItem = CCMenuItemImage::create( "Interfeiss/buttons/arrow_r_btn0001.png", "Interfeiss/buttons/arrow_r_btn0002.png", this, menu_selector(TutorialScene::btNextCallback)); CCMenuItemImage* prevImgItem = CCMenuItemImage::create( "Interfeiss/buttons/arrow_l_btn0001.png", "Interfeiss/buttons/arrow_l_btn0002.png", this, menu_selector(TutorialScene::btPrevCallback)); CCMenuItemImage* closeItem = CCMenuItemImage::create( "Interfeiss/buttons/close_btn0001.png", "Interfeiss/buttons/close_btn0002.png", this, menu_selector(TutorialScene::btCloseCallback)); _images[0] = "Interfeiss/tutorial/1.png"; _images[1] = "Interfeiss/tutorial/2.png"; _images[2] = "Interfeiss/tutorial/3.png"; _images[3] = "Interfeiss/tutorial/4.png"; _images[4] = "Interfeiss/tutorial/5.png"; _images[5] = "Interfeiss/tutorial/6.png"; nextImgItem->setAnchorPoint(ccp(1,0)); prevImgItem->setAnchorPoint(ccp(0,0)); closeItem->setAnchorPoint(ccp(1,1)); CCMenu* nextMenu = CCMenu::create(nextImgItem, NULL); CCMenu* prevMenu = CCMenu::create(prevImgItem, NULL); CCMenu* closeMenu = CCMenu::create(closeItem, NULL); prevMenu->setPosition(ccp(10,10)); nextMenu->setPosition(visibleSize.width - 10, 10); closeMenu->setPosition(visibleSize.width - 10, visibleSize.height - 10); _activeImage = CCSprite::create(_images[0].c_str()); _activeImage->setAnchorPoint(ccp(0,0)); _activeImage->setPositionY((visibleSize.height - _activeImage->getContentSize().height) / 2); addChild(_activeImage,0); _activeImg = 0; showFirstPageAnimation(); addChild(nextMenu, 1); addChild(prevMenu, 2); // addChild(closeMenu, 3); return true; }
//------------------------------------------------------------------ // // TexturePixelFormat // //------------------------------------------------------------------ void TexturePixelFormat::onEnter() { // // This example displays 1 png images 4 times. // Each time the image is generated using: // 1- 32-bit RGBA8 // 2- 16-bit RGBA4 // 3- 16-bit RGB5A1 // 4- 16-bit RGB565 TextureDemo::onEnter(); CCLabelTTF *label = (CCLabelTTF*) getChildByTag(kTagLabel); label->setColor(ccc3(16,16,255)); CCSize s = CCDirector::sharedDirector()->getWinSize(); CCLayerColor *background = CCLayerColor::create(ccc4(128,128,128,255), s.width, s.height); addChild(background, -1); // RGBA 8888 image (32-bit) CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888); CCSprite *sprite1 = CCSprite::create("Images/test-rgba1.png"); sprite1->setPosition(ccp(1*s.width/7, s.height/2+32)); addChild(sprite1, 0); // remove texture from texture manager CCTextureCache::sharedTextureCache()->removeTexture(sprite1->getTexture()); // RGBA 4444 image (16-bit) CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444); CCSprite *sprite2 = CCSprite::create("Images/test-rgba1.png"); sprite2->setPosition(ccp(2*s.width/7, s.height/2-32)); addChild(sprite2, 0); // remove texture from texture manager CCTextureCache::sharedTextureCache()->removeTexture(sprite2->getTexture()); // RGB5A1 image (16-bit) CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB5A1); CCSprite *sprite3 = CCSprite::create("Images/test-rgba1.png"); sprite3->setPosition(ccp(3*s.width/7, s.height/2+32)); addChild(sprite3, 0); // remove texture from texture manager CCTextureCache::sharedTextureCache()->removeTexture(sprite3->getTexture()); // RGB888 image CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB888); CCSprite *sprite4 = CCSprite::create("Images/test-rgba1.png"); sprite4->setPosition(ccp(4*s.width/7, s.height/2-32)); addChild(sprite4, 0); // remove texture from texture manager CCTextureCache::sharedTextureCache()->removeTexture(sprite4->getTexture()); // RGB565 image (16-bit) CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB565); CCSprite *sprite5 = CCSprite::create("Images/test-rgba1.png"); sprite5->setPosition(ccp(5*s.width/7, s.height/2+32)); addChild(sprite5, 0); // remove texture from texture manager CCTextureCache::sharedTextureCache()->removeTexture(sprite5->getTexture()); // A8 image (8-bit) CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_A8); CCSprite *sprite6 = CCSprite::create("Images/test-rgba1.png"); sprite6->setPosition(ccp(6*s.width/7, s.height/2-32)); addChild(sprite6, 0); // remove texture from texture manager CCTextureCache::sharedTextureCache()->removeTexture(sprite6->getTexture()); CCFadeOut* fadeout = CCFadeOut::create(2); CCFadeIn* fadein = CCFadeIn::create(2); CCFiniteTimeAction* seq = CCSequence::create(CCDelayTime::create(2), fadeout, fadein, NULL); CCRepeatForever* seq_4ever = CCRepeatForever::create((CCActionInterval*) seq); CCRepeatForever* seq_4ever2 = (CCRepeatForever*) (seq_4ever->copy()); seq_4ever2->autorelease(); CCRepeatForever* seq_4ever3 = (CCRepeatForever*) (seq_4ever->copy()); seq_4ever3->autorelease(); CCRepeatForever* seq_4ever4 = (CCRepeatForever*) (seq_4ever->copy()); seq_4ever4->autorelease(); CCRepeatForever* seq_4ever5 = (CCRepeatForever*) (seq_4ever->copy()); seq_4ever5->autorelease(); sprite1->runAction(seq_4ever); sprite2->runAction(seq_4ever2); sprite3->runAction(seq_4ever3); sprite4->runAction(seq_4ever4); sprite5->runAction(seq_4ever5); // restore default CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_Default); CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo(); }
void CCSkeleton::draw () { CC_NODE_DRAW_SETUP(); ccGLBlendFunc(blendFunc.src, blendFunc.dst); ccColor3B color = getColor(); skeleton->r = color.r / (float)255; skeleton->g = color.g / (float)255; skeleton->b = color.b / (float)255; skeleton->a = getOpacity() / (float)255; if (premultipliedAlpha) { skeleton->r *= skeleton->a; skeleton->g *= skeleton->a; skeleton->b *= skeleton->a; } CCTextureAtlas* textureAtlas = 0; ccV3F_C4B_T2F_Quad quad; quad.tl.vertices.z = 0; quad.tr.vertices.z = 0; quad.bl.vertices.z = 0; quad.br.vertices.z = 0; for (int i = 0, n = skeleton->slotCount; i < n; i++) { Slot* slot = skeleton->slots[i]; if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue; RegionAttachment* attachment = (RegionAttachment*)slot->attachment; CCTextureAtlas* regionTextureAtlas = getTextureAtlas(attachment); if (regionTextureAtlas != textureAtlas) { if (textureAtlas) { textureAtlas->drawQuads(); textureAtlas->removeAllQuads(); } } textureAtlas = regionTextureAtlas; if (textureAtlas->getCapacity() == textureAtlas->getTotalQuads() && !textureAtlas->resizeCapacity(textureAtlas->getCapacity() * 2)) return; RegionAttachment_updateQuad(attachment, slot, &quad, premultipliedAlpha); textureAtlas->updateQuad(&quad, textureAtlas->getTotalQuads()); } if (textureAtlas) { textureAtlas->drawQuads(); textureAtlas->removeAllQuads(); } if (debugSlots) { // Slots. ccDrawColor4B(0, 0, 255, 255); glLineWidth(1); CCPoint points[4]; ccV3F_C4B_T2F_Quad quad; for (int i = 0, n = skeleton->slotCount; i < n; i++) { Slot* slot = skeleton->slots[i]; if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue; RegionAttachment* attachment = (RegionAttachment*)slot->attachment; RegionAttachment_updateQuad(attachment, slot, &quad); points[0] = ccp(quad.bl.vertices.x, quad.bl.vertices.y); points[1] = ccp(quad.br.vertices.x, quad.br.vertices.y); points[2] = ccp(quad.tr.vertices.x, quad.tr.vertices.y); points[3] = ccp(quad.tl.vertices.x, quad.tl.vertices.y); ccDrawPoly(points, 4, true); } } if (debugBones) { // Bone lengths. glLineWidth(2); ccDrawColor4B(255, 0, 0, 255); for (int i = 0, n = skeleton->boneCount; i < n; i++) { Bone *bone = skeleton->bones[i]; float x = bone->data->length * bone->m00 + bone->worldX; float y = bone->data->length * bone->m10 + bone->worldY; ccDrawLine(ccp(bone->worldX, bone->worldY), ccp(x, y)); } // Bone origins. ccPointSize(4); ccDrawColor4B(0, 0, 255, 255); // Root bone is blue. for (int i = 0, n = skeleton->boneCount; i < n; i++) { Bone *bone = skeleton->bones[i]; ccDrawPoint(ccp(bone->worldX, bone->worldY)); if (i == 0) ccDrawColor4B(0, 255, 0, 255); } } }
DeadDlg::DeadDlg(CCObject *listener,SEL_CallFuncO selector,int type) { // CCLayerColor *layer = CCLayerColor::layerWithColor) m_listener = listener; m_selector = selector; m_backGround = CCSprite::spriteWithSpriteFrameName("fr_window2.png"); m_backGround->setScale(2.0); addChild(m_backGround); m_backGround->setPosition(ccp(320, 500)); CCSprite* spMenu1 = CCSprite::spriteWithSpriteFrameName("fr_button.png"); CCSprite* spMenu2 = CCSprite::spriteWithSpriteFrameName("fr_button.png"); sureItem = CCMenuItemImage::itemFromNormalSprite(spMenu1, spMenu2, this, menu_selector(DeadDlg::menuCallback)); sureItem->setTag(111); sureItem->setPosition(ccp(88, 284)); int need; long hold; if (CGameData::Inst()->chkLogin()) { need = CGameData::Inst()->getCommonInfo()->revive_coin; } else { need = SaveData::Inst()->getReviveCoin(); } if(CGameData::Inst()->getUsrInfo()->login_time > 0){ hold = CGameData::Inst()->getUsrInfo()->coin; SaveData::Inst()->setCurCoin(hold); } else{ hold = SaveData::Inst()->getCurCoin(); } char buf[100]; if(type == enDeadType_normal) { if (hold<need) { strncpy(buf, CGameData::Inst()->getLanguageValue("shopTip14"), 99); } else { strncpy(buf, CGameData::Inst()->getLanguageValue("sureTip"), 99); } } else if(type == enDeadType_free) { strncpy(buf, CGameData::Inst()->getLanguageValue("sureTip"), 99); } TextNode *sureLabel = TextNode::textWithString(buf, 42); sureLabel->setColor(ccc3(255, 255, 255)); sureLabel->setShadowColor(ccBLACK); sureLabel->setPosition(CCPointMake(spMenu1->getContentSize().width * 0.5 - 2, spMenu1->getContentSize().height * 0.5 + 2)); sureItem->addChild(sureLabel); spMenu1 = CCSprite::spriteWithSpriteFrameName("fr_button.png"); spMenu2 = CCSprite::spriteWithSpriteFrameName("fr_button.png"); cancelItem = CCMenuItemImage::itemFromNormalSprite(spMenu1, spMenu2, this, menu_selector(DeadDlg::menuCallback)); cancelItem->setTag(112); cancelItem->setPosition(ccp(394, 284)); TextNode *cancelLabel = TextNode::textWithString(CGameData::Inst()->getLanguageValue("cancelTip"), 42); cancelLabel->setColor(ccc3(255, 255, 255)); cancelLabel->setShadowColor(ccBLACK); cancelLabel->setPosition(CCPointMake(spMenu1->getContentSize().width * 0.5 - 2, spMenu1->getContentSize().height * 0.5 + 2)); cancelItem->addChild(cancelLabel); sureItem->setAnchorPoint(ccp(0, 0)); cancelItem->setAnchorPoint(ccp(0, 0)); CCMenu *menu = CCMenu::menuWithItems(sureItem,cancelItem,NULL); menu->setPosition(ccp(0, 0)); addChild(menu); TextNode *titleLabel = TextNode::textWithString(CGameData::Inst()->getLanguageValue("deadDlgtip1"), 55); titleLabel->setColor(ccc3(122, 37, 8)); addChild(titleLabel); titleLabel->setPosition(ccp(320, 420+255)); if(type == enDeadType_normal) { if (hold<need) { snprintf(buf, 99, "%s%d%s",CGameData::Inst()->getLanguageValue("deadDlgtip2"),need,CGameData::Inst()->getLanguageValue("deadDlgtip3")); } else { snprintf(buf, 99, "%s%d%s",CGameData::Inst()->getLanguageValue("deadDlgtip2"),need,CGameData::Inst()->getLanguageValue("deadDlgtip4")); } infoLabel = TextNode::textWithString(buf, CCSize(388, 70), CCTextAlignmentCenter, 30); infoLabel->setPosition(ccp(320, 300+255)); infoLabel->setColor(ccc3(63, 23, 13)); addChild(infoLabel); } else if(type == enDeadType_free) { snprintf(buf, 99,CGameData::Inst()->getLanguageValue("deadDlgtip7"),CGameData::Inst()->getCommonInfo()->free_revive_lv); infoLabel = TextNode::textWithString(buf, CCSize(388, 110), CCTextAlignmentCenter, 30); infoLabel->setPosition(ccp(320, 300+205)); infoLabel->setColor(ccc3(63, 23, 13)); addChild(infoLabel); } if(type == enDeadType_normal) { snprintf(buf, 99,"%s%ld%s!",CGameData::Inst()->getLanguageValue("deadDlgtip5"),hold,CGameData::Inst()->getLanguageValue("deadDlgtip6")); myYuanbaoLabel = TextNode::textWithString(buf, CCSize(388, 70), CCTextAlignmentCenter, 30); myYuanbaoLabel->setPosition(ccp(320, 190+255)); myYuanbaoLabel->setColor(ccc3(63, 23, 13)); addChild(myYuanbaoLabel); } }
//////////////////////////////////////////////////////// // // NodeChildrenMainScene // //////////////////////////////////////////////////////// void NodeChildrenMainScene::initWithQuantityOfNodes(unsigned int nNodes) { //srand(time()); Size s = Director::sharedDirector()->getWinSize(); // Title LabelTTF *label = LabelTTF::create(title().c_str(), "Arial", 40); addChild(label, 1); label->setPosition(ccp(s.width/2, s.height-32)); label->setColor(ccc3(255,255,40)); // Subtitle std::string strSubTitle = subtitle(); if(strSubTitle.length()) { LabelTTF *l = LabelTTF::create(strSubTitle.c_str(), "Thonburi", 16); addChild(l, 1); l->setPosition(ccp(s.width/2, s.height-80)); } lastRenderedCount = 0; currentQuantityOfNodes = 0; quantityOfNodes = nNodes; MenuItemFont::setFontSize(65); MenuItemFont *decrease = MenuItemFont::create(" - ", [&](Object *sender) { quantityOfNodes -= kNodesIncrease; if( quantityOfNodes < 0 ) quantityOfNodes = 0; updateQuantityLabel(); updateQuantityOfNodes(); }); decrease->setColor(ccc3(0,200,20)); MenuItemFont *increase = MenuItemFont::create(" + ", [&](Object *sender) { quantityOfNodes += kNodesIncrease; if( quantityOfNodes > kMaxNodes ) quantityOfNodes = kMaxNodes; updateQuantityLabel(); updateQuantityOfNodes(); }); increase->setColor(ccc3(0,200,20)); Menu *menu = Menu::create(decrease, increase, NULL); menu->alignItemsHorizontally(); menu->setPosition(ccp(s.width/2, s.height/2+15)); addChild(menu, 1); LabelTTF *infoLabel = LabelTTF::create("0 nodes", "Marker Felt", 30); infoLabel->setColor(ccc3(0,200,20)); infoLabel->setPosition(ccp(s.width/2, s.height/2-15)); addChild(infoLabel, 1, kTagInfoLayer); NodeChildrenMenuLayer* pMenu = new NodeChildrenMenuLayer(true, TEST_COUNT, s_nCurCase); addChild(pMenu); pMenu->release(); updateQuantityLabel(); updateQuantityOfNodes(); }
void UpStateLayer::startAnimationDisplay(int level,long goal){ switch (SettingHelper::getGameType()) { case GAME_TYPE_CLASSIC: m_Top_bg->setVisible(true); m_Level_bg->setVisible(false); // m_Goal_bg->setVisible(false); m_Score_bg->setVisible(true); m_labelTop->setString(CCString::createWithFormat("%i",SettingHelper::getToppestScore4Classic())->getCString()); break; case GAME_TYPE_CLASSIC_LEVEL: m_Top_bg->setVisible(false); m_Level_bg->setVisible(true); // m_Goal_bg->setVisible(true); m_Score_bg->setVisible(true); m_labelTop->setString(CCString::createWithFormat("%i",SettingHelper::getToppestScore4ClassicLevel())->getCString()); break; case GAME_TYPE_SPEED: m_Top_bg->setVisible(true); m_Level_bg->setVisible(false); // m_Goal_bg->setVisible(false); m_Score_bg->setVisible(true); m_labelTop->setString(CCString::createWithFormat("%i",SettingHelper::getToppestScore4Tap())->getCString()); break; case GAME_TYPE_SPEED_LEVEL: m_Top_bg->setVisible(false); m_Level_bg->setVisible(true); // m_Goal_bg->setVisible(true); m_Score_bg->setVisible(true); m_labelTop->setString(CCString::createWithFormat("%i",SettingHelper::getToppestScore4TapLevel())->getCString()); break; case GAME_TYPE_NOTIMELIMIT: m_Top_bg->setVisible(false); m_Level_bg->setVisible(true); // m_Goal_bg->setVisible(true); m_Score_bg->setVisible(true); m_labelTop->setString(CCString::createWithFormat("%i",SettingHelper::getToppestScore4NoLimit())->getCString()); break; default: break; } m_labelLevel->setString(CCString::createWithFormat("%i",level)->getCString()); m_labelGoal->setString(CCString::createWithFormat("%li",goal)->getCString()); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); this->setVisible(true); this->setAnchorPoint(ccp(0, 0)); this->setPosition(ccp(0, origin.y+visibleSize.height)); CCMoveBy * moveTo2 = CCMoveBy::create(0.2, ccp(0, -UpHeight)); this->runAction(CCSequence::create(CCEaseBackOut::create(moveTo2),NULL)); }
bool WelComeGameLayer::setUpdateView(){ bool isRet=false; do { // 从缓存中 取出 背景图片 CCTexture2D* texturebg= CCTextureCache::sharedTextureCache()->textureForKey("gmbg/welcomebg.png"); CCSprite* pSpriteBg=CCSprite::createWithTexture(texturebg); CC_BREAK_IF(!pSpriteBg); pSpriteBg->setPosition(getWinCenter()); this->addChild(pSpriteBg,1); // 添加声音菜单按钮 CCTexture2D* textureon = CCTextureCache::sharedTextureCache()->textureForKey("gmme/button_sound_on.png"); CCTexture2D* textureoff = CCTextureCache::sharedTextureCache()->textureForKey("gmme/button_sound_off.png"); CCMenuItemSprite* pitemVon=CCMenuItemSprite::create(CCSprite::createWithTexture(textureon),CCSprite::createWithTexture(textureon)); CC_BREAK_IF(!pitemVon); CCMenuItemSprite* pitemVoff=CCMenuItemSprite::create(CCSprite::createWithTexture(textureoff),CCSprite::createWithTexture(textureoff)); CC_BREAK_IF(!pitemVoff); CCMenuItemToggle* pVedioTo=NULL; // 当现在 音乐是 播放的时候界面上显示的按钮应该是 暂停音乐按钮 反之 则显示播放按钮 if(CCUserDefault::sharedUserDefault()->getBoolForKey("isplay",false)){ pVedioTo=CCMenuItemToggle::createWithTarget(this,menu_selector(WelComeGameLayer::vedioOnAndOffCallBack),pitemVoff,pitemVon,NULL); }else { pVedioTo=CCMenuItemToggle::createWithTarget(this,menu_selector(WelComeGameLayer::vedioOnAndOffCallBack),pitemVon,pitemVoff,NULL); } CC_BREAK_IF(!pVedioTo); // 注意 里面的 0.15 和0.55 都是 通过PS 定位 看看这个图片放在那里计算出来的 pVedioTo->setPosition(converSpritRel(getWinSize().width*0.15f,getWinSize().height*0.55f)); // 创建开始菜单 CCTexture2D* texturestar_up = CCTextureCache::sharedTextureCache()->textureForKey("gmme/star_up.png"); CCTexture2D* texturestar_down = CCTextureCache::sharedTextureCache()->textureForKey("gmme/star_down.png"); CCMenuItemSprite* pStar=CCMenuItemSprite::create(CCSprite::createWithTexture(texturestar_up),CCSprite::createWithTexture(texturestar_down),this,menu_selector(WelComeGameLayer::menuStarGame)); CC_BREAK_IF(!pStar); pStar->setPosition(ccp(getWinSize().width*0.83f,getWinSize().height*0.75f)); // 创建升级系统菜单 CCTexture2D* textureup_up = CCTextureCache::sharedTextureCache()->textureForKey("gmme/upup.png"); CCTexture2D* textureup_down = CCTextureCache::sharedTextureCache()->textureForKey("gmme/updwon.png"); CCMenuItemSprite* pup=CCMenuItemSprite::create(CCSprite::createWithTexture(textureup_up),CCSprite::createWithTexture(textureup_down),this,menu_selector(WelComeGameLayer::menuUpGameCallback)); CC_BREAK_IF(!pup); pup->setPosition(ccp(660,275)); // 创建退出游戏菜单 CCTexture2D* textureout_up = CCTextureCache::sharedTextureCache()->textureForKey("gmme/outup.png"); CCTexture2D* textureout_down = CCTextureCache::sharedTextureCache()->textureForKey("gmme/outdown.png"); CCMenuItemSprite* pout=CCMenuItemSprite::create(CCSprite::createWithTexture(textureout_up),CCSprite::createWithTexture(textureout_down),this,menu_selector(WelComeGameLayer::menuGameOverCallback)); CC_BREAK_IF(!pout); pout->setPosition(ccp(640,190)); // 创建开发者 菜单按钮 CCTexture2D* texturecoder_up = CCTextureCache::sharedTextureCache()->textureForKey("gmme/coder_up.png"); CCTexture2D* texturecoder_down = CCTextureCache::sharedTextureCache()->textureForKey("gmme/coder_down.png"); CCMenuItemSprite* pcoder=CCMenuItemSprite::create(CCSprite::createWithTexture(texturecoder_up),CCSprite::createWithTexture(texturecoder_down),this,menu_selector(WelComeGameLayer::menuCoderCallback)); CC_BREAK_IF(!pcoder); pcoder->setPosition(converSpritRel(getWinSize().width*0.78f,getWinSize().height*0.21f)); CCMenu* pMenu=CCMenu::create(pVedioTo,pStar,pup,pout,pcoder,NULL); CC_BREAK_IF(!pMenu); pMenu->setPosition(CCPointZero); this->addChild(pMenu,2); isRet=true; } while (0); return isRet; }
//----------------------------------------------------- // // void CGameMenu::onEnter() { CNd91Mng::RemoveBanner(); CNd91Mng::InitadBanner(); CGameScene::onEnter(); CCSize s = CCDirector::sharedDirector()->getWinSize(); CCXMLLayer *pXMLLayer = new CCXMLLayer(); pXMLLayer->init(); pXMLLayer->autorelease(); pXMLLayer->LoadPlist( s_MenuLeveFile ); addChild( pXMLLayer ); const char *MenuButton[] = { "button_online", "button_offline", "button_option", "button_about", "button_91", "button_elves", }; for( int i = 0; i < MAX_GAME_MENU_NUM; i++ ) { CCSprite *pSprite= (CCSprite*)pXMLLayer->GetXMLNodeFromKey( MenuButton[i] ); CCMenu *pMenu = CreatGameUIWithSprite( pSprite, menu_selector(CGameMenu::menuCallback), i, this, pSprite->getPosition() ); pXMLLayer->removeChild( pSprite, true ); addChild( pMenu ); m_pMenu[i] = pMenu; } if( CCUserDefault::sharedUserDefault()->getBoolForKey( "music" ) ) { CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("data/audio/menubg.mp3", true); } //string strPath = GetGameImagesPath(); //strPath = strPath + "UI/r1-hd.png"; //CCMenu* pMenu = CreatGameUIButton( strPath,"", menu_selector( CGameMenu::menuCallback), 10, this, ccp( s.width / 2, s.height / 2 ) ); //addChild(pMenu); //CCLabelTTF *label = CCLabelTTF::labelWithString("play", "Arial", 16); //label->setPosition( pMenu->getPosition() ); //addChild( label, 0 ); std::string effectpath = GetGameParticlePath(); std::string filename = effectpath + "Glitter.plist"; CCParticleSystemQuad *pEmitter = CCParticleSystemQuad::particleWithFile( filename.c_str() ); //m_emitter->setPositionType( kCCPositionTypeRelative ); pEmitter->setPosition( getPosition() ); CCPoint pos = getPosition(); addChild( pEmitter, 100 ); effectpath = GetGameParticlePath(); filename = effectpath + "leaf.plist"; pEmitter = CCParticleSystemQuad::particleWithFile( filename.c_str() ); //m_emitter->setPositionType( kCCPositionTypeRelative ); pEmitter->setPosition( ccp( 0, s.height )); pos = getPosition(); addChild( pEmitter, 100 ); //CurlTest *pCurlTest = new CurlTest(); //addChild(pCurlTest); }
CCPoint BBSimpleBulletSprite::getVelocity(){ return ccp( m_xVel, m_yVel); }
bool VVAlertView::initWithTitle(const char* aTitle, const char* aMessage, VVAlertViewDelegate* aDelegate, const char* aCancelBtnTitle, const char* aOtherBtnTitle) { if ( !VVPopupLayer::init() ) return false; delegate = aDelegate; overlayLayer->removeFromParentAndCleanup(true); CCLabelTTF *titleLabel = NULL; if( aTitle != NULL ) { titleLabel = CCLabelTTF ::labelWithString(aTitle ,fontName.c_str(), titleFontSize); } CCScale9Sprite *bg = CCScale9Sprite::scale9SpriteWithFile(alertBG_name.c_str(), alert9patch_rect); CCLabelTTF *msgLabel = CCLabelTTF::labelWithString(aMessage, CCSizeMake(maxWidth-borderPadding*4, 0), CCTextAlignmentCenter, fontName.c_str(), messageFontSize); CCMenuItemSprite* btnCancel = CCMenuItemDynamic::dynamicItemWithTTFLabel(aCancelBtnTitle, fontName.c_str(), messageFontSize, btnSize, btnBG_name.c_str(), NULL, this, menu_selector(VVAlertView::onBtnCancel), btn9patch_rect, 255); CCMenu *menu; if (aOtherBtnTitle == NULL) { menu = CCMenu::menuWithItems(btnCancel, NULL); } else { CCMenuItemSprite* btnOk = CCMenuItemDynamic::dynamicItemWithTTFLabel(aOtherBtnTitle, fontName.c_str(), messageFontSize, btnSize, btnBG_name.c_str(), NULL, this, menu_selector(VVAlertView::onBtnOk), btn9patch_rect, 255); menu = CCMenu::menuWithItems(btnCancel, btnOk, NULL); menu->alignItemsHorizontallyWithPadding(betweenBtnPadding); } menu->setTouchPriority(VVTouchPriorityMenuOnPopupLayer); addChild(bg); if (titleLabel) addChild(titleLabel); addChild(msgLabel); addChild(menu); if (titleLabel) totalHeight += titleLabel->getContentSize().height; totalHeight += msgLabel->getContentSize().height; totalHeight += btnCancel->getContentSize().height; totalHeight += centerPadding; totalHeight += messagePadding*2; totalHeight += borderPadding*2; float halfHeight = totalHeight/2; if (titleLabel) { titleLabel ->setPosition(ccp(0, halfHeight - borderPadding - titleLabel->getContentSize().height/2)); // -15 : top padding msgLabel ->setPosition(ccp(0, halfHeight - borderPadding - titleLabel->getContentSize().height - messagePadding - msgLabel->getContentSize().height/2 )); } else { msgLabel ->setPosition(ccp(0, halfHeight - borderPadding - msgLabel->getContentSize().height/2 )); } menu ->setPosition(ccp(0, -halfHeight + borderPadding + btnCancel->getContentSize().height/2)); bg->setContentSize(CCSizeMake(maxWidth, totalHeight)); // will be used for placing text field in the middle centerOfMargin = (msgLabel->getPosition().y + menu->getPosition().y)/2; return true; }
void ControlLayer::update(float dt) { if (sGlobal->hero->getPositionX()<5) { sGlobal->hero->isWin=true; } if (sGlobal->hero->isDead) { this->setTouchEnabled(false); } if (sGlobal->hero->isDead&&failedLayerInitTimes==0) { CCLayer *failedLayer=FailedLayer::create(); sGlobal->game_1_1->addChild(failedLayer,2); // CCLayer *victoryLayer=VictoryLayer::create(); // sGlobal->game_1_1->addChild(victoryLayer); failedLayerInitTimes=1; if (sGlobal->isEffectOn) { CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("Audio_boos.mp3",false); } } if(sGlobal->hero->isWin&&winLayerInitTimes==0) { CCLayer *victoryLayer=VictoryLayer::create(); sGlobal->game_1_1->addChild(victoryLayer); winLayerInitTimes=1; if (sGlobal->isEffectOn) { CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("Audio_congratulations.mp3",false); } } int hspeed=0; if (leftSpriteTouched) { hspeed=-3; }else if (rightSpriteTouched) { hspeed=3; }else{ hspeed=0; } sGlobal->hero->move(hspeed); if (jumpSpriteTouched&&sGlobal->hero->isDead==false) { if (sGlobal->hero->isJumpDone) { if (sGlobal->isEffectOn) { CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("Audio_jump.mp3",false); } sGlobal->hero->isJumpDone=false; sGlobal->hero->vspeed=11; } } sGlobal->hero->jump(); int x=0-sGlobal->game_1_1->getPositionX(); int y=0-sGlobal->game_1_1->getPositionY(); this->setPosition(ccp(x,y)); }
LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { BOOL bProcessed = FALSE; //CCLog("wParam:%d", wParam); switch (message) { case WM_MOUSEWHEEL: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_pDelegate) { POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) }; ScreenToClient(m_hWnd, &point); DPoint pt(point.x, point.y); pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); float zDelta = (short)HIWORD(wParam); if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::middleMouseEvent); handleScrollWheel(pt.x, pt.y, 0, zDelta, event); event->release(); } } break; case WM_MOUSEMOVE: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (MK_LBUTTON == wParam && m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; DPoint pt(point.x, point.y); int id = 0; pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::leftMouseEvent); handleTouchesMove(1, &id, &pt.x, &pt.y, event); event->release(); event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::movedMouseEvent); handleMouseMoved(pt.x, pt.y, event); event->release(); } break; case WM_MBUTTONDOWN: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_pDelegate && MK_MBUTTON == wParam) { POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) }; DPoint pt(point.x, point.y); pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); int id = 0; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::middleMouseEvent); handleOtherMouseDown(1, &id, &pt.x, &pt.y, event); event->release(); } } break; case WM_MBUTTONUP: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_pDelegate) { POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) }; DPoint pt(point.x, point.y); pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); int id = 0; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::middleMouseEvent); handleOtherMouseUp(1,&id, &pt.x, &pt.y, event); event->release(); } } break; case WM_LBUTTONDOWN: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_pDelegate && MK_LBUTTON == wParam) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; DPoint pt(point.x, point.y); pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); int id = 0; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::leftMouseEvent); handleTouchesBegin(1, &id, &pt.x, &pt.y, event); event->release(); } } break; case WM_LBUTTONUP: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; DPoint pt(point.x, point.y); int id = 0; pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::leftMouseEvent); handleTouchesEnd(1, &id, &pt.x, &pt.y, event); event->release(); ReleaseCapture(); m_bCaptured = false; } break; case WM_RBUTTONDOWN: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_pDelegate && MK_RBUTTON == wParam) { POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) }; DPoint pt(point.x, point.y); pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); int id = 0; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::rightMouseEvent); handleTouchesBegin(1, &id, &pt.x, &pt.y, event); event->release(); } } break; case WM_RBUTTONUP: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_bCaptured) { POINT point = { (short)LOWORD(lParam), (short)HIWORD(lParam) }; DPoint pt(point.x, point.y); int id = 0; pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::rightMouseEvent); handleTouchesEnd(1, &id, &pt.x, &pt.y, event); event->release(); ReleaseCapture(); m_bCaptured = false; } break; #if(_MSC_VER >= 1600) case WM_TOUCH: { BOOL bHandled = FALSE; UINT cInputs = LOWORD(wParam); PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs]; if (pInputs) { if (s_pfGetTouchInputInfoFunction((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT))) { for (UINT i=0; i < cInputs; i++) { TOUCHINPUT ti = pInputs[i]; POINT input; input.x = TOUCH_COORD_TO_PIXEL(ti.x); input.y = TOUCH_COORD_TO_PIXEL(ti.y); ScreenToClient(m_hWnd, &input); DPoint pt(input.x, input.y); DPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(DRectZero) || m_obViewPortRect.containsPoint(tmp)) { pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; CrossApp::CAEvent* event = new CrossApp::CAEvent(); event->setEventType(CrossApp::EventType::leftMouseEvent); if (ti.dwFlags & TOUCHEVENTF_DOWN) handleTouchesBegin(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y, event); else if (ti.dwFlags & TOUCHEVENTF_MOVE) handleTouchesMove(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y, event); else if (ti.dwFlags & TOUCHEVENTF_UP) handleTouchesEnd(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y, event); event->release(); } } bHandled = TRUE; } delete [] pInputs; } if (bHandled) { s_pfCloseTouchInputHandleFunction((HTOUCHINPUT)lParam); } } break; #endif /* #if(_MSC_VER >= 1600) */ case WM_SIZE: { static int oldWidth = 0, oldHeight = 0, windowState = 0; switch (wParam) { case SIZE_RESTORED: { if (windowState == 2) { CCApplication::sharedApplication()->applicationWillEnterForeground(); } else if (windowState == 1) { this->setFrameSize(oldWidth, oldHeight); CCApplication::sharedApplication()->applicationDidExitFullScreen(); } windowState = 0; } break; case SIZE_MAXIMIZED: { if (windowState == 2) { CCApplication::sharedApplication()->applicationWillEnterForeground(); } else if (windowState == 0) { oldWidth = m_obScreenSize.width * 2; oldHeight = m_obScreenSize.height * 2; RECT rt; SystemParametersInfo(SPI_GETWORKAREA, 0, &rt, 0); // 获得工作区大小 int w = (rt.right - rt.left) * 2; int h = (rt.bottom - rt.top - 24) * 2; this->setFrameSize(w, h); CCApplication::sharedApplication()->applicationDidToggleFullScreen(); } windowState = 1; } break; case SIZE_MINIMIZED: { CCApplication::sharedApplication()->applicationDidEnterBackground(); windowState = 2; } break; } } break; case WM_KEYDOWN: switch (wParam) { case VK_F1: if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0) CAApplication::getApplication()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked); break; case VK_F2: if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0) CAApplication::getApplication()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeMenuClicked); break; case VK_ESCAPE: CAApplication::getApplication()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked); break; case VK_LEFT: CAIMEDispatcher::sharedDispatcher()->dispatchCursorMoveBackward(); break; case VK_RIGHT: CAIMEDispatcher::sharedDispatcher()->dispatchCursorMoveForward(); break; case VK_UP: CAIMEDispatcher::sharedDispatcher()->dispatchCursorMoveUp(); break; case VK_DOWN: CAIMEDispatcher::sharedDispatcher()->dispatchCursorMoveDown(); break; case 'C': case 'X': if (GetKeyState(VK_CONTROL) < 0) { if (wParam == 'C') { CAIMEDispatcher::sharedDispatcher()->dispatchCopyToClipboard(); } else { CAIMEDispatcher::sharedDispatcher()->dispatchCutToClipboard(); } } break; case 'V': if (GetKeyState(VK_CONTROL) < 0) { CAIMEDispatcher::sharedDispatcher()->dispatchPasteFromClipboard(); } break; case 'A': if (GetKeyState(VK_CONTROL) < 0) { CAIMEDispatcher::sharedDispatcher()->dispatchSelectAll(); } break; default: break; } if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } break; case WM_KEYUP: if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } break; case WM_CHAR: { if (wParam < 0x20) { if (VK_BACK == wParam) { CAIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(); } else if (VK_RETURN == wParam) { CAIMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1); } else if (VK_TAB == wParam) { // tab input } else if (VK_ESCAPE == wParam) { // ESC input //CCDirector::sharedDirector()->end(); } } else if (wParam < 128) { // ascii char CAIMEDispatcher::sharedDispatcher()->dispatchInsertText((const char *)&wParam, 1); } else { char szUtf8[8] = {0}; int nLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&wParam, 1, szUtf8, sizeof(szUtf8), NULL, NULL); CAIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen); } if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } } break; case WM_PAINT: PAINTSTRUCT ps; BeginPaint(m_hWnd, &ps); EndPaint(m_hWnd, &ps); break; case WM_CLOSE: CAApplication::getApplication()->end(); break; case WM_DESTROY: destroyGL(); PostQuitMessage(0); break; default: if (m_wndproc) { m_wndproc(message, wParam, lParam, &bProcessed); if (bProcessed) break; } return DefWindowProc(m_hWnd, message, wParam, lParam); } if (m_wndproc && !bProcessed) { m_wndproc(message, wParam, lParam, &bProcessed); } return 0; }
void CCLabelBMFont::createFontChars() { int nextFontPositionX = 0; int nextFontPositionY = 0; unsigned short prev = -1; int kerningAmount = 0; CCSize tmpSize = CCSizeZero; int longestLine = 0; unsigned int totalHeight = 0; unsigned int quantityOfLines = 1; unsigned int stringLen = m_sString.length(); if (0 == stringLen) { return; } for (unsigned int i = 0; i < stringLen - 1; ++i) { unsigned short c = m_sString[i]; if (c == '\n') { quantityOfLines++; } } totalHeight = m_pConfiguration->m_uCommonHeight * quantityOfLines; nextFontPositionY = -(m_pConfiguration->m_uCommonHeight - m_pConfiguration->m_uCommonHeight * quantityOfLines); for (unsigned int i= 0; i < stringLen; i++) { unsigned short c = m_sString[i]; CCAssert( c < kCCBMFontMaxChars, "LabelBMFont: character outside bounds"); if (c == '\n') { nextFontPositionX = 0; nextFontPositionY -= m_pConfiguration->m_uCommonHeight; continue; } kerningAmount = this->kerningAmountForFirst(prev, c); const ccBMFontDef& fontDef = m_pConfiguration->m_pBitmapFontArray[c]; CCRect rect = fontDef.rect; CCSprite *fontChar; fontChar = (CCSprite*)(this->getChildByTag(i)); if( ! fontChar ) { fontChar = new CCSprite(); fontChar->initWithBatchNodeRectInPixels(this, rect); this->addChild(fontChar, 0, i); fontChar->release(); } else { // reusing fonts fontChar->setTextureRectInPixels(rect, false, rect.size); // restore to default in case they were modified fontChar->setIsVisible(true); fontChar->setOpacity(255); } float yOffset = (float) (m_pConfiguration->m_uCommonHeight - fontDef.yOffset); fontChar->setPositionInPixels( ccp( nextFontPositionX + fontDef.xOffset + fontDef.rect.size.width / 2.0f + kerningAmount, (float) nextFontPositionY + yOffset - rect.size.height/2.0f ) ); // NSLog(@"position.y: %f", fontChar.position.y); // update kerning nextFontPositionX += m_pConfiguration->m_pBitmapFontArray[c].xAdvance + kerningAmount; prev = c; // Apply label properties fontChar->setIsOpacityModifyRGB(m_bIsOpacityModifyRGB); // Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on fontChar->setColor(m_tColor); // only apply opaccity if it is different than 255 ) // to prevent modifying the color too (issue #610) if( m_cOpacity != 255 ) { fontChar->setOpacity(m_cOpacity); } if (longestLine < nextFontPositionX) { longestLine = nextFontPositionX; } } tmpSize.width = (float) longestLine; tmpSize.height = (float) totalHeight; this->setContentSizeInPixels(tmpSize); }
MainFooterLayer::MainFooterLayer() { mFootContainer = BaseSprite::create("zhuye_anniu_bg.png"); addChild(mFootContainer); CCPoint originPos = CCDirector::sharedDirector()->getVisibleOrigin(); mFootContainer->setPosition(ccp(mWinSize.width/2,originPos.y + mFootContainer->getContentSize().height/2)); //menu // { // mMenuItemHome = CCMenuItemImage::create( // "function_main.png", // "function_main_select.png", // this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked)); // mMenuItemMaoxian = CCMenuItemImage::create( // "function_adventure.png", // "function_adventure_select.png", // this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked)); // mMenuItemZhuangbei = CCMenuItemImage::create( // "function_equipment.png", // "function_equipment_select.png", // this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked)); // mMenuItemJinji = CCMenuItemImage::create( // "function_pk.png", // "function_pk_select.png", // this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked)); // mMenuItemMengyou = CCMenuItemImage::create( // "function_friend.png", // "function_friend_select.png", // this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked)); // mMenuItemStore = CCMenuItemImage::create( // "function_shop.png", // "function_shop_select.png", // this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked)); // // // mMenu = CCMenu::create(mMenuItemHome, mMenuItemMaoxian, mMenuItemZhuangbei // , mMenuItemJinji,mMenuItemMengyou , mMenuItemStore, NULL); // addChild(mMenu,1); // mMenu->setPosition(CCPointZero); // // mMenuItemHome->setPosition(ccp(45+2,50)); // mMenuItemHome->setTag(TAG_MENU_HOME); // // mMenuItemMaoxian->setPosition(ccp(45+90+4,50)); // mMenuItemMaoxian->setTag(TAG_MENU_MAOXIAN); // // mMenuItemZhuangbei->setPosition(ccp(45+90*2+6,50)); // mMenuItemZhuangbei->setTag(TAG_MENU_ZHUANGBEI); // // mMenuItemJinji->setPosition(ccp(640-45-90*2-6,50)); // mMenuItemJinji->setTag(TAG_MENU_JINJI); // // mMenuItemMengyou->setPosition(ccp(640-45-90-4,50)); // mMenuItemMengyou->setTag(TAG_MENU_MENGYOU); // // mMenuItemStore->setPosition(ccp(640-45-2,50)); // mMenuItemStore->setTag(TAG_MENU_STORE); // } { CCMenuItemImage *itemMaoxian = CCMenuItemImage::create( "zhuye_anniu_maoxian.png", "zhuye_anniu_maoxian_select.png", this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked)); CCMenuItemImage *itemJingji = CCMenuItemImage::create( "zhuye_anniu_jingji.png", "zhuye_anniu_jingji_select.png", this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked)); CCMenuItemImage *itemZhuye = CCMenuItemImage::create( "zhuye_anniu_zhuye_select.png", "zhuye_anniu_zhuye.png", this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked)); CCMenuItemImage *itemHuodong = CCMenuItemImage::create( "zhuye_anniu_huodong.png", "zhuye_anniu_huodong_select.png", this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked)); CCMenuItemImage *itemShangdian = CCMenuItemImage::create( "zhuye_anniu_shangdian.png", "zhuye_anniu_shangdian_select.png", this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked)); mMenu = CCMenu::create(itemMaoxian, itemShangdian, itemZhuye, itemJingji, itemHuodong, NULL); mFootContainer->addChild(mMenu,1); mMenu->setPosition(CCPointZero); itemZhuye->setPosition(ccp(320, 122-68)); itemZhuye->setTag(TAG_MENU_HOME); itemJingji->setPosition(ccp(itemZhuye->getPositionX()-itemJingji->getContentSize().width/2-itemZhuye->getContentSize().width/2, 122-68)); itemJingji->setTag(TAG_MENU_JINGJI); itemMaoxian->setPosition(ccp(itemJingji->getPositionX()-itemJingji->getContentSize().width/2-itemJingji->getContentSize().width/2, 122-68)); itemMaoxian->setTag(TAG_MENU_MAOXIAN); itemHuodong->setPosition(ccp(itemZhuye->getPositionX()+itemZhuye->getContentSize().width/2+itemHuodong->getContentSize().width/2, 122-68)); itemHuodong->setTag(TAG_MENU_HUODONG); itemShangdian->setPosition(ccp(itemHuodong->getPositionX()+itemHuodong->getContentSize().width/2+itemShangdian->getContentSize().width/2, 122-68)); itemShangdian->setTag(TAG_MENU_STORE); } //初始化是打开第一个界面 selectedIndex = mainlayer_ZhuYe; this->getNewMessageInfo(NULL); this->unschedule(schedule_selector(MainFooterLayer::updateMessage)); this->schedule(schedule_selector(MainFooterLayer::updateMessage), 4); //显示竞技效果 checkIsShowLiziAni(NULL); //检查极限守城活动是否开启 this->unschedule(schedule_selector(MainFooterLayer::checkJixianshouchengIsOpen)); this->schedule(schedule_selector(MainFooterLayer::checkJixianshouchengIsOpen), 1); }
bool InfoSlide6::init(){ if (!CCLayer::init()) { return false; } size = CCDirector::sharedDirector()->getWinSize(); dScaleX = size.width / 768 , dScaleY = size.height / 1024; ccColor3B strokeColor = { 255, 255, 255 }; ccFontDefinition strokeTextDef; strokeTextDef.m_fontSize = 60*dScaleX; strokeTextDef.m_fontName = std::string("Dimbo Regular"); strokeTextDef.m_stroke.m_strokeColor = strokeColor; strokeTextDef.m_stroke.m_strokeEnabled = true; strokeTextDef.m_stroke.m_strokeSize = 1.8; m_lTitleLabel = CCLabelTTF::createWithFontDefinition("Power Up`s", strokeTextDef); m_lTitleLabel->setPosition(ccp(size.width / 2, size.height - 220*dScaleY)); m_lTitleLabel->setScaleX(m_lTitleLabel->getScaleX()*0.9f); m_lTitleLabel->setScaleY(m_lTitleLabel->getScaleY()*1.2f); addChild(m_lTitleLabel); m_lDescriptionLabel1 = CCLabelTTF::createWithFontDefinition("Visit the Power Up`s! screen to redeem \nToken for power up`s.", strokeTextDef); m_lDescriptionLabel1->setPosition(ccp(size.width *3/4-100*dScaleX, size.height / 2 + 200*dScaleY)); m_lDescriptionLabel1->setScaleX(m_lDescriptionLabel1->getScaleX()*0.5f); m_lDescriptionLabel1->setScaleY(m_lDescriptionLabel1->getScaleY()*0.7f); m_lDescriptionLabel1->setHorizontalAlignment(kCCTextAlignmentLeft); addChild(m_lDescriptionLabel1); m_lDescriptionLabel2 = CCLabelTTF::createWithFontDefinition("The Penalty-Free Hint(PFH) gives you a\nHint without affecting your score.", strokeTextDef); m_lDescriptionLabel2->setPosition(ccp(size.width *3/4-100*dScaleX, size.height / 2+ 50*dScaleY)); m_lDescriptionLabel2->setScaleX(m_lDescriptionLabel2->getScaleX()*0.5f); m_lDescriptionLabel2->setScaleY(m_lDescriptionLabel2->getScaleY()*0.7f); m_lDescriptionLabel2->setHorizontalAlignment(kCCTextAlignmentLeft); addChild(m_lDescriptionLabel2); m_lDescriptionLabel3 = CCLabelTTF::createWithFontDefinition("Need more raffle tickets? Redeem some \nTokens to Power Up and get them.", strokeTextDef); m_lDescriptionLabel3->setPosition(ccp(size.width *3/4-100*dScaleX, size.height / 2- 100 *dScaleY)); m_lDescriptionLabel3->setScaleX(m_lDescriptionLabel3->getScaleX()*0.5f); m_lDescriptionLabel3->setScaleY(m_lDescriptionLabel3->getScaleY()*0.7f); m_lDescriptionLabel3->setHorizontalAlignment(kCCTextAlignmentLeft); addChild(m_lDescriptionLabel3); m_lDescriptionLabel4 = CCLabelTTF::createWithFontDefinition("No Magic shoe box? Grab some beast \ntraps and get rid of Hypebeast john", strokeTextDef); m_lDescriptionLabel4->setPosition(ccp(size.width *3/4-110*dScaleX, size.height / 2 - 250*dScaleY)); m_lDescriptionLabel4->setScaleX(m_lDescriptionLabel4->getScaleX()*0.5f); m_lDescriptionLabel4->setScaleY(m_lDescriptionLabel4->getScaleY()*0.7f); m_lDescriptionLabel4->setHorizontalAlignment(kCCTextAlignmentLeft); addChild(m_lDescriptionLabel4); CCSprite* symbol1 = CCSprite::create("*****@*****.**"); symbol1->setPosition(ccp(100*dScaleX, size.height / 2 + 200*dScaleY)); symbol1->setScaleX(symbol1->getScaleX()*dScaleX); symbol1->setScaleY(symbol1->getScaleY()*dScaleY); addChild(symbol1); CCSprite* symbol2 = CCSprite::create("*****@*****.**"); symbol2->setPosition(ccp(100*dScaleX, size.height / 2 + 50*dScaleY)); symbol2->setScaleX(symbol2->getScaleX()*dScaleX); symbol2->setScaleY(symbol2->getScaleY()*dScaleY); addChild(symbol2); CCSprite* symbol3 = CCSprite::create("*****@*****.**"); symbol3->setPosition(ccp(100*dScaleX, size.height / 2 - 100*dScaleY)); symbol3->setScaleX(symbol3->getScaleX()*dScaleX); symbol3->setScaleY(symbol3->getScaleY()*dScaleY); addChild(symbol3); CCSprite* symbol4 = CCSprite::create("*****@*****.**"); symbol4->setPosition(ccp(100*dScaleX, size.height / 2 -250*dScaleY)); symbol4->setScaleX(symbol4->getScaleX()*dScaleX); symbol4->setScaleY(symbol4->getScaleY()*dScaleY); addChild(symbol4); return true; }