当前位置:编程学习 > wap >>

cocos2d-x拖动滑块控件CCControlSlider

#include "GameMusicSetting.h"
bool GameMusicSetting::init()
{
    if(!CCLayer::init())
    {
        return false;
    }
    CCSize size=CCDirector::sharedDirector()->getWinSize();
    //参数分别为:滑块滑道图片,滑块滑动后滑道覆盖图片,滑道图片
    CCControlSlider *slider=CCControlSlider::create("bg_ScrollBtn.png", "value_ScrollBtn.png", "bar_ScrollBtn.png");
    slider->setMinimumAllowedValue(0);  //设置滑块设置的最小值
    slider->setMaximumAllowedValue(5);
    slider->setAnchorPoint(ccp(0.5,1));
    slider->setPosition(ccp(size.width/2, size.height/2));
    //设置滑块滑动后的回调函数
    slider->addTargetWithActionForControlEvents(this,cccontrol_selector(GameMusicSetting::callback),CCControlEventValueChanged);
    addChild(slider,1);
    
    return true;
}
CCScene *GameMusicSetting::scene()
{
    CCScene *scene=CCScene::create();
    CCLayer *layer=GameMusicSetting::create();
    scene->addChild(layer);
    return scene;
}
void GameMusicSetting::onEnter()
{
    CCLayer::onEnter();
}
void GameMusicSetting::onExit()
{
    CCLayer::onExit();
}
void GameMusicSetting::callback(CCObject *sender, CCControlEvent controlEvent)
{
    CCControlSlider * pslider=(CCControlSlider *)sender;
    CCLOG("%f",pslider->getValue()*5);   //输出此时滑块所在位置代表的值
}

 

补充:移动开发 , 其他 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,