zoukankan      html  css  js  c++  java
  • 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);   //输出此时滑块所在位置代表的值
    }
  • 相关阅读:
    JS——switch case
    JS——“==”与“===”
    C#——枚举格式转换与比较
    XML——读与写
    SQl基本操作——try catch
    JS——indexOf replace search
    C#——数据库的访问
    SQL基本操作——存储过程
    C#——设置开机启动
    C#——计时器的操作
  • 原文地址:https://www.cnblogs.com/james1207/p/3268827.html
Copyright © 2011-2022 走看看