首页 > 其他 > 详细

cocos2d-x3.0 Slider

时间:2014-05-31 03:16:15      阅读:451      评论:0      收藏:0      [点我收藏+]


.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());
        
    }
}

bubuko.com,布布扣

cocos2d-x3.0 Slider,布布扣,bubuko.com

cocos2d-x3.0 Slider

原文:http://www.cnblogs.com/mfrbuaa/p/3761716.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!