码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2d-x3.0 Slider

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

标签:android   c   style   class   blog   code   


.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

标签:android   c   style   class   blog   code   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!