CCControlSlider和CCControlStepper用法

一开始,size的大小是系统分配。玩家可以通过setDefaultSize()更改值

1. CCControlSlider用法

CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("upgradePlist.plist");

CCLabelTTF* label = CCLabelTTF::create("8", "HelveticaNeue-Bold", 30, CCSizeMake(70,30), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);

label->setPosition(ccp(240, 200));

label->setColor(ccc3(0, 0, 0));

this->addChild(label, 10, 603);

CCControlSlider *slider=CCControlSlider::create(CCSprite::create("progress_bg.png"), CCSprite::create("progress_bar.png"), CCSprite::createWithSpriteFrameName("pen.png"));

slider->setMinimumValue(0);

slider->setMaximumValue(100);

slider->setPosition(ccp(400,400));

addChild(slider);

slider->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::sliderValueChanged), CCControlEventValueChanged);

  

CCSprite *pen=slider->getThumbSprite();

pen->setAnchorPoint(ccp(0.2, 0.5));

pen->setPosition(ccp(20, pen->getContentSize().height-8));

  

CCControlStepper* stepper = CCControlStepper::create(CCSprite::createWithSpriteFrameName("sub_up.png"), CCSprite::createWithSpriteFrameName("add_up.png"));

stepper->setMinimumValue(1);

stepper->setMaximumValue(24);

stepper->startAutorepeat();

stepper->setValue(8);// 起始值

stepper->setStepValue(2);//步间距

((CCLabelTTF *)stepper->getPlusLabel())->setString("");

((CCLabelTTF *)stepper->getMinusLabel())->setString("");

stepper->setPosition(ccp(250, 200));

this->addChild(stepper);

stepper->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::stepperValueChange), CCControlEventValueChanged);


void HelloWorld::sliderValueChanged(CCObject* sender, CCControlEvent controlEvent){

CCControlSlider* slider = (CCControlSlider*)sender;

int theValue = slider->getValue();

  

CCLabelTTF * label =(CCLabelTTF * )this->getChildByTag(603);

label->setString(CCString::createWithFormat(" %d" ,theValue)->getCString());

}


void HelloWorld::stepperValueChange(CCObject* sender, CCControlEvent controlEvent){

CCControlStepper* pControl = (CCControlStepper*)sender;

int theValue = pControl->getValue();

  

CCLabelTTF* label = (CCLabelTTF*)this->getChildByTag(603);

label->setString(CCString::createWithFormat("%d", theValue)->getCString());

}


你可能感兴趣的:(slider)