CCControlStepper的使用

来源:互联网 发布:苹果电脑的解压缩软件 编辑:程序博客网 时间:2024/05/21 09:30

2.0后加了一个点击“+”“—”来改变数值的控件CCControlStepper

 

(1)显示

// label6_3CCLabelTTF* label6_3 = CCLabelTTF::create("8", "HelveticaNeue-Bold", 15, CCSizeMake(70,30), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);label6_3->setPosition(_TVCC_LABEL6_3_POS);this->addChild(label6_3, 10, 603);// label6_3's backgroundCCScale9Sprite* background6_3  = CCScale9Sprite::create("cityBuilding/cityBuildingInfo/cityCenter/buttonBackground.png");background6_3->setContentSize(CCSizeMake(40, 20));background6_3->setPosition(_TVCC_BACKGROUND6_3_POS);this->addChild(background6_3);// stepper6_3CCControlStepper* stepper6_3 = CCControlStepper::create(CCSprite::create("cityBuilding/cityBuildingInfo/cityCenter/stepper-minus.png"), CCSprite::create("cityBuilding/cityBuildingInfo/cityCenter/stepper-plus.png"));stepper6_3->setPosition(_TVCC_STEPPER6_3_POS);stepper6_3->setScale(0.6);stepper6_3->setMaximumValue(24);// 最大值stepper6_3->setValue(8);// 起始值stepper6_3->addTargetWithActionForControlEvents(this, cccontrol_selector(TVCityCenter::valueChanged6_3), CCControlEventValueChanged);this->addChild(stepper6_3);


(2)回调函数

// "保护时间"模块中stepper6_3值改变回调函数void TVCityCenter::valueChanged6_3(CCObject* sender, CCControlEvent controlEvent){CCControlStepper* pControl = (CCControlStepper*)sender;int theValue = pControl->getValue();// Change value of label.CCLabelTTF* label = (CCLabelTTF*)this->getChildByTag(603);label->setString(CCString::createWithFormat("%d", theValue)->getCString());}



 

原创粉丝点击