bool SimpleLayer::init() { if (!BaseLayer::init()) { return false; } auto bg = LayerColor::create(Color4B::BLUE); addChild(bg, 1); _openButton = ControlButton::create("Open more layer", "", 30); _openButton->setPosition(Vec2(100, 400)); _openButton->setAnchorPoint(Vec2(0, 0)); _openButton->addTargetWithActionForControlEvents(this, cccontrol_selector(SimpleLayer::onOpenPressed), Control::EventType::TOUCH_UP_INSIDE); addChild(_openButton, 2); _closeButton = ControlButton::create("Close this layer", "", 30); _closeButton->setPosition(Vec2(100, 300)); _closeButton->setAnchorPoint(Vec2(0, 0)); _closeButton->addTargetWithActionForControlEvents(this, cccontrol_selector(SimpleLayer::onClosePressed), Control::EventType::TOUCH_UP_INSIDE); addChild(_closeButton, 2); return true; }
JSBool js_cocos2dx_CCControl_addTargetWithActionForControlEvents(JSContext *cx, uint32_t argc, jsval *vp) { return JS_TRUE; if(argc == 3) { jsval *argv = JS_ARGV(cx, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj); cocos2d::extension::CCControl* item = (cocos2d::extension::CCControl*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, item) JSObject* jsTargetObj = JSVAL_TO_OBJECT(argv[0]); JSObject* jsFuncObj = JSVAL_TO_OBJECT(argv[1]); int event = JSVAL_TO_INT(argv[2]); js_callback_proxy_t* found = NULL; if (is_target_function_exist(jsTargetObj, jsFuncObj, (void*)item, (void*)event, &found)) { item->removeTargetWithActionForControlEvents(found->nativeTargetObj, cccontrol_selector(JSCallbackTarget::onControlEventReceived), event); JS_CALLBACK_REMOVE_PROXY(found); CCLOG("In add Target: target exists, remove it!"); } JSCallbackTarget* pTarget = new JSCallbackTarget(); item->addTargetWithActionForControlEvents(pTarget, cccontrol_selector(JSCallbackTarget::onControlEventReceived), event); js_callback_proxy_t* p; JS_CALLBACK_NEW_PROXY(p, pTarget, jsTargetObj, jsFuncObj, item, event); JS_AddNamedObjectRoot(cx, &jsTargetObj, "cccontrol target object"); JS_AddNamedObjectRoot(cx, &jsFuncObj, "cccontrol jsFuncObj object"); pTarget->setJSProxy(p); return JS_TRUE; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 3); return JS_FALSE; }
bool LayerSetup::init() { CCLayer::init(); CCLayerColor* layerTrans = CCLayerColor::create(ccc4(192, 192, 192, 128)); addChild(layerTrans); CCLayerColor* layerBG = CCLayerColor::create(ccc4(192, 192, 192, 255), winSize.width / 2, winSize.height / 2); addChild(layerBG); layerBG->setPosition(ccp(winSize.width / 4, winSize.height / 4)); // 创建两个slider MyCCControlSlider* volumeBG = MyCCControlSlider::create("sliderTrack.png", "sliderProgress.png", "sliderThumb.png"); MyCCControlSlider* volumeEffect = MyCCControlSlider::create("sliderTrack.png", "sliderProgress.png", "sliderThumb.png"); addChild(volumeBG); addChild(volumeEffect); _volumeBG = volumeBG; _volumeEffect = volumeEffect; volumeBG->setMinimumValue(0.0f); volumeBG->setMaximumValue(1.0f); volumeEffect->setMinimumValue(0.0f); volumeEffect->setMaximumValue(1.0f); volumeBG->setPosition(ccp(winSize.width / 2, winSize.height / 2)); volumeEffect->setPosition(ccp(winSize.width / 2, winSize.height / 2)); Common::moveNodeY(volumeBG, 40); // Common::moveNodeY(volumeEffect, -30); volumeBG->addTargetWithActionForControlEvents(this, cccontrol_selector(LayerSetup::ChangeBGVolume), CCControlEventValueChanged); volumeEffect->addTargetWithActionForControlEvents(this, cccontrol_selector(LayerSetup::ChangeEffectVolume), CCControlEventValueChanged); setZOrder(Common::ZO_LAYER_SETUP); // 读配置文件 float fVolumeBG = CCUserDefault::sharedUserDefault()->getFloatForKey("BGVolume", 1.0f); float fVolumeEffect = CCUserDefault::sharedUserDefault()->getFloatForKey("EffectVolume", 1.0f); volumeBG->setValue(fVolumeBG); volumeEffect->setValue(fVolumeEffect); // 创建一个确定按钮 CCMenuItemFont* item = CCMenuItemFont::create("Close", this, menu_selector(LayerSetup::Close)); CCMenu* menu = CCMenu::createWithItem(item); addChild(menu); Common::moveNode(item, ccp(80, -60)); _menu = menu; // 暂停 // CCDirector::sharedDirector()->pause(); setTouchEnabled(true); setTouchMode(kCCTouchesOneByOne); setTouchPriority(-130); return true; }
bool ControlColourPicker::init() { if (Control::init()) { // Cache the sprites SpriteFrameCache::getInstance()->addSpriteFramesWithFile("extensions/CCControlColourPickerSpriteSheet.plist"); // Create the sprite batch node SpriteBatchNode *spriteSheet = SpriteBatchNode::create("extensions/CCControlColourPickerSpriteSheet.png"); addChild(spriteSheet); // MIPMAP // ccTexParams params = {GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT}; /* Comment next line to avoid something like mosaic in 'ControlExtensionTest', especially the display of 'huePickerBackground.png' when in 800*480 window size with 480*320 design resolution and hd(960*640) resources. */ // spriteSheet->getTexture()->setAliasTexParameters(); // spriteSheet->getTexture()->setTexParameters(¶ms); // spriteSheet->getTexture()->generateMipmap(); // Init default color _hsv.h = 0; _hsv.s = 0; _hsv.v = 0; // Add image _background=ControlUtils::addSpriteToTargetWithPosAndAnchor("menuColourPanelBackground.png", spriteSheet, Vec2::ZERO, Vec2(0.5f, 0.5f)); if(!_background) return false; CC_SAFE_RETAIN(_background); Vec2 backgroundPointZero = _background->getPosition() - Vec2(_background->getContentSize().width / 2, _background->getContentSize().height / 2); // Setup panels float hueShift = 8; float colourShift = 28; _huePicker = new ControlHuePicker(); _huePicker->initWithTargetAndPos(spriteSheet, Vec2(backgroundPointZero.x + hueShift, backgroundPointZero.y + hueShift)); _colourPicker = new ControlSaturationBrightnessPicker(); _colourPicker->initWithTargetAndPos(spriteSheet, Vec2(backgroundPointZero.x + colourShift, backgroundPointZero.y + colourShift)); // Setup events _huePicker->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlColourPicker::hueSliderValueChanged), Control::EventType::VALUE_CHANGED); _colourPicker->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlColourPicker::colourSliderValueChanged), Control::EventType::VALUE_CHANGED); // Set defaults updateHueAndControlPicker(); addChild(_huePicker); addChild(_colourPicker); // Set content size setContentSize(_background->getContentSize()); return true; } else return false; }
bool CCControlColourPicker::init() { if (CCControl::init()) { setTouchEnabled(true); // Cache the sprites CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("extensions/CCControlColourPickerSpriteSheet.plist"); // Create the sprite batch node CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::create("extensions/CCControlColourPickerSpriteSheet.png"); addChild(spriteSheet); // MIPMAP // ccTexParams params = {GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT}; /* Comment next line to avoid something like mosaic in 'CCControlExtensionTest', especially the display of 'huePickerBackground.png' when in 800*480 window size with 480*320 design resolution and hd(960*640) resources. */ // spriteSheet->getTexture()->setAliasTexParameters(); // spriteSheet->getTexture()->setTexParameters(¶ms); // spriteSheet->getTexture()->generateMipmap(); // Init default color m_hsv.h = 0; m_hsv.s = 0; m_hsv.v = 0; // Add image m_background=CCControlUtils::addSpriteToTargetWithPosAndAnchor("menuColourPanelBackground.png", spriteSheet, CCPointZero, ccp(0.5f, 0.5f)); CCPoint backgroundPointZero = ccpSub(m_background->getPosition(), ccp (m_background->getContentSize().width / 2, m_background->getContentSize().height / 2)); // Setup panels float hueShift = 8; float colourShift = 28; m_huePicker = new CCControlHuePicker(); m_huePicker->initWithTargetAndPos(spriteSheet, ccp(backgroundPointZero.x + hueShift, backgroundPointZero.y + hueShift)); m_colourPicker = new CCControlSaturationBrightnessPicker(); m_colourPicker->initWithTargetAndPos(spriteSheet, ccp(backgroundPointZero.x + colourShift, backgroundPointZero.y + colourShift)); // Setup events m_huePicker->addTargetWithActionForControlEvents(this, cccontrol_selector(CCControlColourPicker::hueSliderValueChanged), CCControlEventValueChanged); m_colourPicker->addTargetWithActionForControlEvents(this, cccontrol_selector(CCControlColourPicker::colourSliderValueChanged), CCControlEventValueChanged); // Set defaults updateHueAndControlPicker(); addChild(m_huePicker); addChild(m_colourPicker); // Set content size setContentSize(m_background->getContentSize()); return true; } else return false; }
SEL_CCControlHandler HRootLayer::onResolveCCBCCControlSelector(CCObject * pTarget, const char * pSelectorName) { SEL_CCControlHandler pRet = NULL; if (pSelectorName) { if (0 == strcmp(pSelectorName, "onBackClick:")) { pRet = cccontrol_selector(HRootLayer::onBackClick); } else if (0 == strcmp(pSelectorName, "onCloseClick:")) { pRet = cccontrol_selector(HRootLayer::onCloseClick); } } return pRet; }
NS_CC_EXT_BEGIN bool CCControlColourPicker::init() { if (CCControl::init()) { setTouchEnabled(true); // Cache the sprites CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("extensions/CCControlColourPickerSpriteSheet.plist"); // Create the sprite batch node CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::create("extensions/CCControlColourPickerSpriteSheet.png"); addChild(spriteSheet); // MIPMAP ccTexParams params = {GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT}; spriteSheet->getTexture()->setAliasTexParameters(); spriteSheet->getTexture()->setTexParameters(¶ms); spriteSheet->getTexture()->generateMipmap(); // Init default color m_hsv.h = 0; m_hsv.s = 0; m_hsv.v = 0; // Add image m_background=CCControlUtils::addSpriteToTargetWithPosAndAnchor("menuColourPanelBackground.png", spriteSheet, CCPointZero, ccp(0.5f, 0.5f)); CCPoint backgroundPointZero = ccpSub(m_background->getPosition(), ccp (m_background->getContentSize().width / 2, m_background->getContentSize().height / 2)); // Setup panels . currently hard-coded... float hueShift = 8; float colourShift = 28; m_huePicker=CCControlHuePicker::create(spriteSheet, ccp(backgroundPointZero.x + hueShift, backgroundPointZero.y + hueShift)); m_colourPicker=CCControlSaturationBrightnessPicker::create(spriteSheet, ccp(backgroundPointZero.x + colourShift, backgroundPointZero.y + colourShift)); // Setup events m_huePicker->addTargetWithActionForControlEvents(this, cccontrol_selector(CCControlColourPicker::hueSliderValueChanged), CCControlEventValueChanged); m_colourPicker->addTargetWithActionForControlEvents(this, cccontrol_selector(CCControlColourPicker::colourSliderValueChanged), CCControlEventValueChanged); // Set defaults updateHueAndControlPicker(); addChild(m_huePicker); addChild(m_colourPicker); // Set content size setContentSize(m_background->getContentSize()); return true; } else return false; }
bool ControlButtonTest_Event::init() { if (ControlScene::init()) { auto screenSize = Director::getInstance()->getWinSize(); // Add a label in which the button events will be displayed setDisplayValueLabel(Label::createWithTTF("No Event", "fonts/Marker Felt.ttf", 32)); _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1)); _displayValueLabel->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f); addChild(_displayValueLabel, 1); setDisplayBitmaskLabel(Label::createWithTTF("No bitmask event", "fonts/Marker Felt.ttf", 24)); _displayBitmaskLabel->setAnchorPoint(Vec2(0.5f, -1)); Vec2 bitmaskLabelPos = _displayValueLabel->getPosition() - Vec2(0, _displayBitmaskLabel->getBoundingBox().size.height); _displayBitmaskLabel->setPosition(bitmaskLabelPos); addChild(_displayBitmaskLabel, 1); // Add the button auto backgroundButton = ui::Scale9Sprite::create("extensions/button.png"); auto backgroundHighlightedButton = ui::Scale9Sprite::create("extensions/buttonHighlighted.png"); auto titleButton = Label::createWithTTF("Touch Me!", "fonts/Marker Felt.ttf", 30); titleButton->setColor(Color3B(159, 168, 176)); ControlButton *controlButton = ControlButton::create(titleButton, backgroundButton); controlButton->setBackgroundSpriteForState(backgroundHighlightedButton, Control::State::HIGH_LIGHTED); controlButton->setTitleColorForState(Color3B::WHITE, Control::State::HIGH_LIGHTED); controlButton->setAnchorPoint(Vec2(0.5f, 1)); controlButton->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f); addChild(controlButton, 1); // Add the black background auto background = ui::Scale9Sprite::create("extensions/buttonBackground.png"); background->setContentSize(Size(300, 170)); background->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f); addChild(background); // Sets up event handlers controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDownAction), Control::EventType::TOUCH_DOWN); controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDragInsideAction), Control::EventType::DRAG_INSIDE); controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDragOutsideAction), Control::EventType::DRAG_OUTSIDE); controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDragEnterAction), Control::EventType::DRAG_ENTER); controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchDragExitAction), Control::EventType::DRAG_EXIT); controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchUpInsideAction), Control::EventType::TOUCH_UP_INSIDE); controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchUpOutsideAction), Control::EventType::TOUCH_UP_OUTSIDE); controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchCancelAction), Control::EventType::TOUCH_CANCEL); // test for issue 2882 controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButtonTest_Event::touchBitmaskAction), Control::EventType::TOUCH_DOWN | Control::EventType::DRAG_INSIDE | Control::EventType::DRAG_OUTSIDE | Control::EventType::DRAG_ENTER | Control::EventType::DRAG_EXIT | Control::EventType::TOUCH_UP_INSIDE | Control::EventType::TOUCH_UP_OUTSIDE | Control::EventType::TOUCH_CANCEL | Control::EventType::VALUE_CHANGED); return true; } return false; }
void BWHomeLayer::initUI() { Size cntentSize = getContentSize(); CCButton* pBtnCloseGuide = CCButton::create("level",COMMON_FONT,50); pBtnCloseGuide->setPosition(Point(cntentSize.width*0.5,cntentSize.height*0.5)); pBtnCloseGuide->addTargetWithActionForControlEvents(this, cccontrol_selector(BWHomeLayer::clickLevel), Control::EventType::TOUCH_UP_INSIDE); addChild(pBtnCloseGuide); CCButton* pBtnEdit = CCButton::create("edit",COMMON_FONT,50); pBtnEdit->setPosition(Point(cntentSize.width*0.5,cntentSize.height*0.2)); pBtnEdit->addTargetWithActionForControlEvents(this, cccontrol_selector(BWHomeLayer::clickEdit), Control::EventType::TOUCH_UP_INSIDE); addChild(pBtnEdit); }
void MyStore::addscrollview(CCControlButton *button) { if (button->getTag()==1) { //普通商城 //scrollview->removeAllChildren(); this->removeChildByTag(10); scrollview=CCScrollView::create(CCSizeMake(700, 215)); scrollview->setPosition(visible_center); scrollview->setDirection(kCCScrollViewDirectionHorizontal); scrollview->ignoreAnchorPointForPosition(false); scrollview->setTag(10); addChild(scrollview); scrollview->setDelegate(this); scrollview->setContentSize(CCSizeMake(1400, 215)); for (int i=0; i<9; i++) { CCString *equipstring=CCString::createWithFormat("equip_%d.png",i+1); CCScale9Sprite *buttonsprite=CCScale9Sprite::create(equipstring->getCString()); CCControlButton *button=CCControlButton::create(buttonsprite); button->setPreferredSize(CCSizeMake(120, 215)); button->setPosition(i*160, visible_origin.y); button->setTag(100+i); button->addTargetWithActionForControlEvents(this, cccontrol_selector(MyStore::buyequip), CCControlEventTouchUpInside); scrollview->addChild(button); } } else if (button->getTag()==2) { //蘑菇商城 this->removeChildByTag(10); scrollview=CCScrollView::create(CCSizeMake(700, 215)); scrollview->setPosition(visible_center); scrollview->setDirection(kCCScrollViewDirectionHorizontal); scrollview->ignoreAnchorPointForPosition(false); scrollview->setTag(10); addChild(scrollview); scrollview->setDelegate(this); scrollview->setContentSize(CCSizeMake(700, 215)); for (int i=0; i<3; i++) { CCString *equipstring=CCString::createWithFormat("equip_%d.png",i+10); CCScale9Sprite *buttonsprite=CCScale9Sprite::create(equipstring->getCString()); CCControlButton *button=CCControlButton::create(buttonsprite); button->setPreferredSize(CCSizeMake(120, 215)); button->setPosition(i*240, visible_origin.y); button->setTag(200+i); button->addTargetWithActionForControlEvents(this, cccontrol_selector(MyStore::buyequip), CCControlEventTouchUpInside); scrollview->addChild(button); } } }
void BossLottery::initContent() { CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ui/fightUI/bossLottery.plist"); circle = CCSprite::createWithSpriteFrameName("bossLottery_bg.png"); addChild(circle); btn = INSTANCE(ButtonUtils)->createButton("bossLottery_btn.png", CCSizeMake(157, 207), ""); btn->setAnchorPoint(ccp(0.51, 0.37)); addChild(btn); btn->setZoomOnTouchDown(false); btn->addTargetWithActionForControlEvents(this, cccontrol_selector(BossLottery::btnHandler), CCControlEventTouchUpInside); CCPoint cP = circle->getAnchorPointInPoints(); for(int i=0;i<36;i++){ BossLotteryLight *light = BossLotteryLight::create(); circle->addChild(light); float t = i*10*3.14f/180; light->setPosition(ccpAdd(cP,ccp(200.0f * sin(t), 200.0f * cos(t)))); array->addObject(light); } lightFlag = 0; getScheduler()->scheduleSelector(schedule_selector(BossLottery::updateLight), this, 0.1f, false); CCLabelTTF *desc = CCLabelTTF::create(); desc->setFontSize(24); desc->setString("击杀将领"); btn->addChild(desc); desc->setColor(ccYELLOW); desc->setPosition(ccpAdd(btn->getAnchorPointInPoints(), ccp(0, 33))); costLabel = CCLabelTTF::create(); costLabel->setFontSize(24); costLabel->setColor(ccGREEN); btn->addChild(costLabel); costLabel->setPosition(ccpAdd(btn->getAnchorPointInPoints(), ccp(0, -34))); costLabel->setString("首次免费"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("common/common.plist"); closeBtn = INSTANCE(ButtonUtils)->createButton("common_redBtn_1.png", "common_redBtn_2.png", "common_redBtn_1.png", CCSizeMake(151, 48), "关闭",24,ccYELLOW); addChild(closeBtn); closeBtn->setPosition(ccp(0, -190)); closeBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(BossLottery::close), CCControlEventTouchUpInside); times = 1; }
bool GeneralDialogTest::init() { if (CCLayer::init()) { //正常状态按钮 CCScale9Sprite *backgroundButton = CCScale9Sprite::create("button.png"); //按下效果 CCScale9Sprite *backgroundHighlightedButton = CCScale9Sprite::create("buttonHighlighted.png"); //按钮的大小根据标题变化 CCLabelTTF *titleButton = CCLabelTTF::create("Touch Me!", "Marker Felt", 30); //按钮颜色 titleButton->setColor(ccc3(159, 168, 176)); CCControlButton* controlButton = CCControlButton::create(titleButton, backgroundButton); controlButton->setBackgroundSpriteForState(backgroundHighlightedButton, CCControlStateHighlighted); controlButton->setTitleColorForState(ccWHITE, CCControlStateHighlighted); // controlButton->setAnchorPoint(ccp(0.5f, 1)); controlButton->setPosition(ccp(640/2, 960/5)); addChild(controlButton); /* 当鼠标处于按下并曾经点中按钮的状态下,鼠标松开且在按钮范围内,则触发一次 */ controlButton->addTargetWithActionForControlEvents(this, cccontrol_selector(GeneralDialogTest::touchUpInside), CCControlEventTouchUpInside); return true; } return false; }
CCTableViewCell* RPGMapItemsMenuLayer::tableCellAtIndex(CCTableView *tableView, unsigned int idx) { CCTableViewCell *cell = tableView->dequeueCell(); if (!cell) { cell = new CCTableViewCell(); cell->autorelease(); } else cell->removeAllChildrenWithCleanup(true); float x = 100; for (int i = 0; i < 4; i++) { int index = idx * 4 + i; if(index >= this->m_itemsList->count()) break; RPGExistingItems *itemsData = (RPGExistingItems*)this->m_itemsList->objectAtIndex(index); CCControlButton *itemBtn = CCControlButton::create(CCString::createWithFormat("%s (%i)", itemsData->m_name.c_str(), itemsData->m_total)->getCString(), "Arial", 22); itemBtn->setPosition(ccp(x, 0)); itemBtn->setTag(itemsData->m_dataId); itemBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(RPGMapItemsMenuLayer::onButton), CCControlEventTouchUpInside); cell->addChild(itemBtn); x += 200; } return cell; }
void AssetsUpdateLayer::updateLayerMessageBox() { SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ccb/ccbResources/SystemLoading.plist"); CCLayer* layer = CCLayer::create(); layer->ignoreAnchorPointForPosition(false); layer->setContentSize(Size(960, 640)); layer->setPosition(Point(Director::getInstance()->getWinSize().width * 0.5, Director::getInstance()->getWinSize().height * 0.5)); layer->setScale(Director::getInstance()->getWinSize().width / 960); addChild(layer, 1); Sprite* messageboxSprite = Sprite::createWithSpriteFrameName("set_floor_v1.png"); messageboxSprite->setPosition(Point(480, 320)); layer->addChild(messageboxSprite, 1); LabelTTF* labelContent = LabelTTF::create(Localization::getInstance()->getValueByKey("Loading_warning_need_update"), "Helvetica",32); labelContent->setPosition(Point(480, 420)); layer->addChild(labelContent, 1); ControlButton* btn = ControlButton::create(LabelTTF::create(Localization::getInstance()->getValueByKey("BUTTON_DONE"), "Helvetica", 32), Scale9Sprite::createWithSpriteFrameName("set_button2.png")); btn->setPreferredSize(CCSize(191,70)); btn->setPosition(Point(480, 220)); btn->addTargetWithActionForControlEvents(this, cccontrol_selector(AssetsUpdateLayer::GoToAppPage), Control::EventType::TOUCH_UP_INSIDE); layer->addChild(btn, 1); }
bool SkillTableView::init() { if (!Node::init()) return false; LayerColor* bg = LayerColor::create(Color4B(255, 255, 255, 127), 450, 500); bg->setPosition(bg->getContentSize()/-2); this->addChild(bg, -1); CCLabelTTF* title = CCLabelTTF::create("技能列表", "fonts/Marker Felt.ttf", 40); title->setPosition(Point(bg->getContentSize().width/2, bg->getContentSize().height-30)); bg->addChild(title); ControlButton* button = ControlButton::create(Scale9Sprite::create("ui/closed_normal.png")); button->setBackgroundSpriteForState(Scale9Sprite::create("ui/closed_selected.png"), Control::State::HIGH_LIGHTED); button->setPreferredSize(Size(57, 58)); button->setPosition(ccpSub(ccpAdd(bg->getPosition(), bg->getContentSize()), button->getContentSize()/2)); this->addChild(button); button->addTargetWithActionForControlEvents(GAME_UILAYER, cccontrol_selector(GameInfoUIController::removeSmallMenuAndButton), Control::EventType::TOUCH_UP_INSIDE); // button->setTouchPriority(0); m_skillTableView = TableView::create(this, Size(420, 420)); m_skillTableView->setPosition(Point(15, 15)); // m_skillTableView->setDirection(kCCScrollViewDirectionVertical); m_skillTableView->setDelegate(this); // m_skillTableView->setVerticalFillOrder(kCCTableViewFillTopDown); bg->addChild(m_skillTableView); m_skillTableView->reloadData(); return true; }
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; }
bool CCEditBox::initWithSizeAndBackgroundSprite(const CCSize& size, CCScale9Sprite* pPressed9SpriteBg) { if (CCControlButton::initWithBackgroundSprite(pPressed9SpriteBg)) { m_pEditBoxImpl = __createSystemEditBox(this); m_pEditBoxImpl->initWithSize(size); this->setPreferredSize(size); this->setPosition(ccp(0, 0)); this->setZoomOnTouchDown(false); this->addTargetWithActionForControlEvent(this, cccontrol_selector(CCEditBox::touchDownAction), CCControlEventTouchUpInside); m_textHolderLabel = CCLabelTTF::create("", "TrebuchetMS", size.height*2/3); m_textHolderLabel->setAnchorPoint(ccp(0.0f, 0.5f)); m_textHolderLabel->setPosition(ccp(2.0f, size.height * 0.5f)); m_textHolderLabel->setColor(m_colPlaceHolder); addChild(m_textHolderLabel, 255); m_textLabel = CCLabelTTF::create("", "TrebuchetMS", size.height*2/3); m_textLabel->setAnchorPoint(ccp(0.0f, 0.5f)); m_textLabel->setPosition(ccp(2.0f, size.height * 0.5f)); m_textLabel->setColor(m_colText); addChild(m_textLabel, 255); return true; } return false; }
bool PropColumnMenu::init() { if (!Layer::init()) return false; this->setTouchEnabled(true); Sprite* bg = Sprite::create("ui/prop_column.png"); this->addChild(bg); m_propColumn = LayerColor::create(ccc4(255, 255, 255, 0), GRID_WIDTH*COL, GRID_HEIGHT*ROW); m_propColumn->setContentSize(Size(GRID_WIDTH*COL, GRID_HEIGHT*ROW)); m_propColumn->setPosition(Point(PROP_X, PROP_Y)); bg->addChild(m_propColumn); ControlButton* button = ControlButton::create(ui::Scale9Sprite::create("ui/closed_normal.png")); button->setBackgroundSpriteForState(ui::Scale9Sprite::create("ui/closed_selected.png"), Control::State::HIGH_LIGHTED); button->setPreferredSize(Size(57, 58)); button->setPosition(ccpSub(ccpAdd(bg->getPosition(), bg->getContentSize()/2), button->getContentSize()/2)); this->addChild(button); button->addTargetWithActionForControlEvents(GAME_UILAYER, cccontrol_selector(GameInfoUIController::removeSmallMenuAndButton), Control::EventType::TOUCH_UP_INSIDE); // button->setTouchPriority(0); for (int i=0; i<12; i++) { m_propVec[i] = PropIconShow::create(PropSystem::getPropInfo(i+1)); m_propColumn->addChild(m_propVec[i]); } return true; }
SEL_CCControlHandler CCBScriptCallbackProxy::onResolveCCBCCControlSelector(CCObject * pTarget, const char * pSelectorName) { this->callBackProp = pSelectorName; removeSelector(this->callBackProp); return cccontrol_selector(CCBScriptCallbackProxy::controlCallback); }
void HelloWorld::testControlBtn() { //创建正常状态下九宫格精灵 auto btnNormal = Scale9Sprite::create("switch-on.png"); //创建点击状态下九宫格精灵 auto btnSelected = Scale9Sprite::create("switch-off.png"); /*创建标题*/ auto title = LabelTTF::create("", "Marker Felt", 30); /* 根据标题和九宫格图片创建按钮 */ auto controlBtn = ControlButton::create(title, btnNormal); //setPreferredSize 设置大小*/ controlBtn->setPreferredSize(Size(128, 128)); /* 设置点击时候显示的图片 */ controlBtn->setBackgroundSpriteForState(btnSelected, Control::State::HIGH_LIGHTED); controlBtn->setPosition(Point(200, 200)); //注册事件 controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::btnClicked), Control::EventType::TOUCH_UP_INSIDE); controlBtn->setTag(10); this->addChild(controlBtn); }
JSBool js_cocos2dx_CCControl_removeTargetWithActionForControlEvents(JSContext *cx, uint32_t argc, jsval *vp) { return JS_TRUE; if(argc == 3) { jsval *argv = JS_ARGV(cx, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj); cocos2d::extension::CCControl* item = (cocos2d::extension::CCControl*)(proxy ? proxy->ptr : NULL); TEST_NATIVE_OBJECT(cx, item) JSObject* jsTargetObj = JSVAL_TO_OBJECT(argv[0]); JSObject* jsFuncObj = JSVAL_TO_OBJECT(argv[1]); int event = JSVAL_TO_INT(argv[2]); js_callback_proxy_t* found = NULL; if (is_target_function_exist(jsTargetObj, jsFuncObj, (void*)item, (void*)event, &found)) { item->removeTargetWithActionForControlEvents(found->nativeTargetObj, cccontrol_selector(JSCallbackTarget::onControlEventReceived), event); JS_CALLBACK_REMOVE_PROXY(found); CCLOG("In remove Target: target exists, remove it!"); return JS_TRUE; } else { JS_ReportError(cx, "In cc.Control.RemoveTargetWithActionForControlEvents, target and callback function aren't matched !"); return JS_FALSE; } } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 3); return JS_FALSE; }
static bool js_cocos2dx_CCControl_addTargetWithActionForControlEvents(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::Control* cobj = (cocos2d::extension::Control *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); bool ok = true; if (argc == 3) { JSObject* jsDelegate = JSVAL_TO_OBJECT(argv[0]); JSObject* jsFunc = JSVAL_TO_OBJECT(argv[1]); Control::EventType arg2; ok &= jsval_to_int32(cx, argv[2], (int32_t *)&arg2); JSB_PRECONDITION2(ok, cx, false, "Error processing control event"); // Check whether the target already exists. auto range = JSB_ControlButtonTarget::_jsNativeTargetMap.equal_range(jsDelegate); for (auto it = range.first; it != range.second; ++it) { if (it->second->_jsFunc == jsFunc && arg2 == it->second->_type) { // Return true directly. JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; } } // save the delegate JSB_ControlButtonTarget* nativeDelegate = new JSB_ControlButtonTarget(); nativeDelegate->setJSTarget(jsDelegate); nativeDelegate->setJSAction(jsFunc); nativeDelegate->setEventType(arg2); __Array* nativeDelegateArray = static_cast<__Array*>(cobj->getUserObject()); if (nullptr == nativeDelegateArray) { nativeDelegateArray = new __Array(); nativeDelegateArray->init(); cobj->setUserObject(nativeDelegateArray); // The reference of nativeDelegateArray is added to 2 nativeDelegateArray->release(); // Release nativeDelegateArray to make the reference to 1 } nativeDelegateArray->addObject(nativeDelegate); // The reference of nativeDelegate is added to 2 nativeDelegate->release(); // Release nativeDelegate to make the reference to 1 cobj->addTargetWithActionForControlEvents(nativeDelegate, cccontrol_selector(JSB_ControlButtonTarget::onEvent), arg2); JSB_ControlButtonTarget::_jsNativeTargetMap.insert(std::make_pair(jsDelegate, nativeDelegate)); JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 3); return false; }
// 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(); ///////////////////////////// // 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("Hello World", "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); CCRect rect1(133, 333, 42, 46); CCScale9Sprite* btnNormal = CCScale9Sprite::create("char_bluelight.png",rect1); CCScale9Sprite* btnDown = CCScale9Sprite::create("char_bluelight.png",rect1); CCControlButton* controlBtn = CCControlButton::create(btnNormal); controlBtn->setBackgroundSpriteForState(btnDown, CCControlStateSelected); controlBtn->setPosition(ccp(visibleSize.width/2, visibleSize.height/2)); controlBtn->setPreferredSize(CCSize(60, 50)); controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDownAction), CCControlEventTouchDown); this->addChild(controlBtn); return true; }
bool HelloWorld::init() { if ( !CCLayer::init() ) { return false; } //获取可视区域尺寸大小 CCSize mysize = CCDirector::sharedDirector()->getVisibleSize(); //获取可视区域的原点位置 CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); //屏幕正中心位置 CCPoint midPos = ccp(mysize.width/2, mysize.height/2); //显示按钮状态的标签displayLabel displayLabel = CCLabelTTF::create("No Event", "Marker Felt", 32); displayLabel->setPosition( midPos + ccp(0, 100) ); this->addChild(displayLabel); //按钮中的背景精灵CCScale9Sprite CCScale9Sprite* bgNormal = CCScale9Sprite::create("btnNormal.png"); //正常背景 CCScale9Sprite* bgHighlighted = CCScale9Sprite::create("btnHighlighted.png"); //高亮背景 //按钮中的标签CCLabelTTF CCLabelTTF* titleNormal = CCLabelTTF::create("Button is Normal !", "Marker Felt", 30); CCLabelTTF* titleHighlighted = CCLabelTTF::create("Button is Highlighted !", "Marker Felt", 30); //创建按钮CCControlButton CCControlButton* btn = CCControlButton::create(titleNormal, bgNormal); btn->setPosition( midPos ); this->addChild(btn); //设置按钮高亮时的状态 btn->setTitleLabelForState(titleHighlighted, CCControlStateHighlighted); //高亮标签 btn->setTitleColorForState(ccRED, CCControlStateHighlighted); //红色 btn->setBackgroundSpriteForState(bgHighlighted, CCControlStateHighlighted); //高亮背景 //写了这句话,反而大小被固定了。没有按照label的大小进行自动伸展了 //btn->setPreferredSize( CCSizeMake(120,40) ); //绑定事件,用于显示按钮状态 btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDownAction), CCControlEventTouchDown); //刚刚开始触摸按钮时 btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDragInsideAction), CCControlEventTouchDragInside); //在内部拖动时(保持触摸状态下) btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDragOutsideAction), CCControlEventTouchDragOutside); //在外部拖动时(保持触摸状态下) btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDragEnterAction), CCControlEventTouchDragEnter); //拖动刚进入内部时(保持触摸状态下) btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDragExitAction), CCControlEventTouchDragExit); //拖动刚离开内部时(保持触摸状态下) btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchUpInsideAction), CCControlEventTouchUpInside); //在内部抬起手指(保持触摸状态下) btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchUpOutsideAction), CCControlEventTouchUpOutside); //在外部抬起手指(保持触摸状态下) btn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchCancelAction), CCControlEventTouchCancel); //取消触点 return true; }
//------------------------------------------------------------------ // // Slider // //------------------------------------------------------------------ void CommonSlider::onEnter() { CommonDemo::onEnter(); setOpacity(127); setColor(ccRED); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); // Add the slider CCSlider* slider = CCSlider::create(CCSprite::create("Images/sliderTrack.png"), CCSprite::create("Images/sliderThumb.png"), CCSprite::create("Images/sliderProgress.png")); slider->setMinimumValue(0.0f); slider->setMaximumValue(5.0f); slider->setPosition(ccp(origin.x + visibleSize.width / 2, origin.y + visibleSize.height * 3 / 5)); slider->addTargetWithActionForControlEvents(this, cccontrol_selector(CommonSlider::onValueChanged), CCControlEventValueChanged); addChild(slider); // value label of slider CCLabelTTF* value = CCLabelTTF::create("0", "Helvetica", 20 / CC_CONTENT_SCALE_FACTOR()); value->setPosition(ccp(origin.x + visibleSize.width / 2, CCUtils::getPoint(slider, 0.5f, 1).y + 15 / CC_CONTENT_SCALE_FACTOR())); addChild(value); slider->setUserData(value); // discrete slider, without progress slider = CCSlider::create(CCSprite::create("Images/sliderTrack.png"), CCSprite::create("Images/sliderThumb.png")); slider->setMaximumValue(20); slider->setDiscreteMode(true); slider->setPosition(ccp(origin.x + visibleSize.width / 2, origin.y + visibleSize.height * 2 / 5)); slider->addTargetWithActionForControlEvents(this, cccontrol_selector(CommonSlider::onValueChanged), CCControlEventValueChanged); addChild(slider); // value label for discrete slider value = CCLabelTTF::create("0", "Helvetica", 20 / CC_CONTENT_SCALE_FACTOR()); value->setPosition(ccp(origin.x + visibleSize.width / 2, CCUtils::getPoint(slider, 0.5f, 1).y + 15 / CC_CONTENT_SCALE_FACTOR())); addChild(value); slider->setUserData(value); }
void RegisterScene::onEnter(){ BaseScene::onEnter(); GraphicUtils::drawString(this, "输入姓名", CommonUtils::getScreenWidth() / 2 , CommonUtils::getScreenHeight() - 300, getSystemColor(COLOR_KEY_WHITE), TEXT_ALIGN_CENTER_MIDDLE, 40); CCSize editBoxSize = CCSizeMake( 200, 32 ); editBox = CCEditBox::create( editBoxSize, CCScale9Sprite::create("img/base_panel.png")); // Positionは画面の遥か外側のためccp(1000,1000) editBox->setPosition( ccp( 2000, 2000 ) ); editBox->setText( "" ); editBox->setMaxLength(8); editBox->setReturnType( kKeyboardReturnTypeDefault ); editBox->setInputMode( kEditBoxInputModeSingleLine ); editBox->setDelegate(this); editBox->setVisible( false ); this->addChild(editBox); // 画像でかぶせる editBoxSprite = GameSprite::init( "img/handle_name_frame.png" ); editBoxSprite->setAnchorPoint(ccp(0.5,1)); editBoxSprite->setSize( 400, 64 ); editBoxSprite->setPosition( CommonUtils::getScreenWidth() / 2, 960); this->addChild(editBoxSprite); m_confirmButton = CCControlButton::create("确认", DEFAULT_FONT_NAME, 40); m_confirmButton->setPosition(CommonUtils::getScreenWidth() / 2, 500); this->addChild(m_confirmButton); m_confirmButton->addTargetWithActionForControlEvents(this, cccontrol_selector(RegisterScene::create_user), CCControlEventTouchDown); m_randomButton = CCControlButton::create("随机姓名", DEFAULT_FONT_NAME, 40); m_randomButton->setPosition(CommonUtils::getScreenWidth() / 2, 1000); this->addChild(m_randomButton); m_randomButton->addTargetWithActionForControlEvents(this, cccontrol_selector(RegisterScene::getRandomName), CCControlEventTouchDown); float nx = CommonUtils::getScreenWidth() / 2 - 143; float ny = 980; userName = GraphicUtils::drawString( this, "", nx, ny, 200, 32, ccc3(255,255,255), TEXT_ALIGN_LEFT_TOP, 40 ); getRandomName(NULL, NULL); }
void BWCombatLayer::initUILayer() { Size contentSize = getContentSize(); CCButton* pBtnBack = CCButton::create("back",COMMON_FONT,50); pBtnBack->setPosition(Point(50,contentSize.height-50)); pBtnBack->addTargetWithActionForControlEvents(this, cccontrol_selector(BWCombatLayer::clickBack), Control::EventType::TOUCH_UP_INSIDE); _pBgLayerUI->addChild(pBtnBack); }
bool ControlSliderTest::init() { if (ControlScene::init()) { auto screenSize = Director::getInstance()->getWinSize(); // Add a label in which the slider value will be displayed _displayValueLabel = LabelTTF::create("Move the slider thumb!\nThe lower slider is restricted." ,"Marker Felt", 32); _displayValueLabel->retain(); _displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f)); _displayValueLabel->setPosition(Point(screenSize.width / 1.7f, screenSize.height / 2.0f)); addChild(_displayValueLabel); // Add the slider ControlSlider *slider = ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png"); slider->setAnchorPoint(Point(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(Point(screenSize.width / 2.0f, screenSize.height / 2.0f + 16)); slider->setTag(1); // When the value of the slider will change, the given selector will be call slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlSliderTest::valueChanged), Control::EventType::VALUE_CHANGED); ControlSlider *restrictSlider = ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png"); restrictSlider->setAnchorPoint(Point(0.5f, 1.0f)); restrictSlider->setMinimumValue(0.0f); // Sets the min value of range restrictSlider->setMaximumValue(5.0f); // Sets the max value of range restrictSlider->setMaximumAllowedValue(4.0f); restrictSlider->setMinimumAllowedValue(1.5f); restrictSlider->setValue(3.0f); restrictSlider->setPosition(Point(screenSize.width / 2.0f, screenSize.height / 2.0f - 24)); restrictSlider->setTag(2); //same with restricted restrictSlider->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlSliderTest::valueChanged), Control::EventType::VALUE_CHANGED); addChild(slider); addChild(restrictSlider); return true; } return false; }
CCControlButton* PluginLayerContent::createRootButton( const char* btnTitle, int btnTag ) { CCControlButton* ctrlBtn = nl::ControlUtils::createButton(btnTitle); ctrlBtn->setTag(btnTag); ctrlBtn->addTargetWithActionForControlEvents( this, cccontrol_selector(PluginLayerContent::onUIAction), CCControlEventTouchUpInside); return ctrlBtn; }
bool HelloScene::init() { if (!CCLayer::init()) { return false; } CCSprite *bg = CCSprite::create("background.png"); bg->setPosition(VisibleRect::center()); //CCSize &winSize = CCDirector::sharedDirector()->getWinSize(); //float scalex = winSize.width / 480; //float scaley = winSize.height / 800; //bg->setScaleX(scalex); //bg->setScaleY(scaley); addChild(bg); const CCPoint ¢er = VisibleRect::center(); CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloScene::menuCloseCallback)); pCloseItem->setPosition(ccp(VisibleRect::rightBottom().x - pCloseItem->getContentSize().width/2 , pCloseItem->getContentSize().height/2)); CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); CCLabelTTF *title = CCLabelTTF::create("Lovexin Plane Chess", "Arial", 40); title->setPosition(ccp(center.x, center.y + 250)); CCLabelTTF *author = CCLabelTTF::create("made by Waltz Duyf", "Arial", 20); author->setPosition(ccp(center.x + 100, center.y + 200)); addChild(title); addChild(author); addSetupSwitch(ccp(center.x - 120, center.y + 50 ), "RED", ccc3(255, 0, 0), FORCE_COLOR_RED);//, cccontrol_selector(HelloScene::valueChangedJoinInR), cccontrol_selector(HelloScene::valueChangedAIR)); addSetupSwitch(ccp(center.x - 120, center.y - 10 ), "YEL", ccc3(234, 165, 0), FORCE_COLOR_YELLOW);//, cccontrol_selector(HelloScene::valueChangedJoinInY), cccontrol_selector(HelloScene::valueChangedAIY)); addSetupSwitch(ccp(center.x - 120, center.y - 70 ), "GRE", ccc3(0, 255, 0), FORCE_COLOR_GREEN);//, cccontrol_selector(HelloScene::valueChangedJoinInG), cccontrol_selector(HelloScene::valueChangedAIG)); addSetupSwitch(ccp(center.x - 120, center.y - 130), "BLU", ccc3(0, 144, 255), FORCE_COLOR_BLUE);//, cccontrol_selector(HelloScene::valueChangedJoinInB), cccontrol_selector(HelloScene::valueChangedAIB)); CCScale9Sprite *backgroundButton = CCScale9Sprite::create("button.png"); CCScale9Sprite *backgroundHighlightedButton = CCScale9Sprite::create("buttonHighlighted.png"); CCLabelTTF *titleButton = CCLabelTTF::create("Play Now", "Arial", 30); titleButton->setColor(ccc3(159, 168, 176)); CCControlButton *button = CCControlButton::create(titleButton, backgroundButton); button->setBackgroundSpriteForState(backgroundHighlightedButton, CCControlStateHighlighted); button->setTitleColorForState(ccWHITE, CCControlStateHighlighted); button->setMargins(70, 20); button->setPosition(ccp(center.x, center.y - 250)); addChild(button); button->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloScene::playBtnCallback), CCControlEventTouchUpInside); return true; }