bool CCControlSliderTest::init() { if (CCControlScene::init()) { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); // Add a label in which the slider value will be displayed m_pDisplayValueLabel = CCLabelTTF::create("Move the slider thumb!" ,"Marker Felt", 32); m_pDisplayValueLabel->retain(); m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1.0f)); m_pDisplayValueLabel->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); addChild(m_pDisplayValueLabel); // Add the slider CCControlSlider *slider = CCControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png"); slider->setAnchorPoint(ccp(0.5f, 1.0f)); slider->setMinimumValue(0.0f); // Sets the min value of range slider->setMaximumValue(5.0f); // Sets the max value of range slider->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); // When the value of the slider will change, the given selector will be call slider->addTargetWithActionForControlEvents(this, cccontrol_selector(CCControlSliderTest::valueChanged), CCControlEventValueChanged); addChild(slider); return true; } return false; }
CCControlSlider* ShaderBlur::createSliderCtl() { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); CCControlSlider *slider = CCControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png"); slider->setAnchorPoint(ccp(0.5f, 1.0f)); slider->setMinimumValue(0.0f); // Sets the min value of range slider->setMaximumValue(3.0f); // Sets the max value of range slider->setValue(1.0f); slider->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 3.0f)); // When the value of the slider will change, the given selector will be call slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ShaderBlur::sliderAction), CCControlEventValueChanged); return slider; }
bool SettingsLayer::init(){ if (!DialogLayer::init()) { return false; } this->setTitle("设 置"); CCLabelTTF* acountLabel=CCLabelTTF::create("账 号:", "", 20); acountLabel->setPosition(S_RM->getPositionWithName("setting_acountLabel")); acountLabel->setColor(ccc3(0, 0, 0)); this->addChild(acountLabel); Button9* userLabel=Button9::create("",CCSizeMake(400, 50),20); m_userItem=CCMenuItemSprite::create(userLabel, userLabel, this, menu_selector(SettingsLayer::menuCallback)); m_userItem->setPosition(S_RM->getPositionWithName("setting_acountItem")); m_userItem->setAnchorPoint(ccp(0,0.5)); this->addMenuItem(m_userItem); CCLabelTTF* childLabel=CCLabelTTF::create("儿 童:", "", 20); childLabel->setPosition(S_RM->getPositionWithName("setting_childLabel")); childLabel->setColor(ccc3(0, 0, 0)); this->addChild(childLabel); Button9* child=Button9::create("设 置",CCSizeMake(400, 50),20); CCMenuItemSprite* childItem=CCMenuItemSprite::create(child, child, this, menu_selector(SettingsLayer::menuCallback)); childItem->setPosition(S_RM->getPositionWithName("setting_childItem")); childItem->setAnchorPoint(ccp(0,0.5)); childItem->setTag(kTagChild); this->addMenuItem(childItem); CCLabelTTF* resetLabel=CCLabelTTF::create("学习进度: ", "", 20); resetLabel->setPosition(S_RM->getPositionWithName("setting_resetLabel")); resetLabel->setColor(ccc3(0, 0, 0)); this->addChild(resetLabel); Button9* reset=Button9::create("重 置",CCSizeMake(150, 50),20); CCMenuItemSprite* resetItem=CCMenuItemSprite::create(reset, reset, this, menu_selector(SettingsLayer::menuCallback)); resetItem->setPosition(S_RM->getPositionWithName("setting_resetItem")); resetItem->setAnchorPoint(ccp(0,0.5)); resetItem->setTag(kTagReset); this->addMenuItem(resetItem); CCLabelTTF* timeLabel=CCLabelTTF::create("时间控制: ", "", 20); timeLabel->setPosition(S_RM->getPositionWithName("setting_timeLabel")); timeLabel->setColor(ccc3(0, 0, 0)); this->addChild(timeLabel); Button9* time=Button9::create("设 置",CCSizeMake(150, 50),20); CCMenuItemSprite* timeItem=CCMenuItemSprite::create(time, time, this, menu_selector(SettingsLayer::menuCallback)); timeItem->setPosition(S_RM->getPositionWithName("setting_timeItem")); timeItem->setAnchorPoint(ccp(0,0.5)); timeItem->setTag(kTagTime); this->addMenuItem(timeItem); CCLabelTTF* weixinLabel=CCLabelTTF::create("微信绑定:", "", 20); weixinLabel->setPosition(S_RM->getPositionWithName("setting_weixinLabel")); weixinLabel->setColor(ccc3(0, 0, 0)); this->addChild(weixinLabel); Button9* weixin=Button9::create("绑 定",CCSizeMake(150, 50),20); CCMenuItemSprite* weixinItem=CCMenuItemSprite::create(weixin, weixin, this, menu_selector(SettingsLayer::menuCallback)); weixinItem->setPosition(S_RM->getPositionWithName("setting_weixinItem")); weixinItem->setAnchorPoint(ccp(0,0.5)); weixinItem->setTag(kTagWeixin); this->addMenuItem(weixinItem); #if (CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID) if (S_UD->getStringForKey("USER_USERNAME", "")=="") { CCLabelTTF* avatarLabel=CCLabelTTF::create("设置头像: ", "", 20); avatarLabel->setPosition(S_RM->getPositionWithName("setting_avatarLabel")); avatarLabel->setColor(ccc3(0, 0, 0)); this->addChild(avatarLabel); Button9* avatar=Button9::create("设 置",CCSizeMake(150, 50),20); CCMenuItemSprite* avatarItem=CCMenuItemSprite::create(avatar, avatar, this, menu_selector(SettingsLayer::menuCallback)); avatarItem->setPosition(S_RM->getPositionWithName("setting_avatarItem")); avatarItem->setAnchorPoint(ccp(0,0.5)); avatarItem->setTag(kTagAvatar); this->addMenuItem(avatarItem); } #endif //音量开关 CCLabelTTF* volumeLabel=CCLabelTTF::create("音 量:", "", 20); volumeLabel->setPosition(S_RM->getPositionWithName("setting_volumeLabel")); volumeLabel->setColor(ccc3(0, 0, 0)); this->addChild(volumeLabel); CCControlSlider* slider = CCControlSlider::create(CCSprite::createWithSpriteFrameName("volume_3.png"), CCSprite::createWithSpriteFrameName("volume_2.png"), CCSprite::createWithSpriteFrameName("volume_1.png")); slider->setMinimumValue(0.1f); // Sets the min value of range slider->setMaximumValue(1.0f); // Sets the max value of range slider->setPosition(S_RM->getPositionWithName("setting_volumeSlider")); slider->addTargetWithActionForControlEvents(this, cccontrol_selector(SettingsLayer::volumeValueChanged), CCControlEventValueChanged); slider->setTag(kTagVolume); slider->setAnchorPoint(ccp(0,0.5)); this->addChild(slider); float volume=S_AE->getBackgroundMusicVolume(); slider->setValue(volume); return true; }
bool Clayer_normalMapped::init() { this->setTouchEnabled(true); CCSize winSize=CCDirector::sharedDirector()->getWinSize();//winSize equals to designResolutionSize CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); //lightSprite m_lightSprite=new normalMapped::ClightSprite(); m_lightSprite->autorelease(); m_lightSprite->init("demoRes/light.png"); m_lightSprite->setPosition(ccp(winSize.width/4, winSize.height/4*3)); this->addChild(m_lightSprite); m_lightSprite->setZ(50); //normlMappedSprite m_normalMappedSprite=new CnormalMappedSprite(); m_normalMappedSprite->autorelease(); m_normalMappedSprite->init("demoRes/fish2.png","demoRes/fish2_normal.png"); m_normalMappedSprite->setPosition(ccp(winSize.width/2, winSize.height/2)); this->addChild(m_normalMappedSprite); m_normalMappedSprite->setLightSprite(m_lightSprite); //slider { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCControlSlider *slider = CCControlSlider::create("uiRes/sliderTrack.png", "uiRes/sliderProgress.png" , "uiRes/sliderThumb.png"); slider->setAnchorPoint(ccp(0.5f, 0.5f)); slider->setMinimumValue(0); // Sets the min value of range slider->setMaximumValue(1); // Sets the max value of range slider->setValue(m_lightSprite->getDiffuse().r); slider->setPosition(ccp(winSize.width *0.5, 180)); slider->addTargetWithActionForControlEvents(this, cccontrol_selector(Clayer_normalMapped::sliderAction), CCControlEventValueChanged); m_pSliderCtl=slider; addChild(m_pSliderCtl,100); //title CCLabelTTF* pLabel = CCLabelTTF::create("R ", "Arial", 40); pLabel->setPosition(ccp(slider->getPositionX()-slider->getContentSize().width/2-pLabel->getContentSize().width/2, slider->getPositionY())); this->addChild(pLabel, 1); } //slider2 { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCControlSlider *slider = CCControlSlider::create("uiRes/sliderTrack.png", "uiRes/sliderProgress.png", "uiRes/sliderThumb.png"); slider->setAnchorPoint(ccp(0.5f, 0.5f)); slider->setMinimumValue(0); // Sets the min value of range slider->setMaximumValue(1); // Sets the max value of range slider->setValue(m_lightSprite->getDiffuse().g); slider->setPosition(ccp(winSize.width *0.5, 180-40)); slider->addTargetWithActionForControlEvents(this, cccontrol_selector(Clayer_normalMapped::sliderAction2), CCControlEventValueChanged); m_pSliderCtl2=slider; addChild(m_pSliderCtl2,100); //title CCLabelTTF* pLabel = CCLabelTTF::create("G ", "Arial", 40); pLabel->setPosition(ccp(slider->getPositionX()-slider->getContentSize().width/2-pLabel->getContentSize().width/2, slider->getPositionY())); this->addChild(pLabel, 1); } //slider3 { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCControlSlider *slider = CCControlSlider::create("uiRes/sliderTrack.png", "uiRes/sliderProgress.png", "uiRes/sliderThumb.png"); slider->setAnchorPoint(ccp(0.5f, 0.5f)); slider->setMinimumValue(0); // Sets the min value of range slider->setMaximumValue(1); // Sets the max value of range slider->setValue(m_lightSprite->getDiffuse().b); slider->setPosition(ccp(winSize.width *0.5, 180-80)); slider->addTargetWithActionForControlEvents(this, cccontrol_selector(Clayer_normalMapped::sliderAction3), CCControlEventValueChanged); m_pSliderCtl3=slider; addChild(m_pSliderCtl3,100); //title CCLabelTTF* pLabel = CCLabelTTF::create("B ", "Arial", 40); pLabel->setPosition(ccp(slider->getPositionX()-slider->getContentSize().width/2-pLabel->getContentSize().width/2, slider->getPositionY())); this->addChild(pLabel, 1); } //slider4 { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCControlSlider *slider = CCControlSlider::create("uiRes/sliderTrack.png", "uiRes/sliderProgress.png", "uiRes/sliderThumb.png"); slider->setAnchorPoint(ccp(0.5f, 0.5f)); slider->setMinimumValue(1); // Sets the min value of range slider->setMaximumValue(4); // Sets the max value of range slider->setValue(m_normalMappedSprite->getKBump()); slider->setPosition(ccp(winSize.width *0.5, 180-120)); slider->addTargetWithActionForControlEvents(this, cccontrol_selector(Clayer_normalMapped::sliderAction4), CCControlEventValueChanged); m_pSliderCtl4=slider; addChild(m_pSliderCtl4,100); //title CCLabelTTF* pLabel = CCLabelTTF::create("kBump ", "Arial", 40); pLabel->setPosition(ccp(slider->getPositionX()-slider->getContentSize().width/2-pLabel->getContentSize().width/2, slider->getPositionY())); this->addChild(pLabel, 1); } //back button { CCScale9Sprite* btnUp=CCScale9Sprite::create("uiRes/button.png"); CCScale9Sprite* btnDn=CCScale9Sprite::create("uiRes/button_dn.png"); CCLabelTTF*title=CCLabelTTF::create("back", "Helvetica", 30); CCControlButton* controlButton=CCControlButton::create(title, btnUp); controlButton->setBackgroundSpriteForState(btnDn,CCControlStateHighlighted); controlButton->setPreferredSize(CCSize(100,50)); controlButton->setPosition(ccp(origin.x+visibleSize.width-controlButton->getContentSize().width/2,origin.y+controlButton->getContentSize().height/2)); controlButton->addTargetWithActionForControlEvents(this, (SEL_CCControlHandler)(&Clayer_normalMapped::controlButtonEvent_back), CCControlEventTouchUpInside); this->addChild(controlButton); m_controlButton_back=controlButton; } //title { { CCLabelTTF* pLabel = CCLabelTTF::create("Normal Mapped", "Arial", 45); // 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); } { CCLabelTTF* pLabel = CCLabelTTF::create("2013-11-4", "Arial", 30); pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height-60)); this->addChild(pLabel, 1); } { CCLabelTTF* pLabel = CCLabelTTF::create("move the light...", "Arial", 30); pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height-120)); this->addChild(pLabel, 1); } } return true; }
void GameSet::initContent() { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCLayerColor *colorlayer = CCLayerColor::create(ccc4(0, 0, 0, 120)); addChild(colorlayer); colorlayer->setPosition(ccp(-winSize.width/2, -winSize.height/2)); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("common/common.plist"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ui/gameSet/gameSet.plist"); CCSprite *bg = CCSprite::create("common/commonBg_451_305.png"); addChild(bg); CCSprite *titleBg = CCSprite::createWithSpriteFrameName("common_titleBg.png"); bg->addChild(titleBg); titleBg->setPosition(ccp(bg->getContentSize().width/2 + 50, bg->getContentSize().height)); CCLabelBMFont *title = CCLabelBMFont::create("设置", "font/font_uiTitle.fnt"); titleBg->addChild(title); title->setPosition(ccp(titleBg->getContentSize().width/2 - 50, titleBg->getContentSize().height/2)); CCScale9Sprite *frame = CCScale9Sprite::create("common/common_scale_1.png"); frame->setPreferredSize(CCSizeMake(328, 150)); frame->setAnchorPoint(ccp(0.5, 0.5)); bg->addChild(frame); frame->setPosition(ccp(bg->getContentSize().width/2, bg->getContentSize().height/2 + 40)); // CCSprite *title = CCSprite::createWithSpriteFrameName("set_title.png"); // bg->addChild(title); // title->setPosition(ccp(bg->getContentSize().width/2, bg->getContentSize().height - 20)); CCControlButton *closeBtn = INSTANCE(ButtonUtils)->createButton("common_backBtn.png", CCSizeMake(75, 81), ""); bg->addChild(closeBtn); closeBtn->setPosition(ccp(bg->getContentSize().width - 20, bg->getContentSize().height - 20)); closeBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(GameSet::close), CCControlEventTouchUpInside); CCLabelBMFont *musicLabel = CCLabelBMFont::create("音乐", "font/font_common.fnt"); bg->addChild(musicLabel); musicLabel->setPosition(ccp(115, 235)); CCControlSlider *musicSlider = CCControlSlider::create(CCSprite::createWithSpriteFrameName("set_barFrame.png"), CCSprite::createWithSpriteFrameName("set_barFrame.png"), CCSprite::createWithSpriteFrameName("set_barBtn.png")); musicSlider->setAnchorPoint(ccp(0.5f, 1.0f)); musicSlider->setMinimumValue(0.0f); // Sets the min value of range musicSlider->setMaximumValue(1.0f); // Sets the max value of range musicSlider->setTag(1); musicSlider->addTargetWithActionForControlEvents(this, cccontrol_selector(GameSet::musicCallBack), CCControlEventValueChanged); musicSlider->setPosition(ccp(260, 250)); musicSlider->setTouchPriority(0); float musicVolume = CCUserDefault::sharedUserDefault()->getFloatForKey(GameSet_musicVolume, 0.5); musicSlider->setValue(musicVolume); bg->addChild(musicSlider); CCLabelBMFont *soundLabel = CCLabelBMFont::create("音效", "font/font_common.fnt"); bg->addChild(soundLabel); soundLabel->setPosition(ccp(115, 185)); CCControlSlider *soundSlider = CCControlSlider::create(CCSprite::createWithSpriteFrameName("set_barFrame.png"), CCSprite::createWithSpriteFrameName("set_barFrame.png"), CCSprite::createWithSpriteFrameName("set_barBtn.png")); soundSlider->setAnchorPoint(ccp(0.5f, 1.0f)); soundSlider->setMinimumValue(0.0f); // Sets the min value of range soundSlider->setMaximumValue(1.0f); // Sets the max value of range soundSlider->setTag(1); soundSlider->addTargetWithActionForControlEvents(this, cccontrol_selector(GameSet::soundCallBack), CCControlEventValueChanged); soundSlider->setPosition(ccp(260, 200)); soundSlider->setTouchPriority(0); float soundVolume = CCUserDefault::sharedUserDefault()->getFloatForKey(GameSet_soundVolume, 0.5); soundSlider->setValue(soundVolume); bg->addChild(soundSlider); CCControlButton *btn1 = INSTANCE(ButtonUtils)->createButton("set_guide.png", CCSizeMake(84, 87), ""); CCControlButton *btn3 = INSTANCE(ButtonUtils)->createButton("set_contact.png", CCSizeMake(83, 84), ""); CCControlButton *btn4 = INSTANCE(ButtonUtils)->createButton("set_develep.png", CCSizeMake(83, 92), ""); bg->addChild(btn1); bg->addChild(btn3); bg->addChild(btn4); if(showHelp){ wikiBtn = INSTANCE(ButtonUtils)->createButton("set_wiki.png", CCSizeMake(87, 89), ""); bg->addChild(wikiBtn); btn1->setPosition(ccp(80, 50)); wikiBtn->setPosition(ccp(180, 50)); btn3->setPosition(ccp(280, 50)); btn4->setPosition(ccp(380, 50)); wikiBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(GameSet::btn2Handler), CCControlEventTouchUpInside); }else{ btn1->setPosition(ccp(80, 50)); btn3->setPosition(ccp(230, 50)); btn4->setPosition(ccp(380, 50)); } btn1->addTargetWithActionForControlEvents(this, cccontrol_selector(GameSet::btn1Handler), CCControlEventTouchUpInside); btn3->addTargetWithActionForControlEvents(this, cccontrol_selector(GameSet::btn3Handler), CCControlEventTouchUpInside); btn4->addTargetWithActionForControlEvents(this, cccontrol_selector(GameSet::btn4Handler), CCControlEventTouchUpInside); }
bool ControllerScene::init(){ CCMenu *menu = CCMenu::create(); menu->setPosition(CCPointZero); this->addChild(menu); CCLabelTTF *label = CCLabelTTF::create("CCTextFieldTTF", "Arial", 24); CCMenuItemLabel *item = CCMenuItemLabel::create(label, this, menu_selector(ControllerScene::menuItemClick1)); item->setPosition(ccp(320, 1100)); menu->addChild(item); label = CCLabelTTF::create("确定", "Arial", 24); m_btn = CCMenuItemLabel::create(label, this, menu_selector(ControllerScene::btnOk)); m_btn->setPosition(ccp(400, 1050)); menu->addChild(m_btn); m_texField = CCTextFieldTTF::textFieldWithPlaceHolder("input", CCSizeMake(200, 50), kCCTextAlignmentLeft, "Arial", 24); m_texField->setPosition(ccp(320, 1050)); this->addChild(m_texField); m_texField->attachWithIME(); m_name = CCLabelTTF::create("show info", "Arial", 24); m_name->setPosition(ccp(100, 1100)); this->addChild(m_name); //CCControlButton label+s9 label = CCLabelTTF::create("BUTTON", "Arial", 24); CCControlButton *btn = CCControlButton::create(label , CCScale9Sprite::create("start.png")); btn->setPreferredSize(CCSizeMake(228, 81)); btn->setLabelAnchorPoint(ccp(0.5, 2)); btn->setPosition(ccp(320, 1000)); this->addChild(btn); btn->addTargetWithActionForControlEvents(this, cccontrol_selector(ControllerScene::btnClick), CCControlEventTouchDown); //CCControlButton s9 CCScale9Sprite *s9 = CCScale9Sprite::create("start.png"); btn = CCControlButton::create(s9); btn->setPosition(ccp(320, 900)); btn->setPreferredSize(CCSizeMake(228, 81)); this->addChild(btn); //CCControlButton title btn = CCControlButton::create("CCControlButton", "Arial", 24); btn->setPosition(ccp(320, 800)); this->addChild(btn); //s9 // s9 = CCScale9Sprite::create("home.png"); // s9->setPosition(ccp(100, 800)); // this->addChild(s9); //CCControlColourPicker not useful CCControlColourPicker *cp = CCControlColourPicker::create(); cp->setPosition(ccp(320, 750)); this->addChild(cp); //CCControlPotentiometer CCControlPotentiometer *pot = CCControlPotentiometer::create("potentiometerTrack.png", "potentiometerProgress.png", "potentiometerButton.png"); pot->setPosition(ccp(100, 750)); this->addChild(pot); pot->setValue(90); //CCControlSlider CCControlSlider *slider = CCControlSlider::create("sliderTrack.png", "sliderProgress.png", "sliderThumb.png"); slider->setPosition(ccp(150, 600)); slider->setMinimumValue(0); slider->setMaximumValue(100); this->addChild(slider); slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ControllerScene::valueChanged), CCControlEventValueChanged); //CCControlStepper CCControlStepper *ste = CCControlStepper::create(CCSprite::create("stepper-minus.png"), CCSprite::create("stepper-plus.png")); ste->setPosition(ccp(320, 600)); this->addChild(ste); //CCControlSwitch CCControlSwitch *swi = CCControlSwitch::create(CCSprite::create("switch-mask.png"), CCSprite::create("switch-on.png"), CCSprite::create("switch-off.png"), CCSprite::create("switch-thumb.png"), CCLabelTTF::create("on", "Arial", 24), CCLabelTTF::create("off", "Arial", 24)); swi->setPosition(ccp(500, 600)); this->addChild(swi); // CCEditBox *edi = CCEditBox::create(CCSizeMake(200, 50), CCScale9Sprite::create("start.png")); edi->setPosition(ccp(150, 500)); this->addChild(edi); return true; }