首页 > 代码库 > cocos2d-x3.0 Slider
cocos2d-x3.0 Slider
.h
#include "cocos2d.h" #include "cocos-ext.h" #include "ui/CocosGUI.h" #include "cocostudio/CocoStudio.h" USING_NS_CC; USING_NS_CC_EXT; using namespace ui;
RichText* _richText; Text* alert;
.cpp
Size widgetSize = Director::getInstance()->getWinSize(); layout = Layout::create(); layout->setSize(Size(widgetSize.width, widgetSize.height)); //横向排列,这里类似Android里的线性布局 //layout->setLayoutType(LAYOUT_RELATIVE); /*以图片为背景*/ layout->setBackGroundImageScale9Enabled(true); layout->setBackGroundImage("green_edit.png"); layout->setPosition(Point(0,0)); addChild(layout); alert = Text::create("Layout", "fonts/Marker Felt.ttf", 30 ); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); layout->addChild(alert); /******************************************************************************************/ Slider* slider = Slider::create(); slider->loadBarTexture("sliderTrack.png"); slider->loadSlidBallTextures("sliderThumb.png", "sliderThumb.png", ""); slider->loadProgressBarTexture("slider_bar_active_9patch.png"); slider->setScale9Enabled(true); slider->setCapInsets(Rect(0, 0, 0, 0)); slider->setSize(Size(250.0, 19)); slider->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); slider->addEventListenerSlider(this, sliderpercentchangedselector(LayoutTest::sliderEvent)); layout->addChild(slider);
void LayoutTest::sliderEvent(cocos2d::Ref *pSender, SliderEventType type) { if (type == SLIDER_PERCENTCHANGED) { Slider* slider = dynamic_cast<Slider*>(pSender); int percent = slider->getPercent(); alert->setText(StringUtils::format("Percent %d",percent).c_str()); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。