CCControlStepper的使用

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

 

(1)显示

// label6_3
CCLabelTTF* 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 background
CCScale9Sprite* 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_3
CCControlStepper* 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());
}



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值